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文件,从而实现软件界面国际化。

你可能感兴趣的:(eclipse,UI,.net)