• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using properties file in source file

 
Vladislav Simovic
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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?
 
roby george
Ranch Hand
Posts: 31
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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...
 
Dieter Quickfend
Bartender
Posts: 543
4
Java Netbeans IDE Redhat
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Stefan Evans
Bartender
Posts: 1782
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic