By Geertjan-Oracle on Aug 16, 2012
I created this basic Java desktop infrastructure with Arabic display texts in about 15 minutes, though the RTL parts took a bit longer to get exactly right in the end, but were solved thanks to two sources discussed further down in this blog entry:
Notice that the application has a window system with undockable components, as well as a menu bar and a toolbar; all of which are pluggable because this is an example of a NetBeans Platform application, which is natively modular. Now "all" you need to do is code your business logic and you're done, since the infrastructure is ready and waiting for your domain-specific content. Consider the above as a generic template for Arabic Java desktop applications, i.e., the above application can run on Windows, Linux, Mac OSX, etc, i.e., on any operating system that supports Java SE.
Want to create the application you see above? Below are 5 tips to help you get started.
- Download the Arabic version of NetBeans IDE. Go to netbeans.org and choose Arabic in the IDE Language drop-down:
Click Next, choose your distribution, and then click Download. You will see Arabic in the page that appears as the download starts:
- Don't worry about incomplete translations. Once you've downloaded and installed NetBeans IDE, take a look at the "locale" folders, which are within, for example, the "platform/modules" folder (as well as the "ide/modules" folder, for example). There you'll see that not only do you have Arabic JARs (denoted by the "ar_SA" extension), but also those for several other languages:
Two concerns could come to the front of your mind at this point, neither of which are genuinely problems. First of all, you'll be concerned about, at the end of your application development, needing to bundle only the Arabic JARs, and not all the other ones, with your application. This blog entry, with thanks to Johan Walter, a Swedish NetBeans Platform developer, should help you out on that score. Secondly, once you've started up NetBeans IDE in Arabic (using the next step below), you might be concerned when you notice that not everything has been translated into Arabic, for example:
But, you shouldn't be concerned about this either. Remember that the point of this exercise is to create your own Arabic application on the NetBeans Platform. As you'll see later in this blog entry, you have full control over all the texts in the NetBeans Platform, so you can change any text, throughout the NetBeans Platform, to Arabic. Therefore, the fact that NetBeans IDE itself, or even the NetBeans Platform itself, is not fully translated to Arabic really isn't a blocker to creating applications in Arabic on top of the NetBeans Platform.
- Set the locale of the IDE and of the application. Once you've downloaded and installed NetBeans IDE, go to the netbeans.conf file and use the "-J-Duser.language" and the "-J-Duser.region" settings, as shown below, to set the IDE to use the Arabic JARs:
However, as noted earlier, the fact that you're creating an application in Arabic doesn't mean that the IDE itself must be set up in Arabic. You could create an Arabic application in the English NetBeans IDE, which might be the simplest way to do it. Once you've started up the IDE and you've created your new NetBeans Platform application, which is as always done via the New Project wizard, set the following in the platform.properties file of the application, so that the Arabic JARs are used for the application that you're creating:
- Use the tools in the IDE. OK. So, now we're where the rubber meets the road. Everything has been set up and now we're creating our modules and coding the application. You're going to run into several things, all of which the IDE handles very gracefully for you. Here are solutions to all the potential stumbling blocks of which I am aware:
- Menus, toolbars, and tabs need to be right-aligned. As luck would have it, quite some research has been done in this area already. Start by reading and using Tonny Kohar's insights on RTL layout, which are great, and very important in this context. Then also take a look at this module in Git, together with the discussion in http://netbeans.org/bugzilla/show_bug.cgi?id=96333. All my knowledge of RTL, as shown in the screenshot at the start of this blog entry, comes from these two sources.
Predefined NetBeans Platform display texts need to be translated to Arabic. Not a problem. Let's imagine you want to translate the "Window" menu to "شباك", for example. Right-click the application and choose Branding. In the Branding dialog, go to Resource Bundles, type the text you want to change, and then you'll need to read through the filtered strings intelligently to identify the one you need to change:
Then right-click on the string you need to translate and choose Add to Branding. Then type your Arabic characters, which will then be saved in the application's 'branding' folder, in a properties file, where the entry will override the one provided by the NetBeans Platform itself.
- New display texts need to be translated to Arabic. For example, when you create new window and new menu items, their display texts need to be Arabic. Not a problem. The NetBeans Java Editor can handle Arabic texts easily, for example, this is how the display text in the tab of a window, the tooltip in a window, and the menu item for opening the window are set, in a Java annotation that is converted to Bundle.properies entries when the file is saved:
- The display text in the title bar needs to be translated to Arabic. Not a problem. Just right-click and choose Rename to rename the application and then use Arabic characters in the rename dialog. (Or go to the Branding dialog and use the General panel, which provides an Application Title field, where you can type Arabic characters.) That's how I ended up with this, which is what's displayed in the title bar:
- Download the completed sample. Want the sources of the above, i.e., the end result of all the work above? Go here, check out the application via Subversion, and open the project in NetBeans IDE 7.2:
However, note that the IDE from which you run this application MUST include the Arabic JARs, i.e., you need to not only have NetBeans IDE 7.2, but the Arabic version of NetBeans IDE 7.2, as described in the first tip above. Note that the RTL support (i.e., the right-aligned menubar, toolbar, and tabs) is not part of the above download. Instead, refer to the sources mentioned in the previous tip if you're interested in those pieces.
Hope this is helpful to Java desktop developers wanting to create their software systems for Arabic end users. Using all the tools, components, and coding patterns provided by the NetBeans Platform is surely a lot simpler than reinventing the wheel all by yourself.
Funny Moment of the Day. Frank Caliendo is pretty clever with his impersonations, check this out on YouTube.