Now when I want to transl...">

Angularjs / gettext: how to convert text to attributes

I have a html piece like this

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

Now when I want to translate it, it looks like

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

The reason I don't have {{and}} is because the 'bar' directive associates the header with its scope with '='

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

The problem is that the "nggettext_extract" task does not retrieve this text because it searches for things between braces. 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 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!

+6
source share
1 answer

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> 
0
source

Source: https://habr.com/ru/post/957432/


All Articles