• No results found

Localizing Control Panel Portlets

In document Liferay 6.2 Developer Guide (Page 125-128)

3. Developing Portlet Applications

3.7. Adding Friendly URL Mapping to the Portlet

3.8.4. Localizing Control Panel Portlets

You may have noticed that your Control Panel-enabled portlets are missing that super-fancy must-have portlet title and description in the Control Panel. To make your portlet look cool within the Control Panel, create specially tailored description and title keys in separate Language.properties files for each portlet in your project. You'll use the

javax.portlet.title and javax.portlet.description language keys.

For demonstration purposes, let's consider a project that has one portlet named eventlisting and another portlet named locationlisting. We'll need to create a resource bundle for each of them to specify their localized title and description values.

Note: If your project only has one portlet, it's best to put your resource bundle directly in the content folder. Specifying your bundle in file

content/Language.properties lets you leverage the Plugins SDK's language building capabilities, via right-clicking on the Language.properties file → Liferay → Build Languages in Developer Studio or executing ant build-lang from the terminal.

Here's what you'd do to localize the title and description for each portlet in the project:

1. If you haven't done so already, configure each portlet to display in the Control Panel. For our example, we would display them in the Content portion and give them an arbitrary weight value for determining where they're to be placed in the column with respect to the other portlets. Here's a sample of how to specify this in our project's

liferay-portlet.xml file (Replace line breaks):

<portlet>

<portlet-name>eventlisting</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>

<portlet>

<portlet-name>locationlisting</portlet-name>

<icon>/icon.png</icon>

<control-panel-entry-category>site_administration.content</control-\

panel-entry-category>

<control-panel-entry-weight>1.6</control-panel-entry-weight>

....

</portlet>

2. Create a namespaced folder to hold each portlet's resource bundle. It's a best practice to name each resource bundle folder based on the name of its portlet.

Liferay 6.2 Developer Guide Page 125 For example, you could create a resource bundler folder content/eventlisting for the eventlisting portlet and a folder content/locationlisting for the

locationlisting portlet.

3. Create a Language.properties file in the resource bundle folders you just created.

Specify the javax.portlet.title and javax.portlet.description language key/values in each of these Language.properties files.

The eventlisting portlet could have the following key/value pairs in its content/eventlisting/Language.properties file:

javax.portlet.title=Event Listing Portlet

javax.portlet.description=Lists important upcoming events.

And the locationlisting portlet could have these key/value pairs in its content/locationlisting/Language.properties file:

javax.portlet.title=Location Listing Portlet javax.portlet.description=Lists event locations.

4. Specify the resource bundles for the portlets in the project's portlet.xml file. The example portlet.xml file code snippet below demonstrates specifying the resource bundles for the eventlisting and locationlisting example portlets:

<portlet>

<portlet-name>eventlisting</portlet-name>

...

<resource-bundle>content.eventlisting.Language</resource-bundle>

<portlet-info>...</portlet-info>

...

</portlet>

<portlet>

<portlet-name>locationlisting</portlet-name>

...

<resource-bundle>content.locationlisting.Language</resource-bundle>

<portlet-info>...</portlet-info>

...

</portlet>

5. Redeploy your plugin project.

6. Go to the Control Panel and select the Event Locations portlet.

7. Add en to your portal context in your URL to interface with the portal in Spanish. For example, your URL would start like this:

http://localhost:8080/es/group/control_panel/...

Portal's Control Panel displays your portlet's localized title and description.

Liferay 6.2 Developer Guide Page 126 You're becoming an expert localizer!

Tip: Do you know how your portlet title is processed? If your portlet doesn't define a resource bundle or javax.portlet.title, the portal container next checks the

<portlet-info> and inner <portlet-title> node in the portlet.xml descriptor. If they're missing too, the <portlet-name> node value is rendered as portlet title.

Note: Be aware that using Struts portlet and referring to a StrutsResource bundle in your portlet.xml engages a different title and description algorithm. Titles and long titles are pulled using two different keys:

javax.portlet.long-title

javax.portlet.title

Now that you're comfortable localizing portlet content, you may want to learn how to make translations available throughout the portal or how to override an existing translation. For instructions on doing that, refer to Chapter 10 of this guide, specifically the Overriding a Language.properties File section. It describes how to use a hook to override existing Liferay translations. You can share your keys with other portlets, as well as override existing Liferay translations.

Next, let's learn how to configure your portlets' preferences using configuration actions.

Liferay 6.2 Developer Guide Page 127

In document Liferay 6.2 Developer Guide (Page 125-128)