dongren1986
dongren1986
2013-11-20 11:49
浏览 286

使用Angular-translate进行参数格式化

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?

图片转代码服务由CSDN问答提供 功能建议

最近我遇到了这个库,我看起来很有前途,我知道它被广泛使用并支持各种简洁的功能,如语言JSON上的异步加载,使用本地存储等等。

但有一点非常简单,就是字符串格式化\传递参数到翻译过滤器,似乎不受支持: 例如:'你已经成功地使用了%S'

某个参数过滤器,例如:

  $ translateProvider.translations('en',{
AUTH_SUCCESS:'%s, 您已成功使用%s'
} 
   
 
 

HTML:

 &lt; span&gt; {  {AUTH_MESSAGE |翻译:[$ scope.name,$ scope.network]}}&lt; span&gt; 
   
 
 

是否有任何可以用于此类目的的内容 这个库?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dtv8189
    dtv8189 2014-01-17 08:37
    已采纳

    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

    点赞 评论
  • dongshi3361
    dongshi3361 2013-11-20 13:29

    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

    点赞 评论

相关推荐