i18next / ng-i18next

translation for AngularJS using i18next
https://github.com/i18next/ng-i18next
MIT License
161 stars 54 forks source link

Sprintf also for filters #54

Closed nodecode closed 10 years ago

nodecode commented 10 years ago

It would be great if you could pass sprintf parameters also to the i18next filter.

I am thinking of a similar implementation as in angular-translate. Here you transmitted to the filter parameters as follows:

{{ 'TRANSLATION_ID' | translate:'{ username: "PascalPrecht" }' }}

Such an implementation in ng-i18next would be very helpful for my current project. Thank you in advance!

nodecode commented 10 years ago

BTW: The replace of normal variables like myVar is also not supported yet, right? That would be also a useful feature.

efolio commented 10 years ago

Hum… I don't understand. We currently do support filters with a key and an object of options/variables.

Example:

The translation in the namespace "my_ns": "greetings": "Hello __username__!"

Filter in JS:

$scope.user = {name: 'Etienne'};
var res = $filter('i18next')('greetings', {ns: 'my_ns', username: $scope.user.name});
// res === "Hello Etienne!"

Filter in HTML:

<p>{{'greetings' |i18next:{ns: 'my_ns', username: $scope.user.name}}}</p>
<p>{{'my_ns:greetings' |i18next:{username: $scope.user.name}}}</p>
<p ng-i18next="[i18next]({username: $scope.user.name})my_ns:greetings" />
<p ng-i18next>[i18next]({username: $scope.user.name})my_ns:greetings</p>
efolio commented 10 years ago

BTW, whereas we can do this with the filter syntax, using ng-i18next directives instead is better because they are:

I especially like and use the last format I gave in the example above (and you can indent if you like.

For example:

<p ng-i18next>
    [i18next]({
        username: $scope.user.name,
        gender: $scope.user.gender,
        role: '<span class="role">(' + $scope.user.role + ')</span>'
    })my_ns:greetings
</p>
nodecode commented 10 years ago

Ah ok, I thought that ng-i18next not support such a thing, because I have nowhere found a corresponding example. Then my request has completed. Thanks!