Javascript 中 ISO 639-1 代码中的语言名称
我正在建立一个网站,人们可以在其中将语言信息与内容相关联.
I'm building a website where people can associate a language information to content.
网站大量使用 Javascript,与各种元素相关的语言信息在内部被视为 ISO 639-1 代码.
The website uses Javascript heavily and the language information associated to various elements is treated internally as an ISO 639-1 code.
如何以用户的语言显示语言名称列表?
How to show a list of language names - in the language of the user ?
推荐答案
在 new(ish) 国际 API:
There is a native support for this in the new(ish) Intl API:
let languageNames = new Intl.DisplayNames(['en'], {type: 'language'});
languageNames.of('fr'); // "French"
languageNames.of('de'); // "German"
languageNames.of('fr-CA'); // "Canadian French"
相关文章