Tips & Tricks Tutorials

i18n support

It is widely announced that the recently released version 5.1 of IntelliJ IDEA provides an “industry-leading i18n support”. But what does that mean? Well, this phrase covers not just one particular feature, but the whole set of enhancements, improvements, and new features for making internationalization faster and easier.
First of all, the “Hard coded strings” inspection helps you to quickly find all hard-coded string literals at once, instead of thoroughly scanning all files in the project.
With this inspection switched on, the literals are highlighted right in the editor. Also you can inspect the code and see the results in the devoted window.

When the hard-coded string is found, it may need internationalization, or it may represent some identifier that does not depend on localization (and that’s often the case). IntelliJ IDEA smartly handles both variants.
If you decide to internationalize the string, just use the intention action, and the string will be added to an existing .properties file.
i18nize action
IntelliJ IDEA also handles situations when a hard coded String literal is a part of a concatenated string. In this case, the generated property string will contain all necessary parameters.
i18nize concatenation action
For the strings that don’t need internationalization, there is a special intention action. With this action you can annotate strings as @NonNls and therefore exclude them from the internationalization process. It is possible to annotate a certain variable or class field as well as a whole method, class, or even package. Just don’t forget to add annotations.jar to your project or module classpath to make the annotation and related intention actions available.
non_nls annotation
Note that @NonNls annotation is not required for values representing property keys. IntelliJ IDEA recognizes them automatically.
Get interested? See i18n demo.

Note   This tip&trick was originally posted at www.javalobby.org.

Technorati tags: internationalization, localization
image description