简体   繁体   English

如何使用bower包含AngularJS I18n文件中的特定区域设置?

[英]How to include specific locale from AngularJS I18n files using bower?

I've downloaded the angular I18n repo using bower install angular-i18n which pulls it into my bower_compontents and updates the bower.json file with angular-i18n : 1.5.3 , which is expected behavior. 我已经使用bower install angular-i18n下载了角度I18n repo,它将它拉入我的bower_compontents并使用angular-i18n : 1.5.3更新bower.json文件,这是预期的行为。

I want to include a specific locale(ex. de-de.js) in my build process so that it gets included along with the other angular scripts, every time I run grunt serve which isn't happening at the moment. 我希望在我的构建过程中包含一个特定的语言环境(例如de-de.js),以便它与其他角度脚本一起被包含在内,每次我运行当前没有发生的grunt serve Any ideas how this can be achieved? 任何想法如何实现这一目标?

Thanks. 谢谢。

In my case, I added in my bower file the specific version that i need using the link of the raw version of the file angular-locale_es.js . 在我的情况下,我使用文件angular-locale_es.js的原始版本的链接在我的凉亭文件中添加了我需要的特定版本。 bower.json bower.json

"dependencies": {
    "angular": "^1.5.0",
    "angular-mocks": "^1.5.0",
    ...
    "angular-locale_es": "https://raw.githubusercontent.com/angular/bower-angular-i18n/master/angular-locale_es.js",
     ...
  }

In your bower.json you can add an overrides section and specify the i18n script you want to include. 在您的bower.json中,您可以添加覆盖部分并指定要包含的i18n脚本。

 { "name": "your application", "version": "1.1.2", "dependencies": { "angular": "#1.5.7", "angular-i18n": "#1.5.7", "moment": "#2.13.0", }, "overrides": { "angular-i18n":{ "main":[ "angular-locale_de-ch.js" ] }, "moment": { "main": [ "moment.js", "locale/de.js" ] }, } } 

So to answer my own question, if you only want one of the locales you can copy and replace the contents of the de-de.js locale into the main angular-i18n file, which is hassle free and does not require a complicated approach. 因此,要回答我自己的问题,如果您只需要其中一个语言环境,则可以将de-de.js语言环境的内容复制并替换为主angular-i18n文件,这样无忧无虑且不需要复杂的方法。

However if you have multiple locales and want to make a decision based on a condition, you can set a default locale using this library 但是,如果您有多个语言环境并希望根据条件做出决定,则可以使用此库设置默认语言环境

https://github.com/lgalfaso/angular-dynamic-locale/ https://github.com/lgalfaso/angular-dynamic-locale/

after which all you have to do is add a base location for your locale files(I'm using the CDN for example): tmhDynamicLocaleProvider.localeLocationPattern('https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.5.5/angular-locale_{{locale}}.js'); 之后你要做的就是为你的语言环境文件添加一个基本位置(例如我使用的是CDN): tmhDynamicLocaleProvider.localeLocationPattern('https://cdnjs.cloudflare.com/ajax/libs/angular-i18n/1.5.5/angular-locale_{{locale}}.js');

check for your condition and pass the locale as $translate.use('de'); 检查您的情况并将区域设置传递为$translate.use('de');

Hope that helps! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM