TaT NetbeansPlatformLocalizationAsPlugins

Netbeans Platform Localization as Plugins

Contributed By; Tonny Kohar
Adapted from http://blogs.kiyut.com/tonny/2008/08/06/netbeans-platform-localization-as-plugins/



This is another series of Netbeans Platform i18n and localization trick. 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.


File:nb-plugins-list_TaT_NetbeansPlatformLocalizationAsPlugins.png

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

Architecture

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 the-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) eg: kiyut.alkitab.actions.Bundle_in_ID.properties

For the platform/ide cluster you need to find out where the text is localized and the jar name eg: org.netbeans.core.actions.Bundle 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
- META-INF
- 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="harness.build-init">
        <property name="update-source.basedir" value="../alkitab-suite/alkitab-core"/>
        <property name="locale.dir" value="${basedir}/build/cluster/modules/locale/"/>
    </target>
 
    <!-- 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"/>
                -->
            </fileset>
        </copy>
    </target>
 
    <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/**" />
            </fileset>
        </jar>
 
        <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/**" />
            </fileset>
        </jar>
 
        <jar jarfile="${locale.dir}/org-netbeans-core-windows.jar" compress="${build.package.compress}">
            <fileset dir="build/classes">
                <include name="**/org/netbeans/core/windows/**/*_*.properties"/>
            </fileset>
        </jar>
 
        <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"/>
            </fileset>
        </jar>
 
        <!-- 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/**"/>
            </zipfileset>
        </jar>
        <move file="${cluster}/${module.jar-temp}" tofile="${cluster}/${module.jar}"/>
 
    </target>
 
    <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}">
            <patternset>
                <exclude name="META-INF/**"/>
            </patternset>
        </unjar>
 
        <!-- step 2: put the locale into the appropriate folder -->
        <copy todir="build/${nbm-expand}/netbeans/modules/locale/" >
            <fileset dir="${cluster}/modules/locale/" />
        </copy>
 
        <!-- step 3: re jar the result -->
        <jar jarfile="build/${nbm}" compress="true">
            <fileset dir="build/${nbm-expand}" />
        </jar>
 
        <!-- step 4 [optional: sign the nbm result -->
        <antcall target="sign-nbm" />
    </target>
 
    <target name="sign-nbm" if="keystore">
        <signjar jar="build/${nbm}" keystore="${keystore}" storepass="${storepass}" alias="${nbm_alias}" />
    </target>
 
</project>

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.

Not logged in. Log in, Register

By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo