yii2-translate-manager icon indicating copy to clipboard operation
yii2-translate-manager copied to clipboard

Javascript not being translated

Open BjornNystrom opened this issue 3 years ago • 3 comments

So I have an issue, and it appeared when i swapped over my application from the basic template to advanced, or somewhere along the line. translate manager finds my strings and they are stored in the database, however when presenting the messages they are not translated.

Now I am sure I am missing something in my configuration but I can not seem to find it...

If i place some console logs in the generated lajax.js in assets I can see that it receives the message but if i do a console.log on languageItems it tells me it is undefined. And I am not sure how to define this variable.

Anyone have any ideas?

PS! the php translations works a charm

BjornNystrom avatar Dec 08 '21 08:12 BjornNystrom

namespace common\controllers;

use lajax\translatemanager\helpers\Language;

// IMPORTANT: all Controllers must originate from this Controller!
class Controller extends \yii\web\Controller {

    public function init() {
        Language::registerAssets();
        parent::init();
    }
}

panrus avatar Dec 08 '21 13:12 panrus

Thanks for the reply I have a controller that all other controllers originate from that I've called BaseController and I have this script in that one, however I've used the full: \lajax\translatemanager\helpers\Language::registerAssets(); since I have another class called Language used in this controller, could this be the problem? that I have 2 language classes here?

BjornNystrom avatar Dec 08 '21 14:12 BjornNystrom

I'm slightly thinking Where does the javascript bit get the language from, because we have done some modifications to the language select where we create cookies etc based on what user has in their settings or the browsers language etc, and while we do set Yii::$app->language; correctly, im thinking if the cookie is wrong for what is needed for JS or if there is something else we need to set in order for the javascript to know what language to use.

BjornNystrom avatar Dec 08 '21 15:12 BjornNystrom