Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
5 = Tutorials =
7 * [[Tutorial for Internationalizing a Form>>Documentation.DevGuide.Tutorials.TranslationsTutorial.WebHome]]
9 = Using properties located in XWiki pages =
11 * Create a page that will host your key/value pairs
12 * Enter all the key/value pairs in that page ({{warning}}use the wiki editor{{/warning}}). For example:(((
13 {{code language="none"}}
14 greeting=hello
15 welcome=Welcome
16 withparams=I can {0} pass {1} {2} params too using the Java MessageFormat syntax
17 {{/code}}
19 NB: the Java MessageFormat syntax is described in the [[MessageFormat Javadoc>>]]. There's in particular an important peculiarity for messages with parameters: single quotes need to be doubled to show up in the translated string, which is not the case for messages that are not parameterized.
20 )))
21 * While editing this page in wiki mode, you will be able to translate it in other languages by clicking on languages next to "Translate this page in" in the "Page Translations" sections of the right panel.(((
22 {{info}}
23 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.
24 {{/info}}
25 )))
26 * Tell XWiki that your page is a Translation page by adding an Object of type ##TranslationDocumentClass## to your page.
27 * On the page where you want to use use either the ##~{~{translation}}## macro or the Localization Script Service (check the document for the [[Localization module>>extensions:Extension.Localization Module]]). Quick examples:(((
28 From wiki syntax:
30 {{code}}
31 {{translation key="key"/}}
32 {{/code}}
34 From Script (Velocity in this example):
36 {{code}}
37 $services.localization.render("key")
38 $services.localization.render("key", ["param1", "param2", ...])
39 {{/code}}
41 where ##key## is the key for the message to retrieve. Parameters can also be passed as is shown in the second syntax above. Beware the parameters need to be passed as an array, not a plain String even if there's only one parameter: {{code}}$services.localization.render("key", ["param1"]){{/code}}.
42 )))
44 == Old way ==
46 Prior to XWiki 4.3, the way to register a Document Resource Bundle was by going to the Administration page, selecting the "Localization" section and entering it in the "Internationalization Document Bundles" field. You could specify several pages, separated by commas.
48 {{info}}
49 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
50 {{/info}}
52 Alternatively you could also specify the list of Internationalization Document Bundles in ##xwiki.cfg## under the key ##xwiki.documentBundles##.
54 = I18n of XWiki Objects =
56 This is currently not implemented (see our logged issue: [[XWIKI-69>>]]). There are 2 workarounds you can use:
58 * 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):(((
59 {{code language="none"}}
60 $doc.getObject('Your.Class', 'lang', $context.language')
61 ## Will select the object whose 'lang' property is set to the current language
62 {{/code}}
63 )))
64 * Use Velocity scripting to do an IF in your object. For example, you could have:(((
65 {{code language="none"}}
66 #if ($context.language == "fr")
67 French texts
68 #else
69 Default texts
70 #end
71 {{/code}}
72 )))
74 = I18n of XWiki Macros =
76 To internationalize macros, the keys below can be added to the Translation document as [[presented above>>#HUsingpropertieslocatedinXWikipages]].
77 A concrete example is presented in the [[Macro Tutorial>>Documentation.DevGuide.Tutorials.WritingMacros.WikiMacroTutorial]].
79 {{code}}
80 rendering.macro.<macro id>.name=Name of the macro, displayed in the macros list in the macros wizard
81 rendering.macro.<macro id>.description=Description of the macro, displayed as a help in the macros list in the macros wizard
83 rendering.macro.<macro id>.parameter.<parameter name>.name=Name of the macro parameter, to be displayed in the form for the macro settings in the macros wizard
84 rendering.macro.<macro id>.parameter.<parameter name>.description=Description of the macro parameter, to be displayed as a help in the form for the macro settings in the macros wizard
85 {{/code}}
87 = Using the static Resource Bundles =
89 * Stop your XWiki instance
90 * Extract the ##ApplicationResources*.properties## file for your language from the ##WEB-INF/lib/xwiki-*oldcore-*.jar## file and put them in your ##WEB-INF/classes## directory
91 * Edit this file and add/modify the key/value pairs you need for your application
92 * In your document, use the following to get the value associated with a key: {{code language="none"}}$services.localization.render("key"){{/code}}
94 This will get the value from the Resource Bundle corresponding to the current language you are using in XWiki.
96 If you're writing an extension JAR and wish to have static translation resources, you can put them in a ##ApplicationResources*.properties## file at the root of your extension JAR and they'll get picked up by the Localization module. See the [[Localization module>>extensions:Extension.Localization Module#HProvidetranslationbundleinajar]] for more details.

Get Connected