Fórum

i18n for developed portlet

Shreyas Kamthe, modificado 9 Anos atrás.

i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi,

This is shreyas.

I am new to Liferay and i am currently working on portlet development.
I want to provide the option of different languages on my portlet. But i want to provide them on the click of button.
What i mean is that i want a button named "French" "German" etc and when the user clicks it the language should change
on reloading the page. I have done it successfully in struts and jsf. But i want to do it using alloy ui.

So please help me.

Thanks
thumbnail
Hitesh Methani, modificado 9 Anos atrás.

RE: i18n for developed portlet

Regular Member Postagens: 171 Data de Entrada: 24/06/10 Postagens Recentes
Hello Shreyas,

You can try changing the locale of the page in controller by using themeDisplay object available,
themeDisplay.setLocale() and themeDisplay.setLanguageId() might do the needful.

Regards,
Hitesh Methani.
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
There's a Language portlet in Liferay - you might want to look at this one and check how it's doing its magic.

Also, you can manipulate the URL. E.g. you'll see the german version by inserting "/de" right after the server name - e.g. the german UI for Liferay's forums is on https://www.liferay.com/de/community/forums (in this case there's not too much content here that's being translated, but the UI and menu should demonstrate the effect.
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Hitesh and Olaf,

Thanks for your response.But can you tell me how to change the url by adding /de through portlet code.
And if I use themedisplay.setlocale() and themedisplay.setlanguageid() will these remain throughout for the whole application ?

Please help me.
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
Shreyas Kamthe:
Thanks for your response.But can you tell me how to change the url by adding /de through portlet code.

It can be as simple as a string operation on the URL. Other than that I'd do exactly what I recommended above: Look at the language portlet that's delivered with Liferay. As I don't have time to do this right now, please do so yourself.
Shreyas Kamthe:
And if I use themedisplay.setlocale() and themedisplay.setlanguageid() will these remain throughout for the whole application ?

Isn't it quicker to try it yourself than to ask here and wait for the answer?
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Olaf,

Thanks for responding. I tried the method you suggested (using the Language portlet provided by Liferay) and it works.
Now the thing is that i want to add my own language to that Language portlet.
So can you just suggest me any method or way by which i can do that ?

Please do reply.
krishna rao, modificado 9 Anos atrás.

RE: i18n for developed portlet

New Member Postagens: 10 Data de Entrada: 13/07/14 Postagens Recentes
Hi Shreyas,

Please follow below steps to add new locale

Step 1 :- Add your locale to portal-ext.properties file {locales=en_US,sl_SI,de_DE,fr_FR,hu_HU,it_IT}

Step 2 :- Stop server and extract portal-impl and add new property file as given below

Step 3 :- Add new languge file Languages_sl.properties to the ROOT/WEB-INF/lib/portal-impl.jar/content folder

Step 4 :- Now start server and use new locale
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi krishna,

Thanks for replying.
Currently the portal-ext.properties file (that i created) does not contain any locales.
It only contains the database connectivity configuration.
So do i have to add them manually as you said {locales = en_US,sl_SI,de_DE,fr_FR,hu_HU,it_IT} ?
And when i modify the jar file after extracting it do i have to again put it in archive (convert it into .jar) ?

please do reply
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
krishna rao:
Step 2 :- Stop server and extract portal-impl and add new property file as given below

Step 3 :- Add new languge file Languages_sl.properties to the ROOT/WEB-INF/lib/portal-impl.jar/content folder


Do not do Steps 3 and 4! For the sake of maintainability you do not want to mess with the content of Liferay's jar files. Instead, you want to create a hook containing your Language_xx.properties and deploy it.

Steps 1 and 4 I agree with.
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Olaf,

Thanks for responding

I referred the site you provided me. I also carried out all the steps.
The thing is that i am able to translate my portlet to languages provided by
Language portlet. But I need to add the new language to Language portlet.
I want to use that new language for my portlet. I also created .properties file
for that language. But how do i use it ?

Please do reply
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
Two aspects:

1. In order to translate your portlet to a new language, just follow the standard procedures and deliver your portlet with Language_xx.properties resources (provided your language code is xx). In order to do this, you configure your portlet to have a localization resource in portlet.xml like this:
<resource-bundle>content.Language</resource-bundle>

Refer to the Developer's Guide for more information, the line above is copied from there.

2. If the language you want to use (let's keep "xx") is not yet known to Liferay, open your portal-ext.properties and define the languages you want to have available. You do this, as documented above. For more information, see this excerpt from the original portal.properties

    #
    # Specify the available locales. Messages corresponding to a specific
    # language are specified in properties files with file names matching that
    # of content/Language_*.properties. These values can also be overridden in
    # properties files with file names matching that of
    # content/Language-ext_*.properties. Use a comma to separate
    # each entry.
    #
    # If there is more than one locale for the same language, the first one in
    # the list will be used when a translation is requested in another locale of
    # the same language but a translated value cannot be found. For example, if
    # there are two locales such us pt_BR and pt_PT (in this order), any key not
    # found in pt_PT will be looked for in pt_BR.
    #
    # Language codes follow the ISO 639-1 standard. Content for each locale must
    # be UTF-8 encoded.
    #
    # See the following links, which specify language and country codes:
    #     http://www.loc.gov/standards/iso639-2/php/code_list.php
    #     http://userpage.chemie.fu-berlin.de/diverse/doc/ISO_3166.html
    #
    locales=ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,hr_HR,cs_CZ,da_DK,nl_NL,nl_BE,en_US,en_GB,en_AU,et_EE,fi_FI,fr_FR,fr_CA,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,it_IT,ja_JP,ko_KR,lo_LA,lt_LT,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ro_RO,ru_RU,sr_RS,sr_RS_latin,sl_SI,sk_SK,es_ES,sv_SE,tr_TR,uk_UA,vi_VN

    #
    # Specify the locales that are in beta. Go to http://translate.liferay.com
    # to participate in the translation efforts.
    #
    locales.beta=ar_SA,eu_ES,bg_BG,ca_AD,zh_TW,hr_HR,cs_CZ,da_DK,nl_NL,nl_BE,en_GB,en_AU,et_EE,gl_ES,el_GR,hi_IN,in_ID,it_IT,ko_KR,lo_LA,lt_LT,nb_NO,fa_IR,pl_PL,pt_PT,ro_RO,ru_RU,sr_RS,sr_RS_latin,sl_SI,sk_SK,sv_SE,tr_TR,uk_UA,vi_VN

    #
    # Specify the locales that are enabled by default.
    #
    locales.enabled=ca_ES,zh_CN,en_US,fi_FI,fr_FR,de_DE,iw_IL,hu_HU,ja_JP,pt_BR,es_ES



thus, you'll need to add

# note the new "xx" entry at the beginning
locales=xx,ar_SA,eu_ES,bg_BG,ca_AD,ca_ES,zh_CN,zh_TW,hr_HR,cs_CZ,da_DK,nl_NL,nl_BE,en_US,en_GB,en_AU,et_EE,fi_FI,fr_FR,fr_CA,gl_ES,de_DE,el_GR,iw_IL,hi_IN,hu_HU,in_ID,it_IT,ja_JP,ko_KR,lo_LA,lt_LT,nb_NO,fa_IR,pl_PL,pt_BR,pt_PT,ro_RO,ru_RU,sr_RS,sr_RS_latin,sl_SI,sk_SK,es_ES,sv_SE,tr_TR,uk_UA,vi_VN

# note the new "xx" entry at the beginning, add all the languages you want to have available by default
locales.enabled=xx,en_US


As always, when changing portal-ext.properties: Restart.

Deploy your portlet. Enjoy
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Olaf,

Thanks a lot Olaf and Krishna for helping me out in this task.

I am able to add new language as well as customize my portlet
to the language provided by liferay. There is just one small defect in my application.
I have added Marathi as my new language with language code ma_IN. But in Language portlet
it appears as "ma". I want it to appear it as Marathi. So where do i make the changes ?

Please do reply
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
I believe it's as easy as adding a translation/language hook, containing the definition for

language.ma_IN=Marathi


If that goes wrong, maybe you'll need a language.ma definition as well.
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Olaf,

Thanks for replying. Got the solution. You solution(of hook) has worked.
Is it possible to change the name of the site and the name of the page
through the Library portlet. If yes can you suggest me some way ?
And also can you tell me how to change the title of other portlets that are
on my page (for example change the title "Language" of Language portlet to the native language)?

Please do reply
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
The name of the site is changed in Site Administration. In case of the default site (the one with the /web/guest URLs), it's the Portal's name, which you find in Server Administration / Preferences, it's the top left field there - but you'll also recognize it from its name. This name is whatever you've provided to the Startup Wizard when you first started Liferay.
Shreyas Kamthe, modificado 9 Anos atrás.

RE: i18n for developed portlet

Junior Member Postagens: 58 Data de Entrada: 09/06/14 Postagens Recentes
Hi Olaf,

So sorry i posted the wrong question.I meant how to change the language of the name of the site and the language of the name of the page
according to the language selected from the Language portlet. Also i wanted to know how to change the language of name of other portlets
that appear on my page by selecting the language in the Language portlet

So sorry about the earlier question emoticon
Please do reply
thumbnail
Olaf Kock, modificado 9 Anos atrás.

RE: i18n for developed portlet

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
In Page Administration, you can translate the name of your pages (even your URLs). If you refer to the portlet titles (e.g. in the portlet borders): They are already translateable/translated. If you change them, you can also provide different names per language in the portlet's "Look & Feel" dialog. If you want different default names for your new language, you can also provide them in your language hook. Just look up javax.portlet.title.* entries in Language.properties