SAP UI5 标准应用的多语言支持 - SAP UI5 运行时语言判定机制

SAP UI5 对多语言的支持特性如下:

The language codes according to the de facto standard BCP-47, which are used by most browsers for language identification. As of JDK 1.7 they are also supported by the Java locale class.

目前大多数浏览器都支持了事实上的标准,BCP-47 里定义的 language code,用来做语言识别。例子:de, en-US, zh-Hans-CN

The Java Locale syntax that combines a lower case ISO 639 alpha-2 or alpha-3 language code with an ISO 3166 alpha-2 country code. Both codes are combined with an underscore. An arbitrary sequence of variant identifiers (also separated by underscores) can be appended as a third component.

另一方法,Java Locale 语法,使用 underscore,即下划线,来连接 ISO 639 alpha-2 (或者alpha-3)以及 ISO 3166 alpha-2 (或者alpha-3), 前者指代 language code,后者指代 country code. 同时,这两部分之后,可以再通过下划线,连接额外的 variant identifier.

例子:de, en_US, zh_TW_Traditional

The SAP proprietary language codes - SAP 专有语言代码

SAPUI5 applications are often used to connect to ABAP-based SAP application servers. These servers use SAP proprietary language codes for compatibility reasons.

SAP UI5 应用可以用来消费 SAP ABAP 服务器上暴露出来的 OData 服务,这些服务器出于兼容性原因,使用 SAP 专有的 language code.

These language codes often match an ISO 639 alpha-2 language code, but not in all cases.

SAP 专有 Language code 通常都和 ISO 639 alpha-2 里定义的 Language code 一一对应,但并不总是如此。

If the language code for a SAPUI5 application is specified with the traditional URL parameter sap-language, SAPUI5 assumes that it is a SAP proprietary language code and converts it to a BCP-47 language tag.

注意,如果用户在 SAP UI5 URL 参数,即 sap-language 里传入一个 code,SAP UI5 会默认将其视为一个 SAP 专有 Language code,并试图将其转换成 BCP-47 对应的 code.

转换规则如下:


SAP UI5 运行时语言判定机制

SAPUI5 has the notion of a current language. It is determined from the following sources of information. The sources are ordered increasingly by priority and the last available user language/locale wins.

SAP UI5 引入了“当前语言”,即运行时语言的概念。SAP UI5 加载的所有国际化文本资源(i18n resouces),都基于该当前语言加载。SAP UI5 运行时语言,使用下列逻辑来决定。下列规则按照优先级从低到高的顺序罗列出来,即越后面的规则,优先级越高。

  1. Hard-coded UI5 default locale ('en') - 硬编码的默认 locale

  2. Potentially configured browser language (window.navigator.browserLanguage); for Internet Explorer this is the language of the Operating System.

浏览器里设置的语言。如果是IE,window.navigator.browserLanguage 指代操作系统的语言。

  1. Potentially configured user language (window.navigator.userLanguage); for Internet Explorer this is the language in the Region settings.

用户语言设置。在 IE 里指代 Region Settings里设置的语言。

注:Jerry 本地测试过,window.navigator.browserLanguage 和 window.navigator.userLanguage 都为空。

  1. General language information from the browser

浏览器语言设置:window.navigator.language,在我的机器上为:en-US

  1. 使用 SAP UI5 configuration API 设置语言:sap.ui.getCore().getConfiguration().setLanguage()
  1. Locale configured via URL parameters

采用 url 参数 sap-language=ZH 设置的语言,具有最高的优先级。如下例子所示:

https://gm4:44355/sap/bc/ui5_ui5/ui2/ushell/shells/abap/FioriLaunchpad.html?sap-language=ZH&sap-client=001#Opportunity-manageOpportunity&/detail/Opportunities(guid'FA163EE5-6C3A-1ED7-B883-0ED9A99A201F')

SAP UI5 自动加载 i18n_zh_CN.properties 文件:

加载该 .properties 文件,使用的Content-Type为: application/octet-stream; charset=UTF-8

最后加载的 Fiori Launchpad html 里定义的content 为:text/html; charset=UTF-8

更多Jerry的原创文章,尽在:"汪子熙":


你可能感兴趣的:(SAP UI5 标准应用的多语言支持 - SAP UI5 运行时语言判定机制)