angularjs/gettext: how to translate text in attributes

3.3k views Asked by At

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!

1

There are 1 answers

0
Elvin Valiev On

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>