Answer the question
In order to leave comments, you need to log in
Condition for Assets in Yii2?
Good day.
Is there a variable, Yii::$app->language
how can I include scripts in assets based on what this variable returns? Without creating its own asset for each language,
that is, for "ru" to connect the script
'theme/assets/global/plugins/date/locales/dater.ru.min.js'
'theme/assets/global/plugins/date/locales/dater.en.min.js'
Answer the question
In order to leave comments, you need to log in
Use AssetBundle and init() method in it like this:
<?php
namespace app\assets;
use yii\web\AssetBundle;
class AppAsset extends AssetBundle
{
public function init()
{
$format = 'theme/assets/global/plugins/date/locales/dater.%s.min.js';
$this->js[] = sprintf($format, \Yii::$app->language);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question