Wiki source code of Localization Component

Last modified by Vincent Massol on 2024/11/19 16:12

Show last authors
1 The localization tool provides translations to java code, by using it as any other component, and to velocity, by placing a ##$msg## variable in the velocity context.
2
3 API methods:
4
5 (% style="list-style-type: square" %)
6 * ##$msg.useDocumentBundle("Some.Document")## - pulls a wiki document bundle in the current execution context. It will be available until the current request completes. Useful for wiki applications.
7 * ##$msg.useFileBundle("path/to/Resources")## - pulls a file bundle in the current execution context, actually a resource bundle like ##ApplicationResources.properties##. It will be available until the current request completes. Useful for plugins/components.
8 * ##$msg.get("key")## - Works like the already existing method.
9 * ##$msg.get("key", ["param1" ...])## - Works like the already existing method.
10
11 Besides the pulled bundles, the tool also uses:
12
13 (% style="list-style-type: square" %)
14 * a list of global document bundles, configured in XWikiPreferences
15 * a static list of document bundles configured in components.xml
16 * a static list of file bundles configured in components,xml
17
18 The order in which the tool searches for a translation is:
19
20 1. pulled document bundles, in the order of their call.
21 1. pulled file bundles, in the order of their call.
22 1. global document bundles
23 1. static document bundles
24 1. static file bundles
25
26 Execution details and improvements over the current message tool:
27
28 (% style="list-style-type: square" %)
29 * singleton instance that relies on the execution context to store the lists of pulled bundles and to get the current language, instead of per-request instances
30 * all loaded bundles are cached for all further request, instead of only for the current request
31 * cached bundles are invalidated using the observation mechanism, instead of keeping a list of modification dates
32 * bundles are loaded only when really needed, i.e. when a request for a key was not found in the previous bundles
33 * only the bundle in the current context language is loaded (same as now)
34 * for each language, the bundle inherits the default language definitions, instead of loading two different bundles and searching them in order
35 * the default language is the one configured in the wiki (same as now)

Get Connected