UWP 多语言的三个概念

首先了解一下 RFC4646 和 BCP-47 是什么东西:

RFC4646

The name is a combination of an ISO 639 two-letter lowercase culture code associated with a language and an ISO 3166 two-letter uppercase subculture code associated with a country or region.(所谓 RFC4646 是定义了语言标签的一套标准,在这个标准下,每一个语言标签由一个两个小写字母的语言标签和一个两个大写字母的国家/区域的国际域名缩写构成)

BCP-47

所谓 BCP-47 也是定义了语言标签的一套标准.

Note that this file is a concatenation of more than one RFC.(BCP-47 包含多个 RPC 文档)

This document replaces [RFC4646]. This document, in combination with [RFC4647], comprises BCP 47.(BCP-47 是由 RFC4646 和 RFC4747构成)

目前在 Windows 10中,.net framework4 及以后的.net framework 均支持 BCP-47。 UWP 表示多语言都用 BCP-47 中定义的标签。

在 Windows 10 和 UWP 中,关于多语言由三个概念:

1.用户语言列表(user profile language list):

可以使用如下接口获取,在Windows10中,实际就是设置中区域和语言里面的首选语言列表

Windows.System.UserProfile.GlobalizationPreferences.Languages

2.应用程序语言列表(App manifest language list):

开发UWP程序的时候,如果要支持多语言,就需要在配置文件中声明需要支持什么语言,在运行时,可以通过如下接口获取当前应用支持什么语言:

Windows.Globalization.ApplicationLanguages.ManifestLanguages

值得注意的是,我们要声明多种语言,可以自动声明,也可以自己手动添加。

3.运行时语言列表(App runtime language list):

在程序运行时,可通过如下接口获取,简单来说,所谓运行时语言列表,就是 1 和 2 中两种列表的交集,细微上还有点区别,可以参考最后的链接。

Windows.ApplicationModel.Resources.Core.ResourceContext.GetForCurrentView().Languages;
Windows.Globalization.ApplicationLanguages.Languages;

参考 doc.microsoft.com:

Understand user profile languages and app manifest languages

posted @ 2018-08-31 00:46  DemoApp  阅读(971)  评论(1编辑  收藏  举报