Answer the question
In order to leave comments, you need to log in
How is language stored when multilingual in Yii2?
I'm trying to implement multilanguage on the site (on the Yii2 framework). I read a bunch of documentation, as examples:
this , this , this , this , and much more.
Some of this even implemented. It even works =) But if everything was fine, I would not contact you =))
Multilingual links look like this:
https://site.com/contact
https://site.com/en/contact
https:// site.com/uk/contact
Now in the project I do not use helpers and generate a link like this:
<a class="nav-link" href="/cat/<?=$item->adjusted_name?>"><?=$item->name?></a>
Html::a .....
'modules' => [
'languages' => [
'class' => 'common\modules\languages\Module',
//Языки используемые в приложении
'languages' => [
'English' => 'en',
'Русский' => 'ru',
'Українська' => 'uk',
'Қазақ' => 'kz',
],
'default_language' => 'ru', //основной язык (по-умолчанию)
'show_default' => false, //true - показывать в URL основной язык, false - нет
],
],
......
'i18n' => [
'translations' => [
'app' => [
'class' => 'yii\i18n\PhpMessageSource',
//'forceTranslation' => true,
'basePath' => '@common/messages',
],
],
],
......
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'class' => 'common\components\UrlManager',
'rules' => [
'languages' => 'languages/default/index', //для модуля мультиязычности
......
Answer the question
In order to leave comments, you need to log in
To paraphrase Dmitry, he suggests modifying the output of the link using a helper, something like this:
<?= Html::a(
Yii::t('app',$item->name),
['/cat/' . $item->adjusted_name]
) ?>
Enter PHP-UP Yii2 internationalization in YouTube,
see the lesson I think it will help))
PS You can not use the get parameter in the link at all, just use ajax and data type attributes
<button type='button' data-lang ='en' >English</button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question