Liferayは6年連続でGartner Magic Quadrantのリーダーに。 詳細はこちら

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
Narmada V
Localization of Portlet
2012/05/18 3:58
答え

Narmada V

ランク: Junior Member

投稿: 37

参加年月日: 2012/05/13

最近の投稿

hi
I am trying to localize my portlet. I have added the below changes.

1. view.jsp:

<%@ page import="java.util.ResourceBundle" %>
<%@ page import="java.util.Locale" %>

<%
Locale locale = (Locale)request.getSession().getAttribute("org.apache.struts.action.LOCALE");
String language = locale.getLanguage();
String country = locale.getCountry();
ResourceBundle res = ResourceBundle.getBundle("content/Language_zh_TW", new Locale(language, country));
%>

<input type="button" value="<%= res.getString("hello-world") %>" />

2. created Language_sh_TW.properties and Language_sh_CN.properties files and added the below content.

javax.portlet.title=May15 Portlet
javax.portlet.short-title=May15portlet
javax.portlet.keywords=May15,portlet
hello-world=Hello World

3. I have modified the portlet.xml file as below.
<supported-locale>es</supported-locale>
<supported-locale>zh_CN</supported-locale>
<supported-locale>zh_TW</supported-locale>
<resource-bundle>content.Language_zh_TW</resource-bundle>

Note: Language.properties and Language_sh_TW.properties and Language_sh_CN.properties fiels are under the folder root/WEB-INF/src/content.

Even by making all these changes, i am unable to localize my portlet.

Could anyone please let me know anythng must be done??
Olaf Kock
RE: Localization of Portlet
2012/05/18 11:37
答え

Olaf Kock

LIFERAY STAFF

ランク: Liferay Legend

投稿: 3139

参加年月日: 2008/09/23

最近の投稿

Try the easier way:

<liferay-ui:message key="hello-world"/>
Hitoshi Ozawa
RE: Localization of Portlet
2012/05/18 18:47
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7949

参加年月日: 2010/03/23

最近の投稿

Be sure to include <%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>.

Information on liferay:ui tags
http://www.liferay.com/community/wiki/-/wiki/Main/Liferay+UI+Taglib
Narmada V
RE: Localization of Portlet
2012/05/20 20:33
答え

Narmada V

ランク: Junior Member

投稿: 37

参加年月日: 2012/05/13

最近の投稿

This gives localization for the predefined keys. This is not working for the non-key words.

If I need to write my own message in the portlet, how can it be localized.
Hitoshi Ozawa
RE: Localization of Portlet
2012/05/20 20:41
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7949

参加年月日: 2010/03/23

最近の投稿

This is not working for the non-key words.

What do you mean by "non-key words". You're suppose to create a key with a matching word/sentence in the language properties.
You're suppose to create your own language properties files for your own portlet. This seems to be what you were doing from your first post.
Narmada V
RE: Localization of Portlet
2012/05/20 21:23
答え

Narmada V

ランク: Junior Member

投稿: 37

参加年月日: 2012/05/13

最近の投稿

i am creating a custom portlet and trying to add some data to it. I want that data to be localized.

The code in jsp page is :
<liferay-ui:message key="yes" />
<liferay-ui:message key="hello-world" />

please find the screenshots attached.

as "yes" is predefined key word, i am getting it the language which i select. But "hello-world" is not the predefined key word. As mentioned, i have added it the Language_xx.properties file.

If i want to localize this hello-world, wat can be done.
画像の固定

添付ファイル: Localization.JPG (16.1k)
Vishal Panchal
RE: Localization of Portlet
2012/05/20 20:59
答え

Vishal Panchal

ランク: Expert

投稿: 279

参加年月日: 2012/05/20

最近の投稿

Hi Narmada V,
to get your own message localized you should specify it in Language.properties file(s) and access using
<liferay-ui:message key="hello-world"/>

or
As you are asking about "non-key words" than
I think you r asking the localized value of the string which is not defined in Language.properties file(s).
e.g. you want to make the studentName as localized which is directly comes from database and you cant define it in Language.properties.
If I am right than you may do one thing is as following:-
(1) In service.xml you may define desired field with localized="true"
e.g.<column name="studentName" type="String" localized="true" />
(2) you can access it as locale specific in your page like
<%= HtmlUtil.escape(modelObj.getStudentName(locale)) %>


Thanks& Regards,
Vishal R. Panchal
srikanth a
RE: Localization of Portlet
2012/05/21 1:04
答え

srikanth a

ランク: Regular Member

投稿: 142

参加年月日: 2011/02/20

最近の投稿

Hi Narmada,
One straight question to you.

1) Did you create the Language.properties for every supported language in your application.
2) If so did you put the key in all the files with respective translation.

if you have done this then you must get the value. Try to crosscheck it.


regards
Sri
Narmada V
RE: Localization of Portlet
2012/05/21 1:12
答え

Narmada V

ランク: Junior Member

投稿: 37

参加年月日: 2012/05/13

最近の投稿

yes i have created language.properties file respect to all the supported languages.

Do u mean to say, I need to write the translation code in the every file for each language??

If yes, suppose if i am getting dynamic data from different website to the portlet. I am not sure of the data i am getting from it. If i wish to Localize such kind of custom portlet what should be done??

Isn't there any tool or any other way provided by Liferay to change the language with out defining the translation code in Language.properties for such requirements?
Olaf Kock
RE: Localization of Portlet
2012/05/21 3:54
答え

Olaf Kock

LIFERAY STAFF

ランク: Liferay Legend

投稿: 3139

参加年月日: 2008/09/23

最近の投稿

Do you reference your localization within portlet.xml?

1<resource-bundle>content/Language</resource-bundle>


(Note: Portlets don't take the .properties ending while hooks do, there it's within the <language-properties> element)
Hitoshi Ozawa
RE: Localization of Portlet
2012/05/21 4:21
答え

Hitoshi Ozawa

ランク: Liferay Legend

投稿: 7949

参加年月日: 2010/03/23

最近の投稿

Do u mean to say, I need to write the translation code in the every file for each language??


No. :-)

Isn't there any tool or any other way provided by Liferay to change the language with out defining the translation code in Language.properties for such requirements?


There actually isn't any requirement to use one specific way. It's possible to use other internationalization technique if you don't want to use liferay's.