Your plugin project may have Site Administration portlets that are missing super-fancy, must-have titles and descriptions that other admin portlets have. Or if you’ve already provided titles and descriptions, you may be wondering how to localize them, to cater to your users’ differing language needs. Well, Liferay makes it easy to implement these cool looking features to your portlets.
To offer localized portlets within Site Administration, you can create specially tailored descriptions and title keys in separate
Language.properties files for each portlet in your project. You use the
javax.portlet.description language keys. The following figure displays an example of localizing portlets to Spanish:
Next, you’ll configure your project’s portlets to display in Site Administration, and then you’ll localize its title and description. You’ll create one resource bundle for the title and another one for the description.
Specify and localize a title and description for each of your project’s portlets by following these steps:
Configure each portlet to display in Site Administration. For example, you can display a portlet in Site Administration’s Content category and you can give your portlet an arbitrary weight value for determining where it’s to be placed in the column with respect to other portlets. You specify each portlet’s category and weight values in the
<control-panel-entry-weight/>elements for each portlet in your project’s
For example, the following XML from a
liferay-portlet.xmlfile specifies Content as the portlet’s category, making the portlet available in the Content section of the Site Administration menu.
<portlet> <portlet-name>yourportlet</portlet-name> <icon>/icon.png</icon> <control-panel-entry-category>site_administration.content</control-panel-entry-category> <control-panel-entry-weight>1.5</control-panel-entry-weight> ... </portlet>
Create a namespaced folder to hold each portlet’s resource bundle. It’s a best practice to name each resource bundle folder based on each portlet’s name.
For example, you’d create a resource bundle folder
docroot/WEB-INF/src/content/yourportletif one of your project’s portlet’s names was yourportlet.
Language.propertiesfile in each resource bundle folder you just created. Specify the
javax.portlet.descriptionlanguage key/values in each of these
For example, you could add the following properties to each
Language.propertiesfile and replace their values:
javax.portlet.title=Your Portlet javax.portlet.description=Your portlet's description.
Specify the resource bundle for each portlet in the portlet’s
<resource-bundle>element in the project’s
portlet.xmlfile. The code snippet below demonstrates specifying the resource bundle for a portlet named yourportlet:
<portlet> <portlet-name>yourportlet</portlet-name> ... <resource-bundle>content.yourportlet.Language</resource-bundle> <portlet-info>...</portlet-info> ... </portlet>
Redeploy your plugin project.
Go to Site Administration → Content and select one of your portlets. Notice that the portlet’s title and description match what you specified in its
To provide your portlet in Liferay’s supported languages, you’ll need to build your portlet’s languages. To do this in Liferay IDE, right-click your portlet’s
content/[PORTLET_NAME]/Language.propertiesfile and select Liferay → Build Languages. You can also accomplish the same thing from the terminal by executing
Note: In order to generate translations of resource bundles automatically, you must configure your environment to use Microsoft’s Bing Translator. Otherwise, Liferay’s
build-langtarget simply generates a
Language_*.propertiesfile copying the original contents of
Langauge.properties, for each language that Liferay supports. In other words, unless you configure to use Bing Translator, you must manually translate the values in the generated
Language_*.propertiesfiles. See the tutorial Translating Languages Using the Bing Translator for details on using the automatic translation services.
Now that you have the languages built, you can specify language key values for each of the supported language files that were generated. For example, the Spanish translation for the title and description of a portlet named yourportlet could be designated inside the
Language_es.propertiesfile as the following keys:
javax.portlet.title=Su portlet en Espanol javax.portlet.description=Descripcion del portlet en Espanol.
To switch the portal to a specific language, add the code of that language to the portal context in the URL. For example, to interface with the portal in Spanish, you’d add
esto the portal context in the URL like this:
The Site Administration page displays your portlet’s localized title and description.
You’re becoming an expert localizer!
Terrific! You’ve configured your plugin’s portlets to show in the Site Administration page, created resource bundles specifically for each portlet, built your portlets’ language translation files, and have verified your portlets’ translated titles and descriptions!