aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Is localisation using resource bundles allowed at all? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Is localisation using resource bundles allowed at all?" Watch "Is localisation using resource bundles allowed at all?" New topic
Author

Is localisation using resource bundles allowed at all?

oli mueller
Ranch Hand

Joined: Feb 13, 2011
Posts: 42
Hi guys,

just one short question to be 100% safe. I want to use localisation of my GUI-texts via resource bundles....I know, it is not a must requirement and I know many people on here have just used static final Strings, but I personally prefer resource bundles....

...But wht i am afraid of is: Are resource bundles allowed at all??? I mean, this requires an additional properties file and i am just not sure if this violates any of the restrictions from sun....I am reading the task description over and over again, but i am still not sure....;))...

Did anybody of you passed with proper localisation???...

Thanks..
Roberto Perillo
Bartender

Joined: Dec 28, 2007
Posts: 2268
    
    3

Howdy, Oli!

...But wht i am afraid of is: Are resource bundles allowed at all???


Well champ, why wouldn't it be? ;)

No need to worry. I'm not sure, but I think Roel used a resource bundle too.


Cheers, Bob "John Lennon" Perillo
SCJP, SCWCD, SCJD, SCBCD - Daileon: A Tool for Enabling Domain Annotations
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

Roberto Perillo wrote:No need to worry. I'm not sure, but I think Roel used a resource bundle too.

I didn't use a ResourceBundle, just a class with nothing more but all String constants containing messages, labels, captions,... This class could be easily converted using a resource bundle in a next version of the application. I didn't use resource bundles for the simple reason: it's not required

But no need to be afraid: using resource bundles is allowed, there is no reason why it would not. You just have to make sure that when you make the runme.jar you don't forget to include the necessary properties files (otherwise your application may be hard to use and you might lose some points). Also specifying the properties file at startup is not allowed (because only "server", "alone" and <nothing> are allowed according to instructions)


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

this is what the specifications says: (mine at least)
All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.

(i guess you can create a properties file programmatically if one doesn't exist)


SCJP 5, SCWCD 5, SCBCD 5
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

Jonathan Elkharrat wrote:All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory.

Jonathan, that's about the properties file which contains the configuration settings of your application (database file path, port number, server ip). This file has nothing to do with the properties file(s) you need for localisation through resource bundles.
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

you're right, but you can also store localisation in properties file as far as i know...
then again, a resource bundle is also a good option. but as you said before, no other argument
is permitted in the program. (but it can give an option in the GUI and store it in the properties)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

Jonathan Elkharrat wrote:(but it can give an option in the GUI and store it in the properties)

Your comment confuses me a bit. It seems you have another understanding of localisation than me. Localisation in this context (together with resource bundles) is about translatable strings (menu captions, button labels, info messages,...) depending on the user's locale. I don't see how an option in the GUI can help you unless you mean something like a "choose your language" option (and this preference will be stored in a properties file, together with other configuration settings).
But to make i18n (localisation) work you will have different properties files (1 for each language you want to support) and in your code you use a resource bundle to retrieve the string based on the user's locale. As shown in this tutorial.
Jonathan Elkharrat
Ranch Hand

Joined: Dec 31, 2008
Posts: 170

you can also do a:
french_option_ok=oui
english_option_ok=yes
etc...
and fetch properties.get(local+"_option_ok");

you can also hardcode them in several class, each for a different locale and use
the class according to user preference. (class can be used a resource bundle too)

anyway, all this is theoretically, i myself find this a bit of overkill for such a small
project. (though there shouldn't be much i18n/l10n to do in this assignment)
Oladeji Oluwasayo
Ranch Hand

Joined: Sep 10, 2010
Posts: 101

Do we really need this localization stuff. Is it worth the bugs that it may attract? What if some really unexpected things happen on the accessor's machine (like an IOException in an attempt to read the properties file into your code). Consider all the things this can bring. Don't people pass by just hard-coding the strings directly into the GUI? Or am I missing something?


OCPJP 6, OCMJD 6
oli mueller
Ranch Hand

Joined: Feb 13, 2011
Posts: 42
wow..interesting how these discussions evolve..;)...

....well, of course the localisation is NOT required and people pass with just string constants....I actually also believe that adding language properties etc. like Jonathan described takes it too far.....I will not provide resource bundles for different languages or Gui options to switch the locales or whatever - all I thought is that I just use a resource bundle, because (1) resource bundles is not much more difficult to implement than String constants and (2) resource bundles are a bit more "professional" and flexible (I would say) than String constants...

Having slept over it, i got also afraid of unexpectable things missing rights to read the property files, SecurityException of the class loader or whatever....because at least I am very very paranoid with this certification process, probably with the String constants you are at least on the safe side....;)

Thanks anyway
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

Jonathan Elkharrat wrote:you can also do a:
french_option_ok=oui
english_option_ok=yes
etc...
and fetch properties.get(local+"_option_ok");

you can also hardcode them in several class, each for a different locale and use
the class according to user preference. (class can be used a resource bundle too)

That's true, but then you are doing all the work in your code The beauty of using a ResourceBundle is just that it does all the work for you: you provide a properties file for each locale you want to support and that's it.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5597
    
  15

Oladeji Oluwasayo wrote:Don't people pass by just hard-coding the strings directly into the GUI? Or am I missing something?

Of course you'll pass with just hard-coding the strings. Localisation is not a must requirement. And the more more complexity or dependencies you add to your project, the more chance you have something might go wrong.
 
 
subject: Is localisation using resource bundles allowed at all?