Runtime Swedish/English Language Switching (Part 2)

In part 1 I showed how to get started creating a runtime language switcher in your NetBeans Platform application so that the end user can (without a restart) switch from one human language to another, such as from English to Swedish and back.

A starting point is to download the community translated version of NetBeans IDE. I.e., go to the NetBeans download page, choose the human language you're interested in from the "IDE Language" drop-down and then download the IDE. Two binaries exist. The official binary, which includes en + officially supported languages (ja,zh_CN,pt_BR and ru) and the community binary, which includes the community-translated languages, which includes, among several others, Swedish (sv).

Once you've got the IDE of your choice, build on top of that, using "--locale sv" in the "run.args.extra" key in "", if you'd like to deploy your application in Swedish mode. Also use the tricks shown in part 1, together with those referred to there from Toni's blog, to refresh the UI after the runtime language switch has been made.

Now, once you've translated everything (and make sure to take a look at i8nchecker, you might need it somehow and it's good to know it's there), you'll need to include only the NetBeans Platform's Swedish JARs (and not also all the other translated JARs from the community binary) in your distribution. Here's how, thanks to an e-mail I received today from Johan Walter from Mercur in Sweden:

<target name="copy-cluster" description="Copies cluster specified by basedir to dir ${dest.dir}">
    <pathconvert property="">
        <path path="${basedir}"/>
        <mapper type="regexp" from="[/\\\\]([\^/\\\\]+)([/\\\\]build[/\\\\]cluster)?[/\\\\]?$" to="\\1"/>
    <copy todir="${dest.dir}/${}">
        <fileset dir="${basedir}">
                    <filename name="\*\*/lib/nbexec\*"/>
                <selector refid="zip.platform.included.files"/>
    <touch file="${dest.dir}/${}/.lastModified"/>
    <condition property="copy.nbexec" value="true">
        <matches pattern="\^platform[0-9]\*$" string="${}"/>
    <antcall target="copy-nbexec"/>
    <copy todir="${dest.dir}/${}">
        <fileset dir="${basedir}">
            <filename name="\*\*/locale/\*_sv.jar"/>

The section in bold above needs to be added to the "copy-cluster" target in the "suite.xml" of your application, which is shown in its entirety above. What you then end up with, once you create the ZIP from the IDE (or command line via Ant target) is several folders named "locale", containing "_sv.jar" files.

If you want to predefine for the end user the locale they should use, refer to this blog entry, which tells you about "app.conf" where you can specify your own ".conf" file in which you'll have "--locale sv" in "netbeans_default_options".


Hi Geertjan!

My colleague and me are writing a NetBeans RCP application based on NetBeans Platform 7.0. We need to deploy this application via Java WebStart which all works fine with NetBeans 7.0. But the default locale of the application shall be German and not English.
Although we already managed to start the NetBeans 7.0 IDE in German language (manually deployed the to the NetBeans installation folder) and added the parameter "run.args.extra=--locale de:DE" in the file we do not manage to get the app starting via Java WebStart in German language.
Do you have any idea? Is it possible to do that?

kind regards,

Posted by Benjamin Ihle on July 14, 2011 at 04:51 AM PDT #

i apply your work. but the menu bar is not change the language.
i think that i should add key to the

Posted by guest on January 28, 2014 at 03:49 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« April 2014