简体   繁体   中英

angularjs/gettext: how to translate text in attributes

I have a piece of html like this

<bar title="'My Title'"></bar>

Now, when I want to translate it, it looks like this

<bar title="'My Title'|translate"></bar>

The reason why I dont have {{ and }} is because the 'bar' directive binds the title to its scope with '='

scope: {
    title: '=',
    ...
}

The problem is that the task 'nggettext_extract' doesn't extract this text, because it is looking for things in between curly brackets. I found a hack to solve this problem:

<bar dummy="{{My Title'|translate}}" title="'My Title'|translate"></bar>

But I hope there is a better solution to this problem ?

UPDATE: The workaround I've implemented now is that I changed the directive as follows

scope: true,
link: function(scope, element, attrs) {
    scope.title = attrs.title;
}

Of course, if someone knows a better solution please let me know!

You can do something like this :

// Inside your controller

$scope.lbl = gettextCatalog.getString('Some text');

// And inside your template you can use

<bar title={{lbl}} > </bar>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM