RE: problems with internationalization

"Anthony Eden" <[email protected]> Sun, 1 Dec 2002 16:34:26 -0500
Newsgroups gmane.comp.java.jpublish.devel
Message-ID <000001c29981$6ce76490$0501000a@mobile1>
I have added your patch.  I would like to make it even easier to have a localized page by having the locale determined automatically using the Language header but I will have to do that a little bit later.  You should now be able to create an action which determines the Locale and either a.) set the Page locale or b.) use the syntax $page.getProperty("name", $locale) where $locale is a reference to the Locale you want to use.

As a side note, I have also upgraded to Velocity 1.3 in the CVS.

Sincerely,
Anthony Eden

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On 
> Behalf Of Florian Gnägi
> Sent: Thursday, November 28, 2002 1:39 PM
> To: [email protected]
> Subject: [JPublish-developer] problems with internationalization
> 
> 
> Hi all
> 
> We try to build a multilingual webapplication. The jPublish 
> documentation describes how to write localized page 
> properties but does not say how to use the localization. How 
> do I set the current language?
> 
> In page.java the property code does not seems to be very 
> multilingual since it uses the default locale from the 
> virtual machine. It is possible to get the properties with a 
> locale e.g. from an action, however when velocity resolves 
> the variable $page.myproperty it does not use the correct 
> getter method. Instead it uses:
> 
> -------
> /** Get the named property.  This method is equivilent to the 
>  <code>getProperty(name)</code> method.  This method is 
> provided  as a convenience to Velocity code.
>  
>  @param name The property name
>  @return The value
> */
> public String getProperty(String name){
>  return getProperty(name, Locale.getDefault());
> }
> -------
> 
> And this one is not capable of delivering internationlized messages.
> 
> I didn't find a possibility to use any other language than 
> the default VM language.
> 
> Is internationalization just a planned feature of jPublish or 
> do I missunderstand someting fundamentally here? I would like 
> to use a locale that is store in the user session or the http 
> response. Can someone help me with this issue?
> 
> Thanks very much!
> 
> 
> Here is a patch for page.java that would solve the issues in our case:
> 
> 202c202
> <         return getProperty(name, Locale.getDefault());
> ---
> >         return getProperty(name, getLocale());
> 235c235
> <             return pageProperty.getValue();
> ---
> >             return pageProperty.getValue(locale);
> 263c263
> <         setProperty(name, value, Locale.getDefault());
> ---
> >         setProperty(name, value, getLocale());
> 274a275,296
> > 
> >  /**
> >   * Returns the locale.
> >   * @return Locale
> >   */
> >  public Locale getLocale() {
> >   if (locale == null){
> >    return Locale.getDefault(); 
> >   }
> >   else{
> >    return locale;
> >   }
> >  }
> > 
> >  /**
> >   * Sets the locale.
> >   * @param locale The locale to set
> >   * 
> >   */
> >  public void setLocale(Locale locale) {
> >   this.locale = locale;
> >  }
> 
> The patch adds the methods getLocale() and setLocale() and 
> replaces the Locale.getDefault() calls with the new 
> getLocale() calls. In the Method 
> getProperty(String name, Locale locale) I found a bug that 
> caused a value to be null when requested a second time (e.b. 
> $page.title in header and on page, this was only the case 
> with the unlocalized property value)
> 
> Do you see any side effects of this patch? The method 
> setLocale() should be called in a path action where the 
> locale could be taken from the user session and written to the page.
> 
> 
> 
> Sincerly,
> -florian
> 
> 
> 
> Florian Gnägi <[email protected]> http://www.olat-zentrum.unizh.ch
> 
> Center for Computing Services
> OLAT-Zentrum
> University of Zurich                Phone: +41 1 63 56788
> Winterthurerstrasse 190
> CH-8057 Zuerich                  FAX:   +41 1 63 
> 54505N¬HY޵隊X¬²š'²ŠÞu¼†zÛazw°=©fNéà²×§N§v¥tú0z°¨–Šâ§(š–œ
> ¶È³zm§ÿÚvË(º·~Šàzw­ýÈ"n)ÿ­çb­ç-¦ZZ–m4Óg§&››–+!uëÞ–Š^®f¢–)à–+
> -&››–+!uëÞ–Š^®X¬¶Ë(º·~Šàzw­†Ûi³ÿåŠËl²‹«qçè® §zßåŠËlþX¬¶)ߣøé¹¹b²^½éh
> 



-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf