?
Solved

i18n What bundle name (fmt:message)

Posted on 2005-03-22
18
Medium Priority
?
2,021 Views
Last Modified: 2008-01-09
I have
<fmt:message bundle="????" key="ExampleLevel1Title" />

what to put in the ???? when I have

vars_it_CH.properties
vars_de_CH.properties
vars_fr_CH.properties

and do you have a clever way to find the LG1 property from any of those bundles

LG1=de
LG2=it
LG3=fr

and use it to load the messages from

vars_de_CH.properties ???

Thanks
0
Comment
Question by:Michel Plungjan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 8
18 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13600249
Set locale, bundle name, then get the message value of the key

e.g.

<fmt:setLocale value='de'/>
<fmt:setBundle basename='vars'/>
<fmt:message var='i18ncountry' key='ExampleLevel1Title'/>
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13600255
Oops,
>><fmt:message var='i18ncountry' key='ExampleLevel1Title'/>
should be
<fmt:message  key='ExampleLevel1Title'/>

otherwise it will store the key value into a variable (sorry, a bad bit of cut and past there!)
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13600284
This also allows you to access the different bundles programmatically and get the same key from multiple bundles
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13600294
Sorry I was not clear then

The interface is based on languageA countryA and is a search form

(the jsp/tiles version of http://ep.espacenet.com/search97cgi/s97_cgi.exe?Action=FormGen&Template=ep/en/advanced.hts)

If you change the drop down, you will see the examples next to each entry field changes.

I want to take the value of the drop down and use that to change the bundle for ONLY those examples, the rest of the page have
for example <fmt:message key="inventor">  NB: THIS WORKS RIGHT NOW in whatever locale I define

So the row with inventor would be for the japanese drop down in any non-japanese interface language:

<fmt:message key="inventor"> <input name="inventor" type="text"> <fmt:message bundle="whatever bundle we have for en_JP"  key="exampleForInventor">

and this for the japanese interface

<fmt:message key="inventor"> <input name="inventor" type="text"> <fmt:message bundle="whatever bundle we have for jp_JP"  key="exampleForInventor">

or if you want to search in the swiss database:

Interface is italian:

<fmt:message key="inventor"> <input name="inventor" type="text"> <fmt:message bundle="whatever bundle we have for it_CH"  key="exampleForInventor">

Interface is german:

<fmt:message key="inventor"> <input name="inventor" type="text"> <fmt:message bundle="whatever bundle we have for de_CH"  key="exampleForInventor">

interface is greek:

<fmt:message key="inventor"> <input name="inventor" type="text"> <fmt:message bundle="whatever bundle we have for default swiss"  key="exampleForInventor">


0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13600301
I want to avoid



<fmt:message key="inventor"> <input name="inventor" type="text"><fmt:setBundle bundle="whatever bundle we have for it_CH"  /><fmt:message key="exampleForInventor" />
<fmt:setBundle bundle="whatever default"  >
<fmt:message key="applicant"> <input name="applicant" type="text"><fmt:setBundle bundle="whatever bundle we have for it_CH"  ><fmt:message key="exampleForApplicant">
<fmt:setBundle bundle="whatever default"  >
.
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13600402
Ok, I will try something clever but much more complicated
I will make each of the 3 cells a tile and have different bundles for tile 1 and 3

I think that will work but be a bit more complex than I had envisioned
0
 
LVL 29

Accepted Solution

by:
bloodredsun earned 800 total points
ID: 13600410
You can work with different locales in the JSP like this (which avoids the verbosity you're trying to avoid, you can also set the values to variables whch would make reuse easier):

<fmt:setLocale value='it_CH'/>
<fmt:setBundle basename='vars'/>
inventor: <fmt:message  key='inventor'/>      <br>
toy: <fmt:message  key='toy'/><br>

<fmt:setLocale value='jp_JP'/>
<fmt:setBundle basename='vars'/>
inventor: <fmt:message key='inventor'/>      <br>
frSecotr<fmt:message  key='toy'/><br>

You will have to do this for each of your javascript object arrays if you are doing it in a similar manner to the link you gave me.
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13600491
Ohhhh wait a sec

<fmt:setLocale value='it_CH'/>
<fmt:setBundle basename='vars'/>
 <c:set var="inventorExample"><fmt:message  key='inventorExample'/></c:set>
 <c:set var="applicantExample"><fmt:message  key='applicantExample'/></c:set>
.
.
.
<fmt:setLocale value='${defaultLocale}'/>
<fmt:message key="inventor">: ---------------------------- ${inventorExample}
<fmt:message key="applicantr">: ---------------------------- ${applicantExample}


Should work no???
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13600509
Now I just need to figure out how to get the default language out of the bundle...
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13600879
That should work, no probs...

>> Now I just need to figure out how to get the default language out of the bundle...
Which default language, yours or theirs?
If you want theirs, you just call bundle without making any setLocale calls, It will default to their default language.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13600905
e.g.

<fmt:setBundle basename='vars'/><!-- gets the default bundle -->
<fmt:message key="inventor">: ---------------------------- ${inventorExample}
<fmt:message key="applicantr">: ---------------------------- ${applicantExample}


<fmt:setLocale value='it_CH'/>
<fmt:setBundle basename='vars'/><!-- gets the defined bundle  for the specified locale-->
<c:set var="inventorExample"><fmt:message  key='inventorExample'/></c:set>
<c:set var="applicantExample"><fmt:message  key='applicantExample'/></c:set>

0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13601078
The user can choose interface language. That is handled perfectly now
<fmt:message key="inventor"> will show inventor in the chosen interface language.

Now the user changes the database he wants to search in
Let's say the interface is fr_EP, e.g. french and the user changes to the swiss database.

Now it happens that the swiss have french data and we have a swiss french resource bundle so I want to show the french examples from the swiss resource. No problem:

<fmt:setLocale value='fr_CH'/>
<c:set var="inventorExample"><fmt:message  key='inventorExample'/></c:set>
<c:set var="applicantExample"><fmt:message  key='applicantExample'/></c:set>

and so on.

Now the user switches to the english interface.
The swiss do not have english data and no english resource bundle. So I want to show the DEFAULT swiss resource bundle which I can find out is the german one IF I can read just ONE of the swiss resource bundles because the variable called LG1 contains the language.

My problem is now how to get to an LG1 from switzerland

<fmt:setLocale value='??_CH'/><<<<<<<<<<<<------------------------ problem
<c:set var="defaultLanguage"><fmt:message  key='LG1'/></c:set>

<fmt:setLocale value='${defaultLanguage}_CH'/>
<c:set var="applicantExample"><fmt:message  key='applicantExample'/></c:set>

Michel
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13601589
You can parse the Request Headers for the one called "accept-language" which should  output something like

accept-language: en-us,en;q=0.5

I think in the case of the swiss, there is no "default" swiss option, it will depend on what the user has selected in the browser whether it will be fr_CH or de_CH.
0
 
LVL 29

Expert Comment

by:bloodredsun
ID: 13601785
PS, it's nice to see the PE actually on the boards ;-)
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13605140
Yeah, sorry...
We are not looking at the accept language but set our own locale based on the links the user clicks.

Thanks
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13630055
Solved it by getting the default locales into properties
0
 
LVL 75

Author Comment

by:Michel Plungjan
ID: 13631135
For support
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
Hey fellow admins! This time, I have a little fairy tale for you. As many tales do, it starts boring and then gets pretty gory. I hope you like it. TL;DR: It is about an important security matter, you should read it if you run or administer Windows …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question