Saturday Jul 12, 2014

How to Bundle Localized NetBeans Modules with Ant Based NetBeans Platform Applications (Part 2)

After learning the basics of bundling localized JARs in Ant based NetBeans Platform applications, yesterday, let's now provide support for a language that is not officially supported by NetBeans IDE, i.e., a language other than English, Brazilian Portuguese, Japanese, Russian, and Simplified Chinese. Timon Veenstra's team working on the AgroSense project have done us all a big service by creating the NetBeans Maven Libraries project on (How to integrate that into a Maven NetBeans Platform application is described here.)

We're going to go there and get the localized JARs we need. They're from NetBeans Platform 7.2, which isn't actually much of a problem because on the level of the NetBeans Platform, which is what most NetBeans Platform developers use (i.e., most developers build on the NetBeans Platform and not on the NetBeans IDE on top of it) not much has changed in terms of UI and strings in general, since most changes over the past few releases have been focused on the level of new and enhanced APIs, not new and enhanced GUI components and other string-bearing-stuff. We'll download the ones we want and put them into the same structure as in yesterday's blog entry.

The requirement we imagine we have is that we want to provide a Spanish translation of our NetBeans Platform application. In the first stage, we're going to get the Spanish JARs we need from Timon Veenstra's project and, after that, for any missing translations, you're going to learn how to supplement the project with your additional localizations.

  1. Go to

  2. For the language of your choice, download the JARs you need. I.e., go to 'core', 'lib' and 'modules', find all 'es' JARs, download them (by right-clicking on the JAR and saving it or by checking out the entire project). As described yesterday, create a new module for each language you want to support, switch to the Files window, and create a 'release' folder, on the same level as 'nbproject' and 'src' and then populate that folder with the relevant JARs that you downloaded.

    Brief description of the strings found in each of the above JARs:

    JAR Description
    core_es.jar Strings such as error messages and module loading/installation messages, e.g., MSG_load_layers=Cargando servicios de módulo...
    boot_es.jar Strings such as the question to show the user to find out whether to start a second instance of the application or not.
    org-netbeans-api-search_es.jar Strings for Search Results window, e.g., title of Output tab, as well as "Find in Projects", "Replace in Projects", etc.
    org-netbeans-core-execution_es.jar String for processes, such as external processes, e.g., CTL_PendingExternalProcess2=Proceso: {0}.
    org-netbeans-core-io-ui_es.jar Strings for Output window, e.g., Menu/Window/Output=&Salida.
    org-netbeans-core-multiview_es.jar Strings for working with multiview components, e.g., CTL_Save=Guardar.
    org-netbeans-core-output2_es.jar Strings for windows related to Output window, e.g., LBL_Find_Title=Buscar and Output window tab, e.g., LBL_Close=Cerrar Separador.
    org-netbeans-core-ui_es.jar Strings for the menubar, e.g., Menu/Edit=&Editar and many actions, e.g., como...
    org-netbeans-core-windows_es.jar Strings for the window system, e.g., CTL_CloneDocumentAction=C&lonar Documento and Actions/Window=Ventana.
    org-netbeans-core_es.jar Strings related to the About Box, e.g., About=&Acerca de and Exit, e.g., Exit=&Salir.


    Strings related to the Plugin Manager and the update mechanism, such as install=Instalar de todos modos and InstallUnitWizard_Title=Installer de Plugins.
    org-netbeans-modules-favorites_es.jar Strings for the Favorites window, such as Favorites=Favoritos and ACT_Add=&Agregar a Favoritos.


    Strings related to the Options window, such as CTL_Options_Dialog_Title=Opciones and CTL_Export=Expor&tar and CTL_Keymap_Options=Asi&gnación de Teclas.
    org-netbeans-modules-print_es.jar Strings for the Print and Page Setup features, such as MNU_Print_Action=Im&primir...
    org-netbeans-modules-progress-ui_es.jar Strings for the progress bar, such as Cancel_Question_Title=Cancelar Tarea en Ejecución.
    org-openide-actions_es.jar Strings for many generic actions, such as cut, copy, paste, and delete.
    org-openide-loaders_es.jar Strings relating to files, such as SaveAsTemplate=Guardar como Plantilla...

    As far as I am (currently) aware, the above are the only JARs you need to think about including (if you are creating a generic NetBeans Platform application, as opposed to one that is based on NetBeans IDE and/or uses various kinds of editors, e.g., the NetBeans XML Editor), there are several other JARs in the 'platform' folder, but these don't have strings in them. (One other one to remember is modules/ext/locale/updater.jar.) Also remember that in each case, the above are JARs that contain nothing more than a few properties files, i.e., they're tiny JARS with almost no content at all, aside from the properties files with the translated strings in them.

    Of course, all the other languages are the same as the above, to the extent that they have been translated. I.e., the keys are the same for all languages, but the values are different, obviously since they're all different languages, and the extent to which they have been translated is also different.

  3. Run the application with --locale es or -J-Duser.language=es. Lots of Spanish texts everywhere now, as you can see in the screenshot below. However, not everything has been translated, for various reasons, e.g., the "Show Only Editor" menu item is new in NetBeans IDE 7.4, and hence didn't exist when the 7.2 localization JARs were created:

  4. Right-click the application and choose Branding. Go to the "Internationalization Resource Bundles" tab. Then choose the locale you're interested in, which in this case, since we're working on Spanish, is "es". After that use the search field to look for your string.

    Be very careful if the string, as in the case of "Show Only Editor" has an underline in it, as in this particular case under the "O", which is caused by an ampersand prior to that letter, resulting in the NetBeans Platform creating an accelerator so that the user can use the keyboard to get to that menu item. Therefore, when you do your search for a string that includes an underline, replace the underline with an ampersand prior to the underlined letter, as shown below:

    Once you've found your string, right-click on it in the dialog above, choose "Add to Branding", and then type the, in this case, Spanish translation of the string.

    What's also really cool about the above dialog is that, as you can see above, you now have a pretty good idea in which module the string is found, i.e., which JAR is going to be overridden: 'org-netbeans-core-windows' in this case, with the 'actions' being a package in that JAR.

  5. Now switch to the Files window. Expand the 'branding' folder in the application. You'll notice that, after doing the previous step, NetBeans IDE has automatically created a folder for you named 'org-netbeans-core-windows.jar'. That's a folder. Continue expanding it and in the 'actions' folder you'll find your translated string.

  6. Run the application again and you'll see your translated texts automatically merged with the localization JARs that you downloaded from Timon Veenstra's project.

It would be pretty cool if anyone who supplements the localization JARs with their own translations for any language would let the NetBeans team know, e.g., at the end of this blog entry, or at netbeans dot webmaster at gmail dot com, that you've done a translation and then those translations can be added together and published as a whole for everyone to benefit from.


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.


« July 2014 »