Locale question

H

hilz

Hi all

I have couple of files:
file_en.txt
file_fr.txt
file_es.txt
file_de.txt

they contain the same simple text in their corresponding languages.
and i want to be able to load these files according to the locale.

I know that:
ResourceBundle.getBundle("file", Locale Locale)
should be used if those files were ".properties" files and contained
key=value pairs. But my files contain just simple text. Is there an
equivalent way of getting the text from those files in a single call similar
to ResourceBundle.getBundle(String baseName, Locale locale)

thanks
hilz
 
H

hilz

So you have no keys in the text files to identify each message?

No, I don't have a key.
Each of those files contain a long paragraph, and there is no key since it
is just a paragraph of text.

anyway, i just figured out that i can get the two letters of the language by
calling Locale.getLanguage()
so i append it to the file name before reading it, and it worked.
thank you for trying though.

thanks
hilz
 
S

Stephen Riehm

hilz said:
Hi all

I have couple of files:
file_en.txt
file_fr.txt
file_es.txt
file_de.txt

they contain the same simple text in their corresponding languages.
and i want to be able to load these files according to the locale.

I know that:
ResourceBundle.getBundle("file", Locale Locale)
should be used if those files were ".properties" files and contained
key=value pairs. But my files contain just simple text. Is there an
equivalent way of getting the text from those files in a single call similar
to ResourceBundle.getBundle(String baseName, Locale locale)

..properties files are also just text files, with minimal formatting.
If you know what's right, why don't you make your locale files 'right'
and then use the normsl, right way. The person who has to maintain your
code will thank you :)

I normally have a locale/ directory in my jar file, and then put the
translations in files like messages_en.properties,
messages_de.properties, etc. Just like they tell you in the books ;-) It
works great.

PS: a simple one-line perl or sed command can be used to convert many
simple text formats into other formats... ie: if your texts are tab
seperated, you could use the following to turn them into key = values pairs.

perl -pe 's/\t/=/' file_en.txt > messages_en.properties

cheers,

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top