Netbeans Platform Localization as Plugins

August 6th, 2008 | by Tonny Kohar |

This is another series of Netbeans Platform i18n and localization trick. You can read the other series in here and here. This methods is used to localize Netbeans Platform based Application which can be updated using Update Center. It also have an entry on the Plugins List. However, please note this may be somekind of HACK. The proper localization should be following Netbeans Localization Project.

Netbeans Plugins Dialog

Note: this is tested on Netbeans 6.1, and use Alkitab Bible Study as example.


As you probably aware, netbeans divide the platform into clusters, each cluster have their own directory and your Application (Platform Based) is given a cluster of its own eg:

- bin
- etc
- ide9 (IDE cluster)
- platform (Platform cluster)
- alkitab (your application cluster)
  * modules
    - locale (note this is important)
- ...

As far as I understand, the netbeans store the locale into the folder [cluster]/modules/locale. So somehow you need to put your jar (contain only locale) into that folder. Another important point that the jar name must be the same name as the module you want to localize eg:

- for com-your-modules.jar, the locale jar name should be com-your-modules[_country_lang].jar
- for org-netbeans-core.jar, the locale jar name should be org-netbeans-core[_country_lang].jar
- etc

The country code and lang is optional for the jar name. It only use if you really want to separate the jar for each locale. To keep thing simple we do not append the country code/language and all the supported locale will be under single jar.

Step 1: Create new module

The first step is to create new module project that will contain the localization (in this case for all languages). Inside the new module, create package (folder structure) which matching the things you want to localize and create the appropriate properties file localized (append country code and language)

For the platform/ide cluster you need to find out where the text is localized and the jar name eg:
with key Exit=E&xit
jar name = org-netbeans-core.jar
And create the same structure in the above new module project.

Step 2: Modify the build.xml

The next step is to modify the build.xml to produce the jar in appropriate location (note: the locale folder). The output will something like this

your-module-name-localization.nbm (this is the new project nbm as step 1)
- info
- netbeans
  - config
    - Modules
      - your-module-name-localization.xml
- modules
  - locale
    - your-jar-contain-localization-properties.jar (optionally can use country code)
    - org-netbeans-core.jar (netbeans part that you localize)
    - org-netbeans-core-windows.jar
    - etc
  - your-module-name-localization.jar

Here is the sample build.xml, note it overrides the target: jar and nbm.

<project name="kiyut.alkitab.modules.localization" default="netbeans" basedir=".">
    <description>Builds, tests, and runs the project kiyut.alkitab.modules.localization.</description>
    <import file="nbproject/build-impl.xml"/>
    <target name="build-init" depends="">
        <property name="update-source.basedir" value="../alkitab-suite/alkitab-core"/>
        <property name="locale.dir" value="${basedir}/build/cluster/modules/locale/"/>
    <!-- Update the source for localization, it is only for Alkitab -->
    <!-- Netbeans properties file need to be update/copied manually -->
    <target name="update-source" description="Update locale source" depends="init">
        <copy todir="." preservelastmodified="false" verbose="true" overwrite="true">
            <fileset dir="${update-source.basedir}">
                <include name="src/**/*.properties"/>
                <include name="src/**/*.htm*"/>
                <exclude name="src/kiyut/alkitab/*.properties" />
                <!-- <include name="javahelp/**/*.properties"/>
                <include name="javahelp/**/*.htm*"/>
                <include name="javahelp/**/*toc.xml"/>
    <target name="jar" depends="projectized-common.jar">
        <!-- step 1: create jar for each module which only contains locale and place it under locale folder -->
        <mkdir dir="${locale.dir}"/>
        <jar jarfile="${locale.dir}/kiyut-alkitab.jar" compress="${build.package.compress}">
            <fileset dir="build/classes">
                <include name="**/kiyut/alkitab/**/*_*.properties"/>
                <exclude name="**/kiyut/alkitab/modules/**" />
        <jar jarfile="${locale.dir}/org-netbeans-core.jar" compress="${build.package.compress}">
            <fileset dir="build/classes">
                <include name="**/org/netbeans/core/**/*_*.properties"/>
                <exclude name="**/org/netbeans/core/windows/**" />
        <jar jarfile="${locale.dir}/org-netbeans-core-windows.jar" compress="${build.package.compress}">
            <fileset dir="build/classes">
                <include name="**/org/netbeans/core/windows/**/*_*.properties"/>
        <jar jarfile="${locale.dir}/org-netbeans-modules-options-api.jar" compress="${build.package.compress}">
            <fileset dir="build/classes">
                <include name="**/org/netbeans/modules/options/**/*_*.properties"/>
        <!-- step 2: update the module jar by removing the uneeded locale files for this module -->
        <property name="module.jar-temp" value="${module.jar}-temp"/>
        <jar jarfile="${cluster}/${module.jar-temp}" compress="${build.package.compress}" index="${build.package.index}" filesetmanifest="merge">
            <zipfileset src="${cluster}/${module.jar}">
                <include name="**/modules/localization/**"/>
                <include name="META-INF/**"/>
        <move file="${cluster}/${module.jar-temp}" tofile="${cluster}/${module.jar}"/>
    <target name="nbm" depends="projectized-common.nbm">
        <property name="nbm-expand" value="nbm-expand"/>
        <!-- step 1: unjar the created nbm file -->
        <unjar src="build/${nbm}" dest="build/${nbm-expand}">
                <exclude name="META-INF/**"/>
        <!-- step 2: put the locale into the appropriate folder -->
        <copy todir="build/${nbm-expand}/netbeans/modules/locale/" >
            <fileset dir="${cluster}/modules/locale/" />
        <!-- step 3: re jar the result -->
        <jar jarfile="build/${nbm}" compress="true">
            <fileset dir="build/${nbm-expand}" />
        <!-- step 4 [optional: sign the nbm result -->
        <antcall target="sign-nbm" />
    <target name="sign-nbm" if="keystore">
        <signjar jar="build/${nbm}" keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}" />

Step 3: Finish and Testing

It is finished, you only need to test it. Note in your application Menu-Tools-Plugins, it should list the new localization plugins which can be updated by Update Center

You can download the whole source code at Alkitab Bible Study Developer section.

Additional comment by Josh is available here (in German)

Tags: , ,

  1. 6 Responses to “Netbeans Platform Localization as Plugins”

  2. By andy on Nov 15, 2008 | Reply

    nice tutorial

  3. By ola on Feb 5, 2014 | Reply

    Thanks for such a wonderful post.
    i am new to netbeans platform, and i want to make my application is Arabic & English language support. The UI of netbeans should also be RTL and LTR.

  1. 4 Trackback(s)

  2. Sep 14, 2008: Websites tagged "i18n" on Postsaver
  3. Dec 13, 2008: Toni Epple » Quick Tip 6: Platform localization
  4. Aug 9, 2010: Java Getriebe » Blog Archive » NetBeans Translator
  5. Jan 20, 2012: Quick Tip 6: Platform localization | Toni's Blog

You must be logged in to post a comment.