XPage Localization Process: How to translate properties files in bulk?

∥☆過路亽.° 提交于 2019-12-13 19:00:46

问题


We have a huge project with more than 100 Custom Controls and XPages in place and now we intend to provide the project in multiple languages.

Localization in XPages, provides this beautiful and a very simple way to convert the entire project in the other language via the properties file. However, in our case, many custom controls are kind of carbon copies of others and many of the translations/keywords are the same, it becomes kind of redundant to change the same thing again and again.

So the question is, is there a simpler approach, where we can probably do a bulk of translation together? Something, where we can export the entire translation as one file and import it back?

Any suggestion/help in the right direction would really be appreciated.


回答1:


Don't use XPage's build-in localization. It might work for a first translation but it's very difficult to maintain after (a lot of) changes in XPages.

Use a managed Java bean instead.
It manages own property files and implements Map interface.

You'd use the bean to get a string usually with EL.

Example:
Get name's label with str['name'] for following entry in property file

name=Name

Use java.text.MessageFormat for messages with data.
Create a method like getMessage(String name, Object arg1) in your bean.

Example:
Get the message for a missing view in JavaScript with
str.getMessage('message.view.not.found', viewName) for following entry in property file

message.view.not.found=Could not find view {0}



回答2:


Another approach would be to use manually created property-files

Here an example for two languages:

First of all you have to create the following two files under Resources/Files

messages.properties

global.welcome = Willkommen {0} auf meiner Webseite

messages_en.properties

global.welcome = Welcome {0} on my website

Now you can reference your message properties on every place in your code

<xp:this.resources>
    <xp:bundle src="/messages.properties" var="resMessage"></xp:bundle>
</xp:this.resources>

<xp:text escape="true" id="cfUser" themeId="Text.User">
    <xp:this.value><![CDATA[${javascript:I18n.format(resMessage['global.welcome'], sessionScope.commonUserName)}]]></xp:this.value>
</xp:text>


来源:https://stackoverflow.com/questions/33279559/xpage-localization-process-how-to-translate-properties-files-in-bulk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!