Tiven Wang
Wang Tiven December 06, 2016
425 favorite favorites
bookmark bookmark
share share

SAP HANA platform及相关的产品如SAPUI5ABAP有多种开发对象Object的多语言Multiple Languages及翻译Translation问题,本文介绍HANA涉及到的多语言功能和翻译工具,及SAPUI5和ABAP的多语言的使用,并且介绍实际场景中需要注意的一些问题。最后特别说明对中文不同标识的处理方式。

HANA Multiple Languages

HANA多语言情景有Modeler Object Labels与Text Bundles file for SAPUI5 Applications及通用的Resource Bundles。

  1. Modeler Object Labels
  2. Text Bundles
  3. Resource Bundles

Modeler Object Labels

SAP HANA Modeler对象的Labels有翻译功能,有两种翻译的方式:

Text Bundles

Text bundles文件是HANA专门存储可翻译文本的数据库文件类型,其文件扩展名为.hdbtextbundle。相对于其他平台使用添加不同国家标识后缀的properties文件作为不同语言的文本文件,HANA Text bundles文件即翻译是存储在HANA数据库中,HANA根据应用程序的语言设置来自动选择相应的语言文本。Text bundles文件翻译使用Repository Translation Tool (rtt)。

在UI5中加载bundle文件的代码如:

// require the jQuery.sap.resources module     
 jQuery.sap.require("jquery.sap.resources");   
// load the resource bundle
var oBundle = jQuery.sap.resources({
  // specify url of the .hdbtextbundle
  url : "i18n/messagebundle.hdbtextbundle"
});

Resource Bundles

UI5还可以使用Resource Bundles方式翻译文本,即使用添加不同国家标识后缀的properties文件作为不同语言的文本文件。

<FileName>.properties // 包含原始关键字和文本
<FileName>_en.properties // 包含英语文本
<FileName>_en_US.properties // 包含美国英语文本
<FileName>_en_UK.properties // 包含英国英语文本

Translation Tool

HANA中的翻译工作有多种方式:

HANA Studio

//TODO

Online Translation Tool

Open the Online Translation Tool in HANA Cockpit. Select the delivery unit and package which includes the artifacts that need to be translated. Then you can add the text’s target language text.

The privileges required to use the SAP HANA Online Translation Tool (OTT) are granted in the role sap.hana.xs.ott.roles::translator .

the path of online translation tool is /sap/hana/xs/translationTool/

Repository Translation Tool

The Repository Translation Tool (RTT) is a Java-based command line tool shipped with the SAP HANA client that enables you to transport language files in a standard format between the SAP HANA repository and a file system or between the SAP HANA repository and a dedicated SAP translation system.

// TODO

Translation tools in ABAP

Setting Up and Coordinating Translation (BC-DOC-TTL)

Language Support with SAP HANA Transport for ABAP

SAP HANA Transport for ABAP (HTA) supports synchronizations of texts from SAP HANA to ABAP in the original language of the SAP HANA package. The synchronized texts can be translated using the standard ABAP translation tool (transaction SE63) and then transported.

Open the transaction SE63, select the Short Texts button, search the object type ID HOTS in the Object Type Selection popup, then select the HANA Object Name which you need to translate then select the source and target language settings, then edit.

// TODO how to transport back translated languages to HANA ?

SAP Translation Hub

SAP HANA Cloud Documentation - SAP Translation Hub (Beta)

// TODO

Language codes

Browser

大部分浏览器的语言编码所使用的标准是BCP-47,如deen-USzh-Hans-CN

HANA Platform

HANA平台使用的语言编码标准和JAVA Locale class使用的标准一样,是ISO 639 alpha-2 or alpha-3的小写字母语言编码加上ISO 3166 alpha-2的国家编码,用下划线分开,还可以再加第三个变量标识。 如deen_USzh_TW_Traditional

从JDK 1.7开始也支持BCP-47标准了。

HANA Session Locale

使用下面的SQL可以查看当前会话的语言代码:

select
  session_context('LOCALE_SAP'), -- SAP Language code in HANA Session
  session_context('LOCALE')      -- HANA Language code in HANA Session
from dummy;

Change HANA Session Locale

Right-clicking onto the system/logon-entry in the ‘Navigator’ -> [Properties] -> [Database User Logon] -> [Additional Properties]. Change HANA Studio Locale

ABAP-based

为了兼容性,ABAP-based SAP application servers使用的是SAP专有Language codes(参见SAP系统表T002),其基本符合ISO 639 alpha-2 language code。如果SAPUI5应用程序连接ABAP-based SAP应用服务器,默认URL参数sap-language的值为SAP专有Language codes,会被自动转成BCP-47 language tag,如

SAP Language Code BCP47 Language Tag Description
ZH zh-Hans ZH is the SAP language code for Simplified Chinese. The most generic representation in BCP47 is zh-Hans. zh-CN (Chinese, China) is another representation, but SAPUI5 decided to use zh-Hans.
ZF zh-Hant ZF is the SAP language code for Simplified Chinese. The most generic representation in BCP47 is zh-Hant. zh-TW (Chinese, Taiwan) is another representation, but SAPUI5 decided to use zh-Hant.
1Q en-US-x-saptrc 1Q is a technical SAP language code used in support scenarios, for example for translation issues. When you select this language code, the technical keys are display instead of the actual data. As no ISO639 code for this exists, the information has been added as a BCP47 private extension to the en-US language tag: “trc” stands for “trace” or “traceability”.
2Q en-US-x-sappsd 2Q is also used as a technical SAP language code in support scenarios and displays a pseudo translation (“psd” in the private extensions name).

详情参考Identifying the Language Code / Locale

HANA Languages in Use

System View for HANA Object Label

HANA数据库对象的标签存在系统view _SYS_REPO.ACTIVE_OBJECT_TEXT_CONTENT 中,通过此View可以查询不同对象的不同语言的标签。

select
  *
from _SYS_REPO.ACTIVE_OBJECT_TEXT_CONTENT
where package_id = '<package id>'
and object_name = '<object name>'
and lang = 'zh';

Select the labels of fields in HANA view from system view bimc_dimension_view in schema _SYS_BI, the language indicated by session context variable LOCALE. Check it by executing

select session_context('LOCALE') from dummy;

If you want to change the language environment setting of HANA studio, please reference change the session locale in HANA studio

mdx select
     dimension_type,
     cube_name,
     is_private_attribute,
     catalog_name,
     dimension_unique_name,
     dimension_catalog_name,
     column_name,
     dimension_caption,
     column_caption
from bimc_dimension_view
where ( catalog_name = '<package id>'
     and ( cube_name = '<object name>'
           or ( cube_name = '$ATTRIBUTE'
                and dimension_unique_name = '[<object name>]' ) ) )
order by catalog_name,
     dimension_unique_name
;

Automatic decide Language code in HANA

在HANA中如何根据会话Session自动选择语言,有三种情况:

HANA View Filter

在HANA Modeler View中可以在语言列上使用 input parameter : filter="$$language$$"

HANA View Text Join

在HANA View中使用Text Join类型来关联join语言类数据表,然后可以选择决定语言的field

HANA CDS or SQL

在HANA CDS或者SQL中则可以使用

where
  <LANG column> =
  (LOWER(SUBSTRING( (SELECT SESSION_CONTEXT('LOCALE') FROM "DUMMY") ) )

ABAP on HANA

通常ABAP中的语言是登录GUI时给定的,存储在系统变量SY-LANGU中,但有时需要在ABAP程序中指定语言,可以使用ABAP语句set locale language <language code>.指定。这样在ABAP中使用sql查询HANA DB时会话就是相应的语言代码了。

例如:ABAP中指定 set locale language '1'. ,ABAP调用HANA时结果 SELECT SESSION_CONTEXT('LOCALE') FROM "DUMMY" 为’zh’。

SAPUI5

对于SAPUI5 app来说,如何判断当前语言及应该加载哪个语言版本的Resource Bundle有一系列判定条件(序号越大的优先级越高):

  1. Hard-coded UI5 default locale (‘en’)
  2. 有的可能配置了浏览器语言(window.navigator.browserLanguage),对于Internet Explorer这个是操作系统的语言
  3. 有的可能配置了用户语言(window.navigator.userLanguage),对于Internet Explorer这个是地区语言
  4. 浏览器通用语言配置(window.navigator.language)
  5. Android手机浏览器(window.navigator.userAgent)
  6. 新的标准(window.navigator.languages),这是数组取第一个
  7. 配置在the application coding (jsdoc:symbols/sap.ui.core.Configuration)
  8. 配置URL parameters (?sap-language=zh)

可以通过Configuration API获取当前语言
var sCurrentLocale = sap.ui.getCore().getConfiguration().getLanguage();

对于Chrome浏览器变量window.navigator.languagewindow.navigator.languages的设置是在 Settings -> Show advanced settings -> Languages -> Languages and input settings
被设为Displayed的语言代码即是window.navigator.language
添加在这里的Languages从上至下按顺序即是window.navigator.languages

UI5 with ABAP

Cookie sap-usercontext=sap-language=EN

//TODO

中文

由于 ABAP Language 只有 ZHZF 两种中文语言,所以在映射到 HANA 的时候 ZH 只能映射到 zh 或者 zh_CN, 并不能区分开。 所以 HANA 也在修复这个Bug,在不久未来的某个版本 HANA 会增加根据ABAP Locale Language 和 Country两个属性决定映射的语言环境。

总结

<<未完>>

Similar Posts

  • SAP HANA Database SAP HANA is an in-memory, column-oriented, relational database management system developed and marketed by SAP SE. Its primary function as database server is to store and retrieve data as requested by the applications. In addition, it performs advanced analytics (predictive analytics, spatial data processing, text analytics, text search, streaming analytics, graph data processing) and includes ETL capabilities as well as an application server.
  • SAP ABAP CDS
  • Unit Test by Spring MVC Test Framework Testing is an integral part of enterprise software development. Dependency Injection should make your code less dependent on the container than it would be with traditional Java EE development. This topic introduce how to create Unit Test by Spring MVC Test Framework for Java project on HCP
  • Apply Spring Data JPA to Java Project on HCP Spring Data’s mission is to provide a familiar and consistent, Spring-based programming model for data access while still retaining the special traits of the underlying data store. Spring Data JPA, part of the larger Spring Data family, makes it easy to easily implement JPA based repositories. This module deals with enhanced support for JPA based data access layers. It makes it easier to build Spring-powered applications that use data access technologies.
  • Apply Spring Architecture to Java Project on HCP The Spring Framework is an application framework and inversion of control container for the Java platform. The framework's core features can be used by any Java application, but there are extensions for building web applications on top of the Java EE platform. Although the framework does not impose any specific programming model, it has become popular in the Java community as an alternative to, replacement for, or even addition to the Enterprise JavaBeans (EJB) model. I will show you how to apply Spring Frameworks to Java project on HANA Cloud Platform.
  • Persistence Service for Java Maven Project on HCP The Java Persistence API (JPA) is a Java specification for accessing, persisting, and managing data between Java objects / classes and a relational database. JPA was defined as part of the EJB 3.0 specification as a replacement for the EJB 2 CMP Entity Beans specification. In this topic I will show you how to create persistence service for Java project on HCP using Java Persistence API (JPA) and it's implementation EclipseLink

Comments

comments powered by Disqus
Back to Top