Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Gustavo Fernandes
Portlet title localization
December 7, 2012 6:08 AM
Answer

Gustavo Fernandes

Rank: Junior Member

Posts: 26

Join Date: October 3, 2011

Recent Posts

Hello,

I am trying to make a portlet title localizable.
So, i followed the instructions to do so. Namely, this and this.

Yes the portlet title gets localized BUT..... if the portlet title contains accented characters (portuguese in my case) these characters are rendered as "gibberish", for the portlet title. The remaining bundle labels are not affected.
Example, for a portuguese word: Gestão, which gets rendered as : Gest�o

IF i modify the resource bundle file's encoding. In this case the title gets rendered correctly BUT.... the other bundle labels, which contain accented characters, are rendered incorrectly.

I atttached the resource bundle files, and the portlet.xml file.

I have this version of liferay bundle, over JBOSS using MySQL :

Liferay Portal Community Edition 6.1.1 CE GA2 (Paton / Build 6101 / July 31, 2012

I am developing using Eclipse Indigo.

The prescribed way (the 'official' one) does not work for these characters.

Any suggestions?

Thank you for any thoughts you might have.

Cheers,

Gustavo
Attachments: Language.properties (1.7k), Language_pt_PT.properties (1.7k), portlet.xml (1.4k)
Gustavo Fernandes
RE: Portlet title localization
December 11, 2012 6:03 AM
Answer

Gustavo Fernandes

Rank: Junior Member

Posts: 26

Join Date: October 3, 2011

Recent Posts

Just dropping a line on what was the solution i and a colleague found.
We found it on stackoverflow, but i don't have the link right now.

So we have changed the encoding for the resource bundle files (.properties) to UTF-8.
Then, inside the functions we're using to get the bundle values;

 1public static String getValue(String key, String valueForKeyNotFound ){
 2        String keyNotfoundMessage = bundle.getString(WebContentListPortletConstants.MESSAGE_KEYNOTFOUND);
 3        String value=keyNotfoundMessage+key;       
 4        try {
 5            value = bundle.getString(key);
 6        } catch (MissingResourceException ex){
 7            if(valueForKeyNotFound != null && !valueForKeyNotFound.isEmpty() ){
 8                value = valueForKeyNotFound;
 9            }
10        }       
11        try {
12            [b]value =  new String(value.getBytes("ISO-8859-1"), "UTF-8");[/b]
13        } catch (UnsupportedEncodingException e) {
14            // TODO Auto-generated catch block
15            e.printStackTrace();
16        }
17        return value;
18       
19    }


Not a very ellegant solution, rather a workaround, i know.
HTH someone out there!

Gustavo