Internationalizing a Matisse Form
By johnc on Mar 16, 2006
One of the coolest things about Matisse is that when you translate your program into another language, it doesn't get all screwed up because all of the components are grouped relative to each other with relative spacing provided by the look and feel. But how do you take a program with hard-coded display text and internationalize it?
Marek Grummich answers this question in this latest installment in our continuation of Matisse articles. There are basically four things you can do (each of which Marek goes through, including Flash demos, of course):
- Insert internationalized strings right in the GUI Builder as you create the form. To do this, click the ellipsis for the text property for a component, then select Resource Bundle in the Select Mode combo box and enter the properties file, key, and value (display text) for the string. View Demo
- Insert an internationalized string in code. If you're working in
the code view, and not in the GUI editor, just press Ctrl-Shift-J, specify
the properties file, key, and value, and the IDE fills in the correct lookup
code for you.
- Internationalize an entire project at once. Right-click the Source
Packages node and choose Tools > Internationalization > Internationalization
Wizard. The wizard will go through and list all of the strings in the source
files and suggest to replace them with key/value pairs in a properties file.
- Convert strings in a single file one at a time. Right-click the
file in the Source Editor and choose Tools > Internationalization >
Internationalize. This is best if you've got a small project or you know there
are lots of strings that you don't want to internationalize. You cycle through
all of strings one at a time and provide the key/value pairs for them.
Another tip: If you know you've got a lot of strings that you don't want to internationalize, put a //NOI18N comment in each row that contains one of these Strings. Then go Tools > Options > Advanced Options > Editing > Internationalization and add //NOI18N to the regular expression in the I18n Search Format property. The IDE will automatically skip all these strings when you run internationalization commands.
Then to run your project in a different locale, put a string like the following in your VM options:
And you get something like this:
Hope everyone's enjoying the Matisse tutorials. Stay tuned for the next and most important one: Hooking up the Matisse form to a database. It's the hardest one so it takes the longest to write. Oh yeah, and regarding Matisse4Eclipse, using SWT to program a Swing app is like using a coal-powered generator to charge up your electric car. IMHO, it's kind of missing the point...