Wiki source code of InternationalizingApplications

Version 1.16 by Vincent Massol on 2007/11/21

Hide last authors
Vincent Massol 1.1 1 1 Writing Internationalized XWiki Applications
2
3 #toc("" "" "")
4
5 1.1 Using the static Resource Bundles
6
Vincent Massol 1.2 7 * Stop your XWiki instance
Vincent Massol 1.16 8 * Unjar the ~~WEB-INF/lib/xwiki-core-\*.jar~~ file 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.
Vincent Massol 1.2 10 * In your document, use the following to get the value associated with a key:
Vincent Massol 1.1 11
Vincent Massol 1.2 12 {code}
Vincent Massol 1.11 13 $msg.get("key")
Vincent Massol 1.2 14 {code}
15
16 This will get the value from the Resource Bundle corresponding to the current language you are using in XWiki.
17
Vincent Massol 1.1 18 1.1 Using properties located in XWiki pages
19
Vincent Massol 1.5 20 #warning("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.")
Vincent Massol 1.1 21
Vincent Massol 1.2 22 * Create a page that will host your key/value pairs.
23 * Enter all the key/value pairs in that page (use the wiki editor). For example:
24
25 {code}
26 greeting=hello
27 welcome=Welcome
Vincent Massol 1.12 28 withparams=I can {0} pass {1} {2} params too using the Java MessageFormat syntax
Vincent Massol 1.2 29 {code}
30
31 * Do the same for all the translations you want.
32
33 #info("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.")
34
35 * Tell XWiki that your page is a Document Bundle by going to the Administration page, selecting the Advanced tab and entering it in the "Internationalization Document Bundles" field. You can specify several pages, separated by commas.
Vincent Massol 1.16 36
Vincent Massol 1.8 37 * Alternatively you can also specify the list of Internationalization Document Bundles in ~~xwiki.cfg~~ under the key ~~xwiki.documentBundles~~.
Vincent Massol 1.16 38
Vincent Massol 1.2 39 * On the page where you want to use the internationalized message, use:
40
41 {code}
Vincent Massol 1.12 42 $msg.get("key")
Vincent Massol 1.16 43 $msg.get("key", ["param1", "param2", ...])
Vincent Massol 1.2 44 {code}
45
Vincent Massol 1.5 46 where ~~key~~ is the key for the message to retrieve. Parameters can also be passed as is shown in the second syntax above.
Vincent Massol 1.16 47

Get Connected