The problem of Yii2 internationalization ZH-CN

Source: Internet
Author: User
Tags i18n

Code Add Location:

Add the following within the config->main.php return of the project file directory and set the en-US and ZH-CN folders in the new messages in the project directory.   Create a lang.php Language conversion array in the ZH-CN folder, and set up the relevant language conversion content, when you want to do language conversion in any place, in <?php?> declaration " \yii:: $app->language = ' ZH-CN '; Change the language ", and then use this, for example:" ' label ' = + yii::t (' lang ', ' Home ') ".

  main.php   

' Language ' = ' en-US ',//Add this sentence default language' i18n ' = [            ' Translations ' = [                ' lang* ' = [                    ' Class ' = ' Yii\i18n\phpmessagesource ',//saving information using PHP files' BasePath ' = ' @app/messages ',//PHP File Save location//' sourcelanguage ' = ' en ',' Filemap ' = [                        ' lang ' = ' lang.php ', ' lang/error ' = ' error.php ',                    ],                ],            ],        ],

  lang.php

<? PHP     return [        ' home ' = ' homepage ',    ];

The problem of Yii2 internationalization ZH-CN

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.