掲示板

Programatically change language

15年前 に Miguel Ancochea によって更新されました。

Programatically change language

New Member 投稿: 7 参加年月日: 08/04/28 最新の投稿
Hi,

We want to change the portal language with our own language-switching links. Therefore, we've thought we need either a way of customizing:

$taglibLiferay.language()

so it shows our own text and style for the links OR we need to change the whole portal language programatically. Is it possible? How?.


One last question: once the language is changed portal-wide how can we get the current language as Locale eg. "en_UK" within any portlet?

We're in a bit of hurry with these. Thanks in advance.
15年前 に Miguel Ancochea によって更新されました。

RE: Programatically change language

New Member 投稿: 7 参加年月日: 08/04/28 最新の投稿
Hi again,

We've seen how to solve the second question, that is, how to query for the current Locale from a portlet:

ThemeDisplay themeDisplay =(ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
Locale locale = LocaleUtil.fromLanguageId(themeDisplay.getLanguageId());

It's also possible to use LanguageUtil instead of ThemeDisplay for this operation.

Still, we don't know how to change the language portal-wide for example from a theme velocity template (we have our own theme) or from a portlet.

Anyone?
15年前 に Richard Becher によって更新されました。

RE: Programatically change language

Junior Member 投稿: 55 参加年月日: 08/06/20 最新の投稿
Hey there,

Did you ever find an answer on how to change the language at the Theme level?

Thanks!
14年前 に Affar Le Rafee によって更新されました。

RE: Programatically change language

Junior Member 投稿: 29 参加年月日: 09/01/18 最新の投稿
Has anyone found a solution to this problem???????
14年前 に Richard Becher によって更新されました。

RE: Programatically change language

Junior Member 投稿: 55 参加年月日: 08/06/20 最新の投稿
Nope....not yet.
13年前 に T FoX によって更新されました。

RE: Programatically change language

Junior Member 投稿: 34 参加年月日: 10/03/02 最新の投稿
You could simply create an hook to override the docroot\html\taglib\ui\language\page.jsp file and apply your own styling to the language selector.

You could also change the language programmatically by executed following method:

themeDisplay.setLocale(new Locale("nl"));
13年前 に Deepak Kenchamba によって更新されました。

RE: Programatically change language

New Member 投稿: 3 参加年月日: 10/10/12 最新の投稿
Liferay seems to follow the technique of inserting the "2 character" language string to the URL to force a language change to the entire portal.
The language string is inserted right after the scheme://server:port/ part of the HTTP URL

While this can be done via the Liferay API or the Language Portlet (as explained above), it can also be done with a nifty javascript which follows the "2 character" language string insertion technique.
Pick up the current browser URL value - window.location & update it switch to the language of choice & force a reload. Voila, the language switch happens with no portlets involved.


E.g:
Default URL
[indent] http://172.16.2.237:8080/web/testtoday/home1[/indent]
Modified URL
[indent] http://172.16.2.237:8080/ar/web/testtoday/home1[/indent]

Notice that the second URL forces Liferay to render the portal in Arabic!
thumbnail
12年前 に David García González によって更新されました。

RE: Programatically change language

Regular Member 投稿: 127 参加年月日: 09/07/14 最新の投稿
I think it is better to change the language programmatically.

http://www.liferay.com/es/community/forums/-/message_boards/message/9380899
thumbnail
12年前 に Achmed Tyrannus Albab によって更新されました。

RE: Programatically change language

Regular Member 投稿: 158 参加年月日: 10/03/05 最新の投稿
Deepak Kenchamba:
Liferay seems to follow the technique of inserting the "2 character" language string to the URL to force a language change to the entire portal.
The language string is inserted right after the scheme://server:port/ part of the HTTP URL

While this can be done via the Liferay API or the Language Portlet (as explained above), it can also be done with a nifty javascript which follows the "2 character" language string insertion technique.
Pick up the current browser URL value - window.location & update it switch to the language of choice & force a reload. Voila, the language switch happens with no portlets involved.


E.g:
Default URL
[indent] http://172.16.2.237:8080/web/testtoday/home1[/indent]
Modified URL
[indent] http://172.16.2.237:8080/ar/web/testtoday/home1[/indent]

Notice that the second URL forces Liferay to render the portal in Arabic!


Haha genius!
thumbnail
9年前 に Pawel Kruszewski によって更新されました。

RE: Programatically change language

New Member 投稿: 3 参加年月日: 09/04/09 最新の投稿
Hi all,

try to use languageId parameter. In my case I had to overwrite redirect url in my struts action hook as I wanted to change locale after user was redirected:

public class CreateAccountAction extends BaseStrutsPortletAction {
    public final void processAction(
            final StrutsPortletAction originalStrutsPortletAction,
            final PortletConfig portletConfig,
            final ActionRequest actionRequest,
            final ActionResponse actionResponse) throws Exception {

        DynamicActionRequest dynamicActionRequest = new DynamicActionRequest(
                actionRequest);
            String redirect =
                    dynamicActionRequest
                            .getParameter(WebKeys.REDIRECT.toLowerCase());
            redirect = HttpUtil
                    .addParameter(redirect, "languageId", languageId);
            dynamicActionRequest.setParameter(
                    WebKeys.REDIRECT.toLowerCase(), redirect);

        originalStrutsPortletAction.processAction(originalStrutsPortletAction,
                portletConfig, dynamicActionRequest, actionResponse);
}


Works really well.

Greets,
Pawel