Version 7.1 by Thomas Mortagne on 2010/04/20

Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = Using the static Resource Bundles =
6
7 * Stop your XWiki instance
8 * Unjar the ##WEB-INF/lib/xwiki-core-*.jar## file (it was named ##xwiki.jar## in old versions) in ##WEB-INF/classes## and remove it from ##WEB-INF/lib##
9 * Edit the ##WEB-INF/classes/ApplicationResources*.properties## Resource Bundle files by adding the key/value pairs you need for your application.
10 * In your document, use the following to get the value associated with a key:(((
11 {{code language="none"}}
12 $msg.get("key")
13 {{/code}}
14
15 This will get the value from the Resource Bundle corresponding to the current language you are using in XWiki.
16 )))
17
18 = Using properties located in XWiki pages =
19
20 {{warning}}
21 The features described below are only available in XWiki 1.0 Beta 4 and above. The ability to parametrize the resource string is available only in XWiki 1.0 Beta 5 and above.
22 {{/warning}}
23
24 * Create a page that will host your key/value pairs.
25 * Enter all the key/value pairs in that page ({{warning}}use the wiki editor{{/warning}}). For example:(((
26 {{code language="none"}}
27 greeting=hello
28 welcome=Welcome
29 withparams=I can {0} pass {1} {2} params too using the Java MessageFormat syntax
30 {{/code}}
31 )))
32 * Do the same for all the translations you want.(((
33 {{info}}
34 To enable multiple languages you'll need to go to the Administration page and set MultiLingual to true and list the different languages you wish to use in the Languages field.
35 {{/info}}
36 )))
37 * Tell XWiki that your page is a Document Bundle by going to the Administration page, selecting the "Programming" icon and entering it in the "Internationalization Document Bundles" field. You can specify several pages, separated by commas.(((
38 {{info}}
39 When creating "Internationalization Document Bundles", you should avoid naming the pages with names that include spaces. For example, a document name of Main.My Messages could cause issues, instead, use Main.MyMessages
40 {{/info}}
41 )))
42 * Alternatively you can also specify the list of Internationalization Document Bundles in ##xwiki.cfg## under the key ##xwiki.documentBundles##.
43 * On the page where you want to use the internationalized message, use:(((
44 {{code}}
45 $msg.get("key")
46 $msg.get("key", ["param1", "param2", ...])
47 {{/code}}
48
49 where ##key## is the key for the message to retrieve. Parameters can also be passed as is shown in the second syntax above.
50 )))
51
52 = I18n of XWiki Objects =
53
54 This is currently not implemented (see our logged issue: [[XWIKI-69>>http://jira.xwiki.org/jira/browse/XWIKI-69]]). There are 2 workarounds you can use:
55
56 * Have several objects, one for each language, with a language field, and then decide which object to use (for example in a Class Sheet, based on the current language).
57 * Use Velocity scripting to do an IF in your object. For example, you could have:(((
58 {{code language="none"}}
59 #if ($context.language == "fr")
60 French texts
61 #else
62 Default texts
63 #end
64 {{/code}}
65 )))

Get Connected