Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
brijesh baser
In Servlet, LanguageUtil.get(locale,"key") some time it return key.
December 10, 2009 2:14 AM
Answer

brijesh baser

Rank: New Member

Posts: 20

Join Date: March 5, 2009

Recent Posts

Hi,

In my servlet, when I call LanguageUtil.get(locale,"key"). Some time it returns key and some time it return value.
I am able to understand that how is it possible.(Locale object is retrieve by user object. ).

Can any one help me.

Thanks & Regards,
Brijesh Baser
brijesh baser
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
December 10, 2009 2:16 AM
Answer

brijesh baser

Rank: New Member

Posts: 20

Join Date: March 5, 2009

Recent Posts

just correct last sentence
I am not able to understand the problem.
Amos Fong
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
December 10, 2009 10:17 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1896

Join Date: October 7, 2008

Recent Posts

Hi Birjesh,

This how it works. For example, I want to get the key "hello-world". So I call

LanguageUtil([English Locale], "hello-world")

First it checks Language_en_US.properties for the english translation. If it doesn't exist, it then checks Language.properties. If it still can't find the translation, then it just returns the key.

See this wiki:
http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/Languagedisplay+customization
brijesh baser
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
December 10, 2009 10:25 PM
Answer

brijesh baser

Rank: New Member

Posts: 20

Join Date: March 5, 2009

Recent Posts

Hi Amos,

I know that how it is work. But in my case, key is inside Language-ext.properties file and some time it (LanguageUtil([English Locale], "hello-world")) it fetch value or some it just print key.

How can I solve this.

Thanks & Regards
Brijesh Baser
Amos Fong
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
December 11, 2009 9:57 AM
Answer

Amos Fong

LIFERAY STAFF

Rank: Liferay Legend

Posts: 1896

Join Date: October 7, 2008

Recent Posts

Sometimes the same key will display translated and sometimes it won't? Or some keys show and some do not?
brijesh baser
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
December 14, 2009 3:10 AM
Answer

brijesh baser

Rank: New Member

Posts: 20

Join Date: March 5, 2009

Recent Posts

Sometimes the same key will display translated and sometimes it won't
Ronaldo Felipe
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
November 9, 2010 5:10 AM
Answer

Ronaldo Felipe

Rank: New Member

Posts: 6

Join Date: August 24, 2010

Recent Posts

I've stuck in a similar problem, but, in my case, LanguageUtil is returning wrong translation and it happens in one spot Liferay's calendar. For instance the Liferay's login is translating correctly to pt_BR while the calendar is en_US.

Extra info: This misunderstand of locale happens when you don't put a title in a event for example.
Ronaldo Felipe
RE: In Servlet, LanguageUtil.get(locale,"key") some time it retur
November 9, 2010 7:28 AM
Answer

Ronaldo Felipe

Rank: New Member

Posts: 6

Join Date: August 24, 2010

Recent Posts

In the end it wasn't a locale problem, just a wrong default translation.


I solved it changing portal-impl.jar/content/Language_pt_BR.properties in LIFERAY_HOME\tomcat-6.0.18\webapps\ROOT\WEB-INF\lib
It wasn't a good solution but when I tried put my LIFERAY_HOME/tomcat-6.0.18/webapps/ROOT/WEB-INF/content/Language-ext_pt-BR.properties it didn't override liferay's default properties so I corrected it myself.
Vijay Gohil
RE: In Servlet, LanguageUtil.get(locale,"key") some time it return key.
August 3, 2011 11:45 PM
Answer

Vijay Gohil

Rank: New Member

Posts: 15

Join Date: June 29, 2010

Recent Posts

Hi Brijesh,
I have also faced same problem and i have also found solution for that
Use pageContext as first parameter in place of locale object in LanguageUtil.get (locale, key) method
pageContext is implicit object of jsp
Sagar A Vyas
RE: In Servlet, LanguageUtil.get(locale,"key") some time it return key.
August 4, 2011 6:49 AM
Answer

Sagar A Vyas

Rank: Liferay Master

Posts: 657

Join Date: April 17, 2009

Recent Posts

brijesh baser:
Hi,

In my servlet, when I call LanguageUtil.get(locale,"key"). Some time it returns key and some time it return value.
I am able to understand that how is it possible.(Locale object is retrieve by user object. ).

Can any one help me.

Thanks & Regards,
Brijesh Baser


Hi Brijesh,

Two things that
1)
If you want to access your property from jsp page then you have to write
<%= LanguageUtil.get(pageContext,"my-own-msg") %>
2)
If you want to access your property from controller page then you have to write
PortletConfig portletConfig = (PortletConfig) portletRequest.getAttribute(JavaConstants.JAVAX_PORTLET_CONFIG);
String mailBody = LanguageUtil.get(portletConfig, locale, key);
where locale = themeDisplay.getLocale()
key = your key which you have defined in Language.property file

Thanks,
Sagar Vyas
Avinash R
RE: In Servlet, LanguageUtil.get(locale,"key") some time it return key.
October 28, 2013 7:27 AM
Answer

Avinash R

Rank: New Member

Posts: 13

Join Date: September 19, 2013

Recent Posts

Vijay Gohil:
Hi Brijesh,
I have also faced same problem and i have also found solution for that
Use pageContext as first parameter in place of locale object in LanguageUtil.get (locale, key) method
pageContext is implicit object of jsp

Thank you that worked.

Also, as an alternate solution, you can also use LanguageUtil.get(portletConfig, locale, key)
where the portletConfig is also an implicit object available in jsp.

rel: https://www.liferay.com/community/forums/-/message_boards/message/21325568
Montej Shah
RE: In Servlet, LanguageUtil.get(locale,"key") some time it return key.
August 5, 2015 7:47 AM
Answer

Montej Shah

Rank: Junior Member

Posts: 25

Join Date: February 18, 2015

Recent Posts

Hi Sagar A Vyas,
you are right when we call from controller side it's require to know from which portlet we want to get key value.
Because of it can happen for each portlet we can create individual language file. So portletConfig is the object through which LanguageUtil know which file to use for key and value