Authors
Overview
This portlet demonstrates how to use the org.exoplatform.services.resources.LocaleConfigService to switch the language of the Portal. The idea is to offer a portlet with just a few flags, which act as language switch buttons, instead of the language selection popup currently provided by GateIn.
Description
The main part using the LocaleConfigService can be found in the processAction method of the portlet, where the desired language is being passed in as parameter:
LocaleConfigService localeConfigService = (LocaleConfigService) PortalContainer.getInstance().getComponentInstanceOfType(LocaleConfigService.class); LocaleConfig localeConfig = localeConfigService.getLocaleConfig(language.toLowerCase()); if (localeConfig == null) localeConfig = localeConfigService.getDefaultLocaleConfig(); PortalRequestContext prqCtx = PortalRequestContext.getCurrentInstance(); prqCtx.setLocale(localeConfig.getLocale());
For the display of the flags, portlet preferences are being used. At startup, these are read from portlet.xml (see below), and can be changed at runtime using the portlets edit mode:
<portlet-preferences> <preference> <name>supported.languages</name> <value>CN,DE,ES,FR,EN,GR,IN,IT,JP,KO,NL,PL,PT,RU,TR</value> <read-only>true</read-only> </preference> <!-- a comma-delimited string of all flags that should be displayed --> <preference> <name>display.languages</name> <value>DE,EN,FR,IT</value> <read-only>false</read-only> </preference> </portlet-preferences>
Just note that the 'supported.languages' value is based on the flag icons that are included in the portlet, but could be extended if necessary.
Installation procedure
- Get a copy of the source with GIT: git clone git://github.com/martinweiler/languageSwitchPortlet.git
- Type 'mvn package'
- Copy target/languageSwitchPortlet.war into the deploy directory of GateIn/EPP
Build system: Maven
Source location: GIT at https://github.com/martinweiler/languageSwitchPortlet
Compatibility list (please add to this list if you have tested a new version of GateIn):
Tester | Version of the example | Version of GateIn | Result | Comment |
---|---|---|---|---|
Martin Weiler | 1.0.0 | GateIn 3.1.0 | KO | org.exoplatform.portal.application.PortalRequestContext has no method setLocale |
Martin Weiler | 1.0.0 | GateIn 3.2 (trunk) | OK | |
Martin Weiler | 1.0.0 | EPP 5.1 | OK |
Comments