0

I want to use JsTrans extension in my yii2 advanced project. https://www.yiiframework.com/extension/jstrans But I have problem with the configuration. After I downloaded the extensions, I extract it in common/extensions folder with name "JsTrans". And then I add this code in my main config:

'components' => [
    ...
    'jsTrans' => array(
        // 'class'=>'ext.JsTrans.JsTrans', 
        'class' => 'common\extensions\JsTrans\JsTrans',
        'categories' => array('app'),
        'languages' => array('en', 'id'),
        // 'defaultLanguage' => 'en', // Optional
    )
],

But when I called this in view, I get error: Getting unknown property: yii\web\Application::jstrans My view code

I also tried call it using Yii::$app->jsTrans->init(); but I get another error: Unable to find 'common\extensions\JsTrans\JsTrans' in file: D:\xampp\htdocs\my-project\common/extensions/JsTrans/JsTrans.php. Namespace missing?

  • You need to change the namespace in `common/extensions/JsTrans/JsTrans.php`. Namespace should be `namespace common/extensions/JsTrans;` – Insane Skull Aug 12 '21 at 12:25
  • That extension is for Yii 1.x not for Yii 2. – Michal Hynčica Aug 12 '21 at 12:32
  • @MichalHynčica Oh, I think I'm careless about this. Do you know the similar extension for Yii2? – Nadia R Aug 13 '21 at 02:44
  • It looks like there is [w3lifer/yii2-i18n-js](https://github.com/w3lifer/yii2-i18n-js) that seems to be similar. But, I've never used it. Or you can use some independent JS internationalization library for example check https://openbase.com/categories/js/best-javascript-internationalization-libraries – Michal Hynčica Aug 13 '21 at 06:56
  • @MichalHynčica Thank you. I've tried that yii-i18n-js extension. It works well and simple. – Nadia R Aug 14 '21 at 07:31

0 Answers0