Angular js 支持本地化 [英] Angular js support for localization

查看:26
本文介绍了Angular js 支持本地化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在 AngularJS 中找到支持多种语言的文档,但没有成功.是否支持本地化?

I tried to find documentation in AngularJS for supporting multiple languages with no success. Is localization supported?

推荐答案

看一看 angular-translate:https://github.com/angular-translate/angular-translate

Take a look at angular-translate: https://github.com/angular-translate/angular-translate

对于所有 DIY 的人:

for all DIY folks:

您可以找到 angular 的本地化文件:此处

You can find localized files for angular: here

这些文件将帮助您使用内置的角度过滤器:date货币编号.太棒了……到目前为止.

These files will help you with the build-in angular filters: date, currency and number. Amazing... so far.

现在你想使用你自己的文本,你需要的只是 angular.js 依赖注入的强大功能.创建一个新文件,如:myTexts_en_us.js"并像这样使用 $provide.value:

Now you want to use your own texts, than all you need is the power of angular.js dependency injection. Create a new file like: "myTexts_en_us.js" and use $provide.value like this:

$provide.value("myTexts", {firstText : "This is my localized text"});

详情:
http://jsfiddle.net/4tRBY/24/

对于实际使用,您应该添加过滤器:http://jsfiddle.net/4tRBY/41/

For real-world-use, you should add a filter: http://jsfiddle.net/4tRBY/41/

提示:

  • 确保手动、JS 或服务器将新的本地化文件插入到 html 中.(服务器是这里的最佳选择!)
  • 如果您包含 angular-local 文件之一,则不会需要在您的应用程序模块中进行设置.(您将自动拥有 $locale - 请参阅小提琴)
  • 向您的 $provide-value 添加一个 id 键 - 并将该值设置为您在文件中使用的语言代码 - 这将有助于测试.
  • Make sure to insert your new localization-file into your html by hand, JS or Server. (Server is the best choice here!)
  • if you include one of the angular-local files, you do not need to set it up in your app module. (you will have $locale automatically - see the fiddle)
  • add an id key to your $provide-value - and set the value to a language code you are using in your file - this will be come in handy for testing.

这篇关于Angular js 支持本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆