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

44次阅读

共计 2588 个字符,预计需要花费 7 分钟才能阅读完成。

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_…

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 的原创文章,尽在:” 汪子熙 ”:

正文完
 0