Locale question

Discussion in 'Java' started by hilz, Dec 17, 2004.

  1. hilz

    hilz Guest

    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
     
    hilz, Dec 17, 2004
    #1
    1. Advertising

  2. hilz

    Guest

    So you have no keys in the text files to identify each message?
     
    , Dec 17, 2004
    #2
    1. Advertising

  3. hilz

    hilz Guest

    <> wrote in message
    news:...
    > 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
     
    hilz, Dec 18, 2004
    #3
  4. hilz wrote:
    > 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
     
    Stephen Riehm, Dec 18, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Maurice Hulsman
    Replies:
    1
    Views:
    1,870
    Guus Bosman
    Jul 25, 2004
  2. Replies:
    4
    Views:
    1,014
  3. Gabriel Genellina
    Replies:
    0
    Views:
    713
    Gabriel Genellina
    Feb 18, 2009
  4. zade
    Replies:
    1
    Views:
    623
    James Kanze
    Mar 5, 2010
  5. Sibylle Koczian
    Replies:
    2
    Views:
    1,129
    Sibylle Koczian
    Nov 20, 2010
Loading...

Share This Page