angularjs学习笔记(3)–i18n使用

项目中用到angular-ui-bootstrap插件中的datepicker,可是datepicker显示的星期和月份是英文的,我需要他们都显示成中文的,最简单的方法就是用angularjs的i18n(Internationalization, 简称i18n)。
官方文档告诉我们,我们只需引入相应的local文件就好了,例如我要引入中文的i18n文件,只需引入angular-locale_zh-ch.js。然后将ngLocal模块注入我的当前工作模块即可。

其中angular-locale_zh-ch.js如下所示:

ngLocal就是一个模块,支持日期,数字和货币的国际化和本地化。另外,AngularJS还通过ngPluralize指令支持本地多元化。看下面这个例子:

https://github.com/angular/angular.js/blob/master/i18n/e2e/localeTest_zh.html

localTest_cn.html:(很抱歉目前html代码只能贴图,一时没找在wordpress里贴html代码而html特殊符号显示正常的方法,因为尖括号就是典型的html特殊符号。)

 

还有一种方法就是自定义i18n,毕竟官方给的i18n支持的本地化仅作用于日期,数字和货币。看下面的例子。

http://jsfiddle.net/7zdpa/
index.html

app.js

效果如图

angularjs学习笔记(3)–i18n使用》上有384条评论

  1. 张迪张迪

    这篇文章写的很好,前因后果都讲的清楚,并伴随有例子,i18n这一部分由于我之前并不需要所以没有仔细看过,但是看了元帅这篇文章我感到我立即就学会了。

    回复
  2. 张迪张迪

    突然发现i18n还有一种用法,就是前端有些文字的设置,可以统一保存在i18n.js文档里。
    就像以前做php的时候系统名称等信息统一存放在config.php里一样。
    这非常有用,尤其是在更改名称时候,不必到每个含有该名称的页面去修改。
    我觉得非常有必要将之扩展,加载在目前的项目里。

    回复
  3. Pingback引用通告: URL

  4. Angelina

    I’m retired http://www.theformation-cc.co.uk/building-a-brand buy bimatoprost amazon The shares gained as much as 11pc after the company said in its half-year update that its improving order book in American construction has been translating into revenue, supporting its forecast of a rise in revenue over the next six months. The stock later dropped back somewhat to trade around 4pc up at 228p by early afternoon on Thursday.

    回复
  5. Cole

    Will I have to work shifts? http://www.theformation-cc.co.uk/building-a-brand bimatoprost generic price At the event, Olander said the new device is also more water-resistant, provides hourly reminders to get users moving more and lets users tag their sessions so that they can better track their activity. For example, users who practice yoga can now get credit for the activity, even though their arms may not move.

    回复
  6. Irea

    Just over two years http://www.hamptonframes.com/about-us/ purchase promethazine online Boomers represent the past and millennials are the future, so there’s hope for a better political system. As more and more millennials become eligible to vote, they will have an even more profound influence on American politics. They know how to work together to make things better. Things will only get better because they can’t get much worse.

    回复
  7. Hunter

    How much is a Second Class stamp? zyban mg Ping An’s conglomerate model and exposure to banking isunique among Chinese insurers, and can be traced back to itsclose ties with the Communist Party, which helped it avoid beingbroken up in the wake of the Asian financial crisis.

    回复
  8. Emma

    Your cash is being counted Acticin Permethrin Cream There were two turning points. The first came after the Giants moved into position to regain the lead just before halftime when Manning, on first down from the Broncos 28, was flushed out of the pocket and intercepted in the end zone, where Hakeem Nicks was double covered. Manning expected Nicks to go outside and he didn’t – but he also missed seeing Victor Cruz open underneath, the second time in the game where pass pressure forced him to miss seeing an open man.

    回复
  9. Juan

    What sort of work do you do? geodon 20 mg A group of 28 Greenpeace activists, a Russian photographer and a British videographer have been held since their ship, the “Arctic Sunrise” was seized by the Russian coast guard after protesting outside a Gazprom-owned oil rig Sept. 18.

    回复
  10. Camila

    We’ve got a joint account where can i buy levofloxacin “The sounds I was hearing were plants being thrown, like the potted plants being broken on the floor…they were turning chairs over, they were throwing down garbage cans – whatever was moveable in the mall they were turning it over,” one witness told local NBC4.

    回复
  11. James

    Children with disabilities maxalt coupons A lawyer involved with the case told Reuters that Barcenas, a once-trusted aide, turned over documents showing how he ran a secret slush fund at the party for many years, and provided details of years of cash payouts to party leaders.

    回复
  12. Emma

    Very interesting tale buy pantoprazole A first-ever U.S. default on debt or other payments could trigger a massive drop in global stock markets, push up borrowing costs sharply and cause businesses to stop hiring and consumers to stop spending, grinding the economy to a halt, analysts say.

    回复
  13. Elizabeth

    We need someone with qualifications nizagara tablets medicine “The Atlanta Braves extend our sincerest and heartfelt condolences to Mr. Homer’s family and friends,” the statement read. “We are saddened by this tragic incident and will continue our investigation along with the Atlanta Police Department.”

    回复
  14. Nigel

    I’ve got a very weak signal capital loan His finest moment against the AFC East rivals came during the 2010 divisional playoffs when he devised a brilliant game plan with then-defensive coordinator Mike Pettine to propel the Jets to a second consecutive AFC Championship Game. Brady, who was sacked five times, was skittish from start to finish that night.

    回复
  15. Pingback引用通告: buybacklinkscheap.com pussy eating

Eli进行回复 取消回复

电子邮件地址不会被公开。 必填项已用*标注