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 執行時語言,使用下列邏輯來決定。下列規則按照優先順序從低到高的順序羅列出來,即越後面的規則,優先順序越高。
- Hard-coded UI5 default locale ('en') - 硬編碼的預設 locale
- Potentially configured browser language (window.navigator.browserLanguage); for Internet Explorer this is the language of the Operating System.
瀏覽器裡設定的語言。如果是IE,window.navigator.browserLanguage 指代作業系統的語言。
- 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 都為空。
- General language information from the browser
瀏覽器語言設定:window.navigator.language,在我的機器上為:en-US
- 使用 SAP UI5 configuration API 設定語言:sap.ui.getCore().getConfiguration().setLanguage()
- 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的原創文章,盡在:"汪子熙":