i18n support

Posted on by alexandra.rusina

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.

Comments below can no longer be edited.

3 Responses to i18n support

  1. larry says:

    January 7, 2008

    When I use this feature in 7.0.2, the dialog cannot be guided to my .properties file. It lists no files except java files. Is it filtering for .java instead of .properties?


  2. Thomas says:

    September 11, 2009

    I am still experiencing the same problems like Larry does.

  3. Felipe Micaroni Lalli says:

    December 10, 2012

    Please make it ignores debug messages. http://youtrack.jetbrains.com/issue/IDEA-91636


Subscribe for updates