Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
RE: MVC portlet development: how to internazionalize?
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Hi all, there is any example/documentation about developing a MVC portlet that manage multilingual content? For now, the only thing I know is that I have to put localized=true in service.xml file
<column localized="true" name="myColumn" type="String"></column> and use service builder to generate a persistence layer that manage different languages at the column level. I posted also a Liferay Documentation thread AAny hint?</column>
Hi (again) Mirto 
I'll try to help out on this one as well. You can leverage some of the aui input tag lib to help you out here. In your view (jsp?) you can use the aui input with an attribute that will render the flags for the languages that are available (configured) for you instance.
The post of the different values Liferay will actually handle for you which is great. On the back side you can use the ParamUtil to get the list of values. I am going from memory here but I think you get an array with <locale>=<value> like this --
I think at this stage you can convert it to a Map using the MapUtil class
... or something like that. Now that you have your map, you can call your service with the Map as a parameter and you should be good to go.
I'll try to help out on this one as well. You can leverage some of the aui input tag lib to help you out here. In your view (jsp?) you can use the aui input with an attribute that will render the flags for the languages that are available (configured) for you instance.
<aui:input name="sample" localized="<%= true %>" />The post of the different values Liferay will actually handle for you which is great. On the back side you can use the ParamUtil to get the list of values. I am going from memory here but I think you get an array with <locale>=<value> like this --
String[] sampleValues = ParamUtil.getStringValues(actionRequest, "sample", null);I think at this stage you can convert it to a Map using the MapUtil class
Map<locale, string> sampleMap = MapUtil.fromArray(sampleValues);</locale,> ... or something like that. Now that you have your map, you can call your service with the Map as a parameter and you should be good to go.
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Hi Andrew, thanks (again) 
I'm trying your suggestions
First progress:
I discovered how multilingual content is stored.
Using a Basic Web Content (journalarticle) when you edit an article you have a button to create a new translation (here I'm using English and Italian)
After the action that creates an Italian translation the multilanguage fields content is transformed in XML (example for description field)
Instead in my test field (the field "name" in the guestbook demo application) there is only standard text.
I'm investigating about the create translation function.
I'm trying your suggestions
First progress:
I discovered how multilingual content is stored.
Using a Basic Web Content (journalarticle) when you edit an article you have a button to create a new translation (here I'm using English and Italian)
After the action that creates an Italian translation the multilanguage fields content is transformed in XML (example for description field)
<!--?xml version='1.0' encoding='UTF-8'?-->
<root available-locales="en_US,it_IT," default-locale="en_US">
<description language-id="it_IT">prova multilingua</description>
<description language-id="en_US">multilingual test</description>
</root> Instead in my test field (the field "name" in the guestbook demo application) there is only standard text.
I'm investigating about the create translation function.
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Hi Andrew,
after a long time working on other issues I returned to this one.
Now I'm using Liferay 7.1 CE GA 1.
In edit_foo.jsp I have
<aui:input name="field5" localized="<%= true %>"/>
And in the interface I see the flag switch and the 2 translation I entered (see screenshot 1)
In MsbOnePortlet.java I have
String[] field5Values = ParamUtil.getStringValues(actionRequest, "field5", null);
But when I debug the code (see screenshot 2) only the string value of the active language flag:
it rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr
Instead I expected to receive couples of stings to convert to map. I mean
"it_IT", "it rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr", "EN_US", "en qqqqqqqqqqqqqqqqq"
What I'm missing?
Attachments:
Mirto Silvio Busico, modified 7 Years ago.
Regular Member
Posts: 240
Join Date: 1/18/12
Recent Posts
Well,
I was able to solve the aui frontend problems.
Now I close this thread and open a new one on write/read localized content.
Thanks