Message Bundles(国际化)

Eclipse NLS class based (New method, recommended)

Overview

In this method, each plug-in maintains one Messages class, which extends the NLS class provided by Eclipse. This class loads each of keys from a messages.properties file into static Strings, which are referenced by the source code. This provides for compile-time checking, and eliminates the need for NON-NLS comments, as no hard-coded Strings are involved.

Structure

The messages.properties file and accompanying Messages class should be placed in the internal package of your plug-in:

$PLUGIN/src/$PLUGIN-AS-PACKAGE/internal/messages.properties
$PLUGIN/src/$PLUGIN-AS-PACKAGE/internal/Messages.java

For example, if your plug-in is net.refractions.udig.catalog.ui, it would look like:

net.refractions.udig.catalog.ui/src/net/refractions/udig/catalog/ui/internal/messages.properties
net.refractions.udig.catalog.ui/src/net/refractions/udig/catalog/ui/internal/Messages.java

Externalizing for the first time

Eclipse provides an Externalize Strings Wizard that can be used to automate this process very nicely.

  • Right click on a plug-in or source code file and select Source-->Externalize Strings...

Once inside the wizard, make sure you check "Use Eclipse's string externalization mechanism". If this is already checked and greyed out, then the plug-in is already configured to use it.

You are then presented with a list of values and keys. The keys are given numerical suffixes. Please change them to something more meaningful.

  • If a value should not be externalized, press Ignore
  • If you wish to do nothing, press Internalize
  • Press the Configure... button and make sure that the Messages class and messages.properties file are created in the proper directory (see above under "Structure")
生成默认版本(英文)的.properties文件后,使用插件ResourceBundleEditor建立各个语言的property文件,从而实现软件界面国际化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值