• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Using properties file in source file

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made a server application and now i want it to support multiple languages. I have looked over the net and found that solution is properties file.

Now i have the next problem, while i can change jsf pages via messages, i want also to change the language of my hardcoded strings in source file also using this same properties file. Can this be accomplished?
 
Ranch Hand
Posts: 31
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can use properties file for multi language, but in that case you have to pick all text from properties file, dont wtite any text direct in source file.
 
Vladislav Simovic
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let me be more clear - I have JSF page and a bean behind it. Some of the content of the page is adjusted dynamically by methods of the bean, eg i wite some text to the page. I also want that text to be language dependent.

How do i pick that text from properties file?
 
roby george
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So i think you need to use some langugae convertor, which convert your text onthe fly and display that on your pgae, Propertis file only use when you have fixed text.

clear me if i m wrong...
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

where certainI18nString is a property in your backing bean containing your internationalized string.
 
Vladislav Simovic
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dieter Quickfend wrote:
where certainI18nString is a property in your backing bean containing your internationalized string.



I want all my strings to be in .propeties file - the ones i hardcoded in .java files, and the ones i use on jsf pages. I dont want to have something in .properties file(for static jsf values) and something in other txt file (for values that bean returns that are shown on the page).

its like this:



First is static value user that is same for all users. Second is country of origin of user which can be different for every user. If we have user named Bob, from England, following would be written for him:

User: England

If we switch language to Italian it sholud write:

Utente: Inghilterra

And both of these words should be in .properties file.
 
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just did a quick search on JSF i18n and it linked me to this post on the ranch

Full details on i18n with JSF can be found in The JSF Tutorial

But basically
- put ALL your translatable text into a message properties file
- import your properties file into the JSF page with the <f:loadBundle> tag
- anywhere you want to display the text from the properties bundle, use the <h:outputText> tag



That would print out a translated "user" string, and then the value of the beans "country" straight from the bean.

If you also wanted to translate the country (as you did in your example), you would have to make the country stored in the bean a country code to look it up in the properties file.


cheers,
Stefan
 
Vladislav Simovic
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also did some research of my own in the meantime and i found quite good tutorial:

http://webcache.googleusercontent.com/search?q=cache:BOkPVeCsP5gJ:www.techcubetalk.com/2009/01/how-to-load-a-properties-file-in-java/+java+how+to+access+properties+file+from+from+runtime&cd=2&hl=en&ct=clnk&source=www.google.com
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic