views:

86

answers:

1

I'm writing a new Java 6 Swing application and want to have a "Show tips at start-up" feature. I've done this before, but never with localization in mind.

In the past, my tips dialog used an XML file to hold the tips, but I'm afraid this will make things difficult when it comes time to translate these tips into different languages. I've thought about using a .properties file like with other strings in the application, but wonder if this is a maintainable approach. I would like to give the user the ability to add their own tips which will also display in the same dialog.

Is the properties approach the way to go? If I allow users to add their own tips, I'll need some way to make sure the keys (for text retrieval) are unique.

+1  A: 

I would say the properties files is the best approach. But i would make the user a screen to add new tips, instead of letting them modify the properties files directly.

To read all the keys, you can use java.util.ResourceBundle you will find a method called getKeys

You should build a screen like this:

alt text

medopal
@medopal - Thanks. I was planning on a screen. However, I want something a bit simpler, which will let the user just add a tip in their native language. I suppose I could detect the locale first and then just update the appropriate properties file. Does that sound like a good approach, or am I making more work for myself that way?
ssakl
I never tried to autodetect the user Locale myself, so in your place, i will make a dropdown list like the one in the image, and default it to my customer language. To make the screen simpler, you can make it just one column with an 'Add new' button
medopal
@medopal - It looks like I can use Locale.getDefault() to get the default locale for the currently running JVM. This should be good enough for my purposes. My target audience for the app is non-technical, so the less they have to do on their own the better.
ssakl
I believe getDefault() will do the job, i was preferring the drop down list since the user might want to add the same message in multiple languages. But better to make it simple as you mentioned :)
medopal
@medopal - The .properties file was definitely the way to go. I haven't implemented the user screen yet, but displaying the tips was much less work than my previous XML implementation. Thanks for your help!
ssakl