| <?xml version="1.0"?> |
| <!-- |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| --> |
| |
| <document> |
| |
| <properties> |
| <title>Localization Component</title> |
| <author email="epugh@upstate.com">Eric Pugh</author> |
| <author email="tv@apache.org">Thomas Vandahl</author> |
| </properties> |
| |
| <body> |
| |
| <section name="Overview"> |
| <p> |
| This component provides Localization of strings. It is written |
| for use in Turbine but it can be used in any container compatible |
| with Avalon's ECM container. |
| </p> |
| <p> |
| There two implementations |
| <ul> |
| <li>SimpleLocalizationService and</li> |
| <li>LocalizationService</li> |
| </ul> |
| The <code>SimpleLocalizationService</code> provides basic localization functions |
| for generic applications whereas the <code>LocalizationService</code> adds support |
| for web applications and depends on a servlet container environment. |
| </p> |
| </section> |
| |
| <section name="SimpleLocalizationService"> |
| <subsection name="Role Configuration"> |
| <source><![CDATA[ |
| <role |
| name="org.apache.fulcrum.localization.SimpleLocalizationService" |
| shorthand="localization" |
| default-class="org.apache.fulcrum.localization.SimpleLocalizationServiceImpl"/> |
| ]]></source> |
| </subsection> |
| |
| <subsection name="Component Configuration"> |
| <table> |
| <tr> |
| <th>Item</th> |
| <th>Datatype</th> |
| <th>Cardinality</th> |
| <th>Description</th> |
| </tr> |
| <tr> |
| <td>bundles</td> |
| <td>Complex</td> |
| <td>[1]</td> |
| <td> |
| The list of configured bundles. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles@locale-default-language</td> |
| <td>String</td> |
| <td>[0|1]</td> |
| <td> |
| The default language to use if none is specified. If this attribute |
| is absent, the JVM default language will be used. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles@locale-default-country</td> |
| <td>String</td> |
| <td>[0|1]</td> |
| <td> |
| The default country to use if none is specified. If this attribute |
| is absent, the JVM default country will be used. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles/bundle</td> |
| <td>String</td> |
| <td>[1..n]</td> |
| <td> |
| The name of the bundle |
| </td> |
| </tr> |
| </table> |
| </subsection> |
| |
| <subsection name="Component Configuration Example"> |
| <source><![CDATA[ |
| <localization> |
| <bundles locale-default-language="en" locale-default-country="US"> |
| <bundle>org.apache.fulcrum.localization.BarBundle</bundle> |
| <bundle>org.apache.fulcrum.localization.FooBundle</bundle> |
| </bundles> |
| </localization> |
| ]]></source> |
| </subsection> |
| </section> |
| |
| <section name="LocalizationService"> |
| <subsection name="Role Configuration"> |
| <source><![CDATA[ |
| <role |
| name="org.apache.fulcrum.localization.LocalizationService" |
| shorthand="localization" |
| default-class="org.apache.fulcrum.localization.DefaultLocalizationService"/> |
| ]]></source> |
| </subsection> |
| |
| <subsection name="Component Configuration"> |
| <table> |
| <tr> |
| <th>Item</th> |
| <th>Datatype</th> |
| <th>Cardinality</th> |
| <th>Description</th> |
| </tr> |
| <tr> |
| <td>bundles</td> |
| <td>Complex</td> |
| <td>[1]</td> |
| <td> |
| The list of configured bundles. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles@locale-default-language</td> |
| <td>String</td> |
| <td>[0|1]</td> |
| <td> |
| The default language to use if none is specified. If this attribute |
| is absent, the JVM default language will be used. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles@locale-default-country</td> |
| <td>String</td> |
| <td>[0|1]</td> |
| <td> |
| The default country to use if none is specified. If this attribute |
| is absent, the JVM default country will be used. |
| </td> |
| </tr> |
| <tr> |
| <td>bundles/bundle</td> |
| <td>String</td> |
| <td>[1..n]</td> |
| <td> |
| The name of the bundle |
| </td> |
| </tr> |
| </table> |
| </subsection> |
| |
| <subsection name="Component Configuration Example"> |
| <source><![CDATA[ |
| <localization> |
| <bundles locale-default-language="en" locale-default-country="US"> |
| <bundle>org.apache.fulcrum.localization.BarBundle</bundle> |
| <bundle>org.apache.fulcrum.localization.FooBundle</bundle> |
| </bundles> |
| </localization> |
| ]]></source> |
| </subsection> |
| </section> |
| |
| <section name="Resource Bundles"> |
| <p> |
| Resource bundles are basically property files. You might have one for |
| the "en" locale thus: |
| </p> |
| |
| <source><![CDATA[ |
| LABEL_ORGANIZATION = organisation |
| CURRENT_RECORD = Record {0} of {1} |
| ]]></source> |
| |
| <p> |
| and another for the "en_US" locale thus: |
| </p> |
| |
| <source><![CDATA[ |
| LABEL_ORGANIZATION = organization |
| ]]></source> |
| |
| <p> |
| Please see the <em>java.util.ListResourceBundle</em> and |
| <em>java.util.ResourceBundle</em> classes for more information. |
| </p> |
| </section> |
| |
| <section name="Usage"> |
| <source><![CDATA[ |
| TurbineServices.getInstance().getService(LocalizationService.LOCALIZATION) |
| .getString("DISPLAYPROJECTS_TITLE"); |
| ]]></source> |
| |
| <p> |
| Wow. That is a lot of typing. That could be easily shortened to this: |
| </p> |
| |
| <source><![CDATA[ |
| Localization.getString("DISPLAYPROJECTS_TITLE"); |
| ]]></source> |
| |
| <p> |
| The hard example above was given as an example of using Services. The easy |
| example is the one that you really should be using. Another cool feature |
| of the Localization class is that you can pass in a RunData object like |
| this: |
| </p> |
| |
| <source><![CDATA[ |
| Localization.getString(data, "DISPLAYPROJECTS_TITLE"); |
| ]]></source> |
| |
| <p> |
| This has the added effect of using the Accept-Language HTTP header to determine |
| which language to display based on what setting the user has defined in |
| the browser. Can you say Dynamic Localization? ;-) |
| </p> |
| |
| <p> |
| The Localization class also supports the formatting of localized strings containing |
| parameters, such as in |
| </p> |
| |
| <source><![CDATA[ |
| Localization.format(Localization.getDefaultBundle(), |
| Localization.getLocale(data.getRequest()), |
| "CURRENT_RECORD", |
| recno, all); |
| ]]></source> |
| |
| <p> |
| This actually doesn't look too nice, however the call using the LocalizationTool |
| from a <a href="http://velocity.apache.org/">Velocity</a> template just deflates to |
| </p> |
| |
| <source><![CDATA[ |
| $l10n.format("CURRENT_RECORD", $recno, $all); |
| ## Other examples |
| ## No arguments |
| $l10n.LABEL_ORGANIZATION |
| ## One argument |
| $l10n.format("STRING_KEY_ONE_ARG" "arg1") |
| ## Three or more arguments |
| $l10n.format("STRING_KEY_3_OR_MORE_ARGS" ["arg1", "arg2", "arg3"]) |
| ]]></source> |
| </section> |
| |
| </body> |
| </document> |