When to Use Which Multilanguage Feature
WPS provides a number of ways where you can implement Multilanguage support. In fact, there are such a number of them that it is confusing for the inexperienced user. This tip lists down the steps to take according to your Multilanguage requirements.
Use the portlet context’s getResourceAsStream(). This method lets you open the file for the particular markup and human language.
eg
PORTLET-INF
|- Your regular portlet-inf
stuffs……
|- YourResources
|-
html
|-
data.file
|-
en
|-
data.file
|-
uk
|-
data.file
|-
us
|-
data.file
|-
ja
|-
data.file
|-
zh
|-
data.file
|-
wml
|-
same structure as html
eg
InputStream dataIOS =
getPortletConfig().getContext().getResourceAsStream(“/PORTLET-INF/YourResources/data.file”,htmlClient,chineseLocale);
The getResourceAsStream() method will know how to search your directory structure
for the data.file that matches the markup, locale and
variant. See the javadocs of the PortletContext class for the
details.
Use portlet context’s getText() method. This method lets you display a text from a file. The file must be in name-value pairs ie a Properties formatted file.
PORTLET-INF
|- Your regular portlet-inf
stuffs……
|- classes
|-
nls
|-
data.properties
|-
data_en.properties
|-
data_ja.properties
|-
data_zh.properties
/PORTLET-INF/classes directory. data_nl.properties,
where nl
is the supported language.key = value
format,
where key must appear in all
the properties files, and value
is in the corresponding language.
String localizedText = getConfig().getContext().getText(“nls.data”,
“welcomeHeader”, getLocale());
The first argument to the getText() method is the dot delimited String of
the directory structure and filename. The second argument is the key which you want to
extract the value, and the third argument is the Locale object.
Note: In the stock sample that comes with WPS, the sample
code uses the java.util.ResourceBundle class for retrieving Multilanguage text. It is
recommended that you use the method described here rather than that of the
stock sample. The reason is the same as described in Step 5 of tip: How to access
file in portlets. There is no way you can par your ML
files such that the Portlet Installer can expand it to the correct WPS
directory.
eg
<P>portletAPI:text
key="welcomeHeader"
bundle="nls.data"/></P>
Portal wide Multilanguage properties files can be found in the following directory:
<wps_root>\app\web\WEB-INF\classes.
You can access the values in these properties file from your portlets and JSPs
eg
java.util.ResourceBundle resourceBundle = com.ibm.wps.puma.ResourceBundleLoader.getBundle("nls.registration",
request.getLocale());
where registration
is one of the ML properties file found under <wps_root>/app/web/WEB-INF/class/nls
You can then access the ML value by:
eg
String namePrompt = resourceBundle.getString("givenName");
Or in your JSP:
<p><%= resourceBundle.getString("givenName") %>
<INPUT>……
There are cases when it might just be more convenient for you to have multilingual JSPs, rather than using one JSPs together with many different resource files. A good example would be a JSP containing help instructions.
eg
PORTLET-INF
|- your usual portlet-inf stuffs
|- helpjsps
|-html
|- help.jsp
|- en
|- uk
|- help.jsp
|- us
|- help.jsp
|- zh
|- help.jsp
|- wml
|- follows same
structure
eg
portletcontext.include("/PORTLET-INF/helpjsps/help.jsp",
portletrequest, portletresponse);
WPS will be smart enough to pick up the correct ML file for display based on the user’s preferred language and browser type.