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

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

问题描述

我试图找到在AngularJS文档,支持多国语言,但没有成功。是本地化支持?

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

推荐答案

看看角翻译:<一href=\"https://github.com/angular-translate/angular-translate\">https://github.com/angular-translate/angular-translate

所有DIY乡亲:

您可以找到角度本地化文件:这里

You can find localized files for angular: here

这些文件将帮助您与内置的角度过滤器:日期,的currency 的。惊艳...为止。

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。 (服务器是最好的选择了!)

  • 如果您包括角度本地文件之一,你并不需要设置它您的应用模块中。 (您将自动获得$区域 - 见小提琴)

  • 添加ID关键是你的$提供价值 - 和c使用的是在你的文件中的值设置为语言$ C $ - 这将是派上用场的测试。

  • 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.

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

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