如何在yii2中使用多语言? [英] how to use multilanguage in yii2?
本文介绍了如何在yii2中使用多语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在yii2中创建多语言应用程序?
yii2中是否有任何预安装消息?
How to create multilanguage app in yii2?
Is there any preinstall message in yii2?
config:
'language' => 'es',
'components' => [
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
//'basePath' => '@app/messages',
'sourceLanguage' => 'ru-RU',
'fileMap' => [
'app' => 'app.php',
'app/error' => 'error.php',
],
],
],
],
视图:
echo \Yii::t('app', 'I am a message!');
$username = 'Alexander';
echo \Yii::t('app', 'Hello, {username}!', [
'username' => $username,
]);
推荐答案
尝试一下:
在前端或后端编辑config.php
Edit config.php in frontend or backend
'language' => 'ru',
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages',
'fileMap' => [
'app' => 'app.php',
],
],
],
],
在frontend/messages/ru/app.php
或backend/messages/ru/app.php
查看:
echo \Yii::t('app', 'I am a message!');
这篇关于如何在yii2中使用多语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文