Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Internationalization support of the Web Console is based on Java Resource Bundles loaded from the plugin bundles and is transparent to the plugin itself. In addition to localization the mechanism described here can also be used for generic templating of Web Console responses.

Basic Mechanism

All requests handled by web console plugins are wrapped by response wrapper, which installs a Writer filter if the response is a text/html response. This writer filter recognizes variables of the pattern ${name} and tries to replace that part of the output with another string:

  • If a variable of that name exists, the value of that variable is used. See Variable Resolution below.
  • Otherwise if a resource bundle provides a translated string for the name, that string is used. See Resource Bundles below.
  • Otherwise the name itself is just placed in the output.

Variable Resolution

Variable Resolution is based on a org.apache.felix.webconsole.VariableResolver object provided as a request attribute prior to calling the ServletResponse.getWriter() method. If no such resolver is provided in the request, an instance of the org.apache.felix.webconsole.DefaultVariableResolver is used and stored in the request. Replacing the VariableResolver after the getWriter() has been called has no effect for variable resolution. Variables may be added to the VariableResolver even after the getWriter() method has been called.

Resource Bundles

Resources for the Resource Bundles is provided by the Web Console bundle on the one hand and by the bundle providing the plugin on the other hand. Resources are identified inside a bundle with the Bundle-Localization manifest header as described in Section 3.10 Localization in the Core Specification.

...

During request processing the Locale of the request (ServletRequest.getLocale()) is used to identify the actual resources to use. From this information a ResourceBundle is constructed from a collection of the resources provided by the plugin bundle and the resources provided by the Web Console.

Web Console Localization

The Web Console contains a single localization file OSGI-INF/l10n/bundle.properties. Fragments attached to the Web Console bundle may provide translations for these resources. All plugins of the Web Console itself will use a ReosurceBundle, which is only based on the localization of the Web Console itself.

Using Templating