Argument formatting with Angular-translate
Asked Answered
Q

2

13

Lately I've encountered this library, I looks very promising, and I understand that it's widely used and supports all kinds of neat features such as asynchronous loading on languages JSONs, using local storage, etc etc.

One thing that is quite trivial though, is string formatting \ passing parameters to the translate filter, doesn't seem to be supported: for instance: 'You have successfully singed in with %S'

A certain param filter, such as:

$translateProvider.translations('en', {
AUTH_SUCCESS : '%s, You have successfully singed in with %s'
}

HTML:

<span>{{AUTH_MESSAGE | translate : [$scope.name, $scope.network]}}<span>

Is there anything that can serve that kind of purpose in this library?

Quartet answered 20/11, 2013 at 11:49 Comment(0)
M
29

Well, it is documented in the main docs, you just have to take a look at the main docs

{
    'AUTH_SUCCESS' : '{{ name }}, You have successfully singed in with {{ network }}'
}

.

<span>{{AUTH_MESSAGE | translate : '{name : $scope.name, network : $scope.network}' }}</span>

Check out this one: http://angular-translate.github.io/docs/#/guide/06_variable-replacement

Micron answered 17/1, 2014 at 8:37 Comment(3)
what happened with this page? It gives me a 404 error.Braze
it looks like it does not work with $ctrl: {{'USERS_ALL'|translate: '{usersCount:$ctrl.usersCount}'}}Strategist
@StepanSuvorov, you have to do {{'USERS_ALL'|translate: ({usersCount:$ctrl.usersCount})}}Transparent
Q
0

Found the answer, apparently they have a wide support for this feature, just not documented at the main docs \ README.md

Here is the answer

Quartet answered 20/11, 2013 at 13:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.