javascript 使用 Angular-translate 进行参数格式化
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20095142/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Argument formatting with Angular-translate
提问by Oleg Belousov
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.
最近我遇到了这个库,我看起来很有前途,我知道它被广泛使用并支持各种简洁的功能,例如语言 JSON 上的异步加载、使用本地存储等。
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'
一件很简单的事情是字符串格式化\将参数传递给翻译过滤器,似乎不受支持:例如:“你已经成功地用 %S 唱歌”
A certain param filter, such as:
某个参数过滤器,例如:
$translateProvider.translations('en', {
AUTH_SUCCESS : '%s, You have successfully singed in with %s'
}
HTML:
HTML:
<span>{{AUTH_MESSAGE | translate : [$scope.name, $scope.network]}}<span>
Is there anything that can serve that kind of purpose in this library?
在这个图书馆里有什么可以达到这种目的的吗?
回答by Pascal Precht
Well, it isdocumented 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
看看这个:http: //angular-translate.github.io/docs/#/guide/06_variable-replacement
回答by Oleg Belousov
Found the answer, apparently they have a wide support for this feature, just not documented at the main docs \ README.md
找到了答案,显然他们对此功能有广泛的支持,只是在主文档\ README.md 中没有记录