blob: df0c75227a6dac7daacba538359e02d5ad48df19 [file] [log] [blame]
<!DOCTYPE html>
<!--
| Generated by Apache Maven Doxia Site Renderer 1.9.2 from xdocs/index.xml at 14 September 2021
| Rendered using Apache Maven Fluido Skin 1.9
-->
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="generator" content="Apache Maven Doxia Site Renderer 1.9.2" />
<meta name="author" content="Eric Pugh" />
<meta name="author" content="Thomas Vandahl" />
<title>Fulcrum Localization &#x2013; Localization Component</title>
<link rel="stylesheet" href="./css/apache-maven-fluido-1.9.min.css" />
<link rel="stylesheet" href="./css/site.css" />
<link rel="stylesheet" href="./css/print.css" media="print" />
<script src="./js/apache-maven-fluido-1.9.min.js"></script>
</head>
<body class="topBarDisabled">
<div class="container-fluid">
<header>
<div id="banner">
<div class="pull-left"><a href="https://turbine.apache.org/" id="bannerLeft" title="Apache Turbine"><img src="https://turbine.apache.org/images/turbine-project.png" alt="Apache Turbine"/></a></div>
<div class="pull-right"></div>
<div class="clear"><hr/></div>
</div>
<div id="breadcrumbs">
<ul class="breadcrumb">
<li id="publishDate">Last Published: 14 September 2021<span class="divider">|</span>
</li>
<li id="projectVersion">Version: 1.0.8-SNAPSHOT</li>
<li class="pull-right"><span class="divider">|</span>
<a href="https://turbine.apache.org/fulcrum/" class="externalLink" title="Fulcrum">Fulcrum</a></li>
<li class="pull-right"><span class="divider">|</span>
<a href="https://turbine.apache.org/" class="externalLink" title="Turbine">Turbine</a></li>
<li class="pull-right"><a href="https://www.apache.org" class="externalLink" title="Apache">Apache</a></li>
</ul>
</div>
</header>
<div class="row-fluid">
<header id="leftColumn" class="span2">
<nav class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">Overview</li>
<li class="active"><a href="#"><span class="none"></span>Main</a></li>
<li class="nav-header">Project Documentation</li>
<li><a href="project-info.html" title="Project Information"><span class="icon-chevron-down"></span>Project Information</a>
<ul class="nav nav-list">
<li><a href="dependencies.html" title="Dependencies"><span class="none"></span>Dependencies</a></li>
<li><a href="dependency-info.html" title="Dependency Information"><span class="none"></span>Dependency Information</a></li>
<li><a href="distribution-management.html" title="Distribution Management"><span class="none"></span>Distribution Management</a></li>
<li class="active"><a href="#"><span class="none"></span>About</a></li>
<li><a href="issue-management.html" title="Issue Management"><span class="none"></span>Issue Management</a></li>
<li><a href="licenses.html" title="Licenses"><span class="none"></span>Licenses</a></li>
<li><a href="mailing-lists.html" title="Mailing Lists"><span class="none"></span>Mailing Lists</a></li>
<li><a href="plugin-management.html" title="Plugin Management"><span class="none"></span>Plugin Management</a></li>
<li><a href="plugins.html" title="Plugins"><span class="none"></span>Plugins</a></li>
<li><a href="scm.html" title="Source Code Management"><span class="none"></span>Source Code Management</a></li>
<li><a href="summary.html" title="Summary"><span class="none"></span>Summary</a></li>
<li><a href="team.html" title="Team"><span class="none"></span>Team</a></li>
</ul></li>
<li><a href="project-reports.html" title="Project Reports"><span class="icon-chevron-right"></span>Project Reports</a></li>
<li class="nav-header">Apache</li>
<li><a href="https://www.apache.org/" class="externalLink" title="Apache Website"><span class="none"></span>Apache Website</a></li>
<li><a href="https://www.apache.org/licenses/" class="externalLink" title="License"><span class="none"></span>License</a></li>
<li><a href="https://www.apache.org/foundation/how-it-works.html" class="externalLink" title="How the ASF works"><span class="none"></span>How the ASF works</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html" class="externalLink" title="Sponsorship"><span class="none"></span>Sponsorship</a></li>
<li><a href="https://www.apache.org/foundation/thanks.html" class="externalLink" title="Thanks"><span class="none"></span>Thanks</a></li>
<li><a href="https://www.apache.org/security/" class="externalLink" title="Security"><span class="none"></span>Security</a></li>
</ul>
</nav>
<div class="well sidebar-nav">
<hr />
<div id="poweredBy">
<div class="clear"></div>
<div class="clear"></div>
<div class="clear"></div>
<a href="http://maven.apache.org/" title="Built by Maven" class="poweredBy"><img class="builtBy" alt="Built by Maven" src="./images/logos/maven-feather.png" /></a>
</div>
</div>
</header>
<main id="bodyColumn" class="span10" >
<section>
<h2><a name="Overview"></a>Overview</h2>
<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
</p>
<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.
</section>
<section>
<h2><a name="SimpleLocalizationService"></a>SimpleLocalizationService</h2>
<section>
<h3><a name="Role_Configuration"></a>Role Configuration</h3>
<div class="source"><pre class="prettyprint">
&lt;role
name=&quot;org.apache.fulcrum.localization.SimpleLocalizationService&quot;
shorthand=&quot;localization&quot;
default-class=&quot;org.apache.fulcrum.localization.SimpleLocalizationServiceImpl&quot;/&gt;
</pre></div>
</section>
<section>
<h3><a name="Component_Configuration"></a>Component Configuration</h3>
<table border="0" class="table table-striped">
<tr class="a">
<th>Item</th>
<th>Datatype</th>
<th>Cardinality</th>
<th>Description</th>
</tr>
<tr class="b">
<td>localization@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 class="a">
<td>localization@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 class="b">
<td>bundles</td>
<td>Complex</td>
<td>[1]</td>
<td>
The list of configured bundles.
</td>
</tr>
<tr class="a">
<td>bundles/bundle</td>
<td>String</td>
<td>[1..n]</td>
<td>
The name of the bundle
</td>
</tr>
</table>
</section>
<section>
<h3><a name="Component_Configuration_Example"></a>Component Configuration Example</h3>
<div class="source"><pre class="prettyprint">
&lt;localization locale-default-language=&quot;en&quot; locale-default-country=&quot;US&quot;&gt;
&lt;bundles&gt;
&lt;bundle&gt;org.apache.fulcrum.localization.BarBundle&lt;/bundle&gt;
&lt;bundle&gt;org.apache.fulcrum.localization.FooBundle&lt;/bundle&gt;
&lt;/bundles&gt;
&lt;/localization&gt;
</pre></div>
</section>
</section>
<section>
<h2><a name="LocalizationService"></a>LocalizationService</h2>
<section>
<h3><a name="Role_Configuration"></a>Role Configuration</h3>
<div class="source"><pre class="prettyprint">
&lt;role
name=&quot;org.apache.fulcrum.localization.LocalizationService&quot;
shorthand=&quot;localization&quot;
default-class=&quot;org.apache.fulcrum.localization.DefaultLocalizationService&quot;/&gt;
</pre></div>
</section>
<section>
<h3><a name="Component_Configuration"></a>Component Configuration</h3>
<table border="0" class="table table-striped">
<tr class="a">
<th>Item</th>
<th>Datatype</th>
<th>Cardinality</th>
<th>Description</th>
</tr>
<tr class="b">
<td>localization@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 class="a">
<td>localization@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 class="b">
<td>bundles</td>
<td>Complex</td>
<td>[1]</td>
<td>
The list of configured bundles.
</td>
</tr>
<tr class="a">
<td>bundles/bundle</td>
<td>String</td>
<td>[1..n]</td>
<td>
The name of the bundle (first one is default bundle)
</td>
</tr>
</table>
</section>
<section>
<h3><a name="Component_Configuration_Example"></a>Component Configuration Example</h3>
<div class="source"><pre class="prettyprint">
&lt;localization locale-default-language=&quot;en&quot; locale-default-country=&quot;US&quot;&gt;
&lt;bundles&gt;
&lt;bundle&gt;org.apache.fulcrum.localization.BarBundle&lt;/bundle&gt;
&lt;bundle&gt;org.apache.fulcrum.localization.FooBundle&lt;/bundle&gt;
&lt;/bundles&gt;
&lt;/localization&gt;
</pre></div>
</section>
</section>
<section>
<h2><a name="Resource_Bundles"></a>Resource Bundles</h2>
<p>
Resource bundles are basically property files. You might have one for
the &quot;en&quot; locale thus:
</p>
<div class="source"><pre class="prettyprint">
LABEL_ORGANIZATION = organisation
CURRENT_RECORD = Record {0} of {1}
</pre></div>
<p>
and another for the &quot;en_US&quot; locale thus:
</p>
<div class="source"><pre class="prettyprint">
LABEL_ORGANIZATION = organization
</pre></div>
<p>
Please see the <i>java.util.ListResourceBundle</i> and
<i>java.util.ResourceBundle</i> classes for more information.
</p>
</section>
<section>
<h2><a name="Usage"></a>Usage</h2>
<div class="source"><pre class="prettyprint">
TurbineServices.getInstance().getService(LocalizationService.ROLE)
.getString(&quot;DISPLAYPROJECTS_TITLE&quot;);
</pre></div>
<p>
Wow. That is a lot of typing. In Turbine, that could be easily shortened to this:
</p>
<div class="source"><pre class="prettyprint">
Localization.getString(&quot;DISPLAYPROJECTS_TITLE&quot;);
</pre></div>
<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>
<div class="source"><pre class="prettyprint">
Localization.getString(data, &quot;DISPLAYPROJECTS_TITLE&quot;);
</pre></div>
<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>
<div class="source"><pre class="prettyprint">
Localization.format(Localization.getDefaultBundle(),
Localization.getLocale(data.getRequest()),
&quot;CURRENT_RECORD&quot;,
recno, all);
</pre></div>
<p>
This actually doesn't look too nice, however the call using the Turbine LocalizationTool
from a <a class="externalLink" href="http://velocity.apache.org/">Velocity</a> template just deflates to
</p>
<div class="source"><pre class="prettyprint">
$l10n.format(&quot;CURRENT_RECORD&quot;, $recno, $all);
## Other examples
## No arguments
$l10n.LABEL_ORGANIZATION
## One argument
$l10n.format(&quot;STRING_KEY_ONE_ARG&quot; &quot;arg1&quot;)
## Three or more arguments
$l10n.format(&quot;STRING_KEY_3_OR_MORE_ARGS&quot; [&quot;arg1&quot;, &quot;arg2&quot;, &quot;arg3&quot;])
</pre></div>
</section>
</main>
</div>
</div>
<hr/>
<footer>
<div class="container-fluid">
<div class="row-fluid">
<p>&#169; 2005&#x2013;2021
<a href="https://www.apache.org/">The Apache Software Foundation</a>
</p>
</div>
</div>
</footer>
</body>
</html>