Angular 5 中的语言环境 [英] Locales in Angular 5
问题描述
我不熟悉语言环境的概念.据我所知,我制作了一个 Angular 4 应用程序,它可以使用 navigator.language()
API 从浏览器读取语言环境并提供给 Angular 的管道.由于 v5 中所有这些都发生了变化,因此我对迁移有一些疑问.
I am new to the concept of locales. From what I could understand, I made an Angular 4 app that would read the locale from the browser using the navigator.language()
API and supply to Angular's pipes. Since all of this changes with v5, I have some questions around migration.
我的理解是这里的列表:https://github.com/angular/angular/tree/master/packages/common/locales 提供了可以提供给 registerLocaleData()
的语言环境列表.
My understanding is that the list here: https://github.com/angular/angular/tree/master/packages/common/locales provides a list of locales that can be supplied to registerLocaleData()
.
因此,我可以从 '@angular/common/locales/en-IN'
和 registerLocaleData(localeEnIn)
导入 localeEnIn 来激活语言环境.
Thus, I can import localeEnIn from '@angular/common/locales/en-IN'
and registerLocaleData(localeEnIn)
to activate the locale.
要在浏览器的语言环境中自动加载应用程序,我必须使用 navigator.language()
API 来获取语言环境 ID(比如en-GB")并调用 registerLocaleData(localeEnGb)
其中 localeEnGb
从上面的列表中导入.这可以在我不必指定所有语言环境的情况下自动执行吗?
To automatically load the app in the browser's locale, I will have to use the navigator.language()
API to get the locale ID (say "en-GB") and call registerLocaleData(localeEnGb)
where localeEnGb
is imported from the list above. Can this be automated without me having to specify all locales?
有像 en
和 de
这样的语言环境.我应该拆分 navigator.language()
的响应并只提供en"吗?
There are locales like en
and de
. Should I split the response of navigator.language()
and supply just "en"?
推荐答案
这对我来说也很成问题:
This is so problematic also for me:
请在此处找到所有 Angular 5 语言环境的导入:http://iteration.info/Sharing/AllAngular5Locales.rtf
Please find here an import of ALL the Angular 5 locales : http://iteration.info/Sharing/AllAngular5Locales.rtf
我希望在 Angular 6 中能做到:
I hope in Angular 6 will do :
import locales($var);
这篇关于Angular 5 中的语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!