softark:
Do you say that built-in translations of yii (e.g. “OK”, “Cancel”, “Next”, “Prev”) failed to work? Or is it your custom translation that didn’t work?
And have you found nothing in the application log?
only the custom translation doesn’t work.
I test in the following way:
[size="4"]site/index: [/size]
public function actionIndex()
{
echo "PHP: " . PHP_VERSION . "<br>";
echo "ICU: " . INTL_ICU_VERSION . "<br>";
yii::$app->language = 'de-DE';
//yii::$app->language = 'zh-CN';
echo yii::$app->language . "<br>";
echo Yii::t('app', 'testEN') . "<br>";
echo yii::t('app', 'testEN') . "<br>";
//exit;
result:
[size="4"]common/messages/de-DE/app.php: [/size]
<?php
return [
'testEN' => 'testGerman',
];
[size="4"]common/config/main-local.php: [/size]
'i18n' =>
[
'translations' =>
[
'app*' =>
[
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => dirname(__DIR__) . '\messages',
'sourceLanguage' => 'en-US',
'forceTranslation' => true,
'fileMap' =>
[
'app*' => 'app.php',
'frontend*' => 'app.php',
'app/error' => 'error.php',
],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
'frontend*' =>
[
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => dirname(__DIR__) . '\messages',
'sourceLanguage' => 'en-US',
//'sourceLanguage' => 'de-DE',
'forceTranslation' => true,
'fileMap' =>
[
'app*' => 'app.php',
'frontend' => 'app.php',
'app/error' => 'error.php',
],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
'backend*' =>
[
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => dirname(__DIR__) . '\messages',
'sourceLanguage' => 'en-US',
'forceTranslation' => true,
'fileMap' =>
[
'app*' => 'app.php',
'backend*' => 'app.php',
'app/error' => 'error.php',
],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
'*' =>
[
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => dirname(__DIR__) . '\messages',
'sourceLanguage' => 'en-US',
'forceTranslation' => true,
'fileMap' =>
[
'app*' => 'app.php',
'frontend*' => 'app.php',
'backend*' => 'app.php',
'app/error' => 'error.php',
],
'on missingTranslation' => ['app\components\TranslationEventHandler', 'handleMissingTranslation']
],
],
],
[size="4"]common/messages/config.php [/size]
I think we don’t need this config at all.
<?php
return [
'languages' =>
[
'en-US',
'de-DE',
'tr-TR',
'ro-RO',
'hu-HU',
'cs-CZ',
'pl-PL',
'bg-BG',
'fr-FR',
'es-ES',
'pt-PT',
'ru-RU',
'zh-CN'
],
'translator' => 'Yii::t',
'sort' => false,
'removeUnused' => false,
'only' => ['*.php'],
'except' => [
'.svn',
'.git',
'.gitignore',
'.gitkeep',
'.hgignore',
'.hgkeep',
'/messages',
],
'format' => 'php',
'messagePath' => __DIR__,
'overwrite' => true,
'catalog' => 'app',
'catalog' => 'frondend',
'catalog' => 'backend',
'catalog' => 'messages',
'overwrite' => true,
];
Thanks for reading.