Writing Internationalized XWiki Applications
Version 8.2 by Sorin Burjan on 2011/03/30
Contents
Using the static Resource Bundles
- Stop your XWiki instance
- 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
- Edit the WEB-INF/classes/ApplicationResources*.properties Resource Bundle files by adding the key/value pairs you need for your application.
- In your document, use the following to get the value associated with a key:$msg.get("key")
This will get the value from the Resource Bundle corresponding to the current language you are using in XWiki.
For a full tutorial on how to do translations, please click here.
Using properties located in XWiki pages
- Create a page that will host your key/value pairs.
- Enter all the key/value pairs in that page (greeting=hello
welcome=Welcome
withparams=I can {0} pass {1} {2} params too using the Java MessageFormat syntax ). For example: - Do the same for all the translations you want.
- 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.
- Alternatively you can also specify the list of Internationalization Document Bundles in xwiki.cfg under the key xwiki.documentBundles.
- On the page where you want to use the internationalized message, use:$msg.get("key")
$msg.get("key", ["param1", "param2", ...])where key is the key for the message to retrieve. Parameters can also be passed as is shown in the second syntax above.
I18n of XWiki Objects
This is currently not implemented (see our logged issue: XWIKI-69). There are 2 workarounds you can use:
- 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):$doc.getObject('Your.Class', 'lang', $context.language')
## Will select the object whose 'lang' property is set to the current language - Use Velocity scripting to do an IF in your object. For example, you could have:#if ($context.language == "fr")
French texts
#else
Default texts
#end