Wiki source code of InternationalizingApplications
Version 4.6 by Philipp Roessler on 2009/09/02
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
1.1 | 1 | 1 Writing Internationalized XWiki Applications |
2 | |||
3 | #toc("" "" "") | ||
4 | |||
5 | 1.1 Using the static Resource Bundles | ||
6 | |||
![]() |
1.2 | 7 | * Stop your XWiki instance |
![]() |
4.1 | 8 | * Unjar the <tt>WEB-INF/lib/xwiki-core-\*.jar</tt> file (it was named <tt>xwiki.jar</tt> in old versions) in <tt>WEB-INF/classes</tt> and remove it from <tt>WEB-INF/lib</tt> |
9 | * Edit the <tt>WEB-INF/classes/ApplicationResources*.properties</tt> Resource Bundle files by adding the key/value pairs you need for your application. | ||
![]() |
1.2 | 10 | * In your document, use the following to get the value associated with a key: |
![]() |
1.1 | 11 | |
![]() |
1.2 | 12 | {code} |
![]() |
1.11 | 13 | $msg.get("key") |
![]() |
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 | |||
![]() |
1.1 | 18 | 1.1 Using properties located in XWiki pages |
19 | |||
![]() |
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.") |
![]() |
1.1 | 21 | |
![]() |
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 | ||
![]() |
1.12 | 28 | withparams=I can {0} pass {1} {2} params too using the Java MessageFormat syntax |
![]() |
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 | |||
![]() |
4.4 | 35 | * 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. |
![]() |
1.16 | 36 | |
![]() |
4.5 | 37 | #info("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") |
38 | |||
![]() |
4.1 | 39 | * Alternatively you can also specify the list of Internationalization Document Bundles in <tt>xwiki.cfg</tt> under the key <tt>xwiki.documentBundles</tt>. |
![]() |
1.16 | 40 | |
![]() |
1.2 | 41 | * On the page where you want to use the internationalized message, use: |
42 | |||
43 | {code} | ||
![]() |
1.12 | 44 | $msg.get("key") |
![]() |
1.16 | 45 | $msg.get("key", ["param1", "param2", ...]) |
![]() |
1.2 | 46 | {code} |
47 | |||
![]() |
4.1 | 48 | where <tt>key</tt> is the key for the message to retrieve. Parameters can also be passed as is shown in the second syntax above. |
![]() |
1.16 | 49 | |
![]() |
4.3 | 50 | 1.1 I18n of XWiki objects |
51 | |||
52 | This is impossible to have different objects for different page translations for now. | ||
53 | However, you can emulate it. | ||
54 | |||
55 | A possible solution is to have one object per language and add a language property in the objects. | ||
56 | So you can filter objects by language in a page. | ||
57 |