php YII 更改默认语言
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12440049/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
YII Change the default language
提问by user1288058
I'm a beginner in YII framework (PHP) When creating a new site with YII, it will displayed with english page.
我是 YII 框架 (PHP) 的初学者 使用 YII 创建新站点时,它将显示英文页面。
I want to change the default language to French, so pages will be displayed in French.
我想将默认语言更改为法语,因此页面将以法语显示。
回答by Jon
To change the language, set CApplication::languageappropriately. This can be done at runtime as in
要更改语言,请CApplication::language适当设置。这可以在运行时完成,如
Yii::app()->language = 'fr';
but usually it's done in your application configuration:
但通常它是在您的应用程序配置中完成的:
array(
// ...settings...
'language' => 'fr',
// ...more settings...
)
回答by shgnInc
and so you can set the default languages in the config/main.php as
所以你可以在 config/main.php 中将默认语言设置为
return array(
...
'sourceLanguage' => 'fr',
'language'=>'en',
...
'params' => array(
...
'languages'=>array('en_us'=>'English', 'fr'=>'French', 'fa_ir'=>'?????'),
....
),
);
and change your language everywhere you like:
并在您喜欢的任何地方更改您的语言:
Yii::app()->language = Yii::app()->params->languages['fa_ir'];
or more:
或者更多:
Yii::app()->language = Yii::app()->params->languages[$_GET['lang']];
回答by Teoman Diler
location for Yii2: root/config/web.php and add this: 'language' => 'fr',
Yii2 的位置:root/config/web.php 并添加:'language' => 'fr',
$config = [
'id' => 'basic',
'language' => 'fr', // Add this in config/web.php
'basePath' => dirname( __DIR__ ),
'bootstrap' => ['log'],
...
...
];
回答by bpile
Setting default language (in which your application is written in) can be configured trough CApplication::sourceLanguage, changing CApplication::languagehas no effect because it is set to en_en by default.
设置默认语言(您的应用程序所使用的语言)可以通过 配置CApplication::sourceLanguage,更改CApplication::language没有任何影响,因为它默认设置为 en_en。
also when setting language you should be using localeID - fr_FR ;)
同样在设置语言时,您应该使用 localeID - fr_FR ;)

