Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 = Tutorials =
6
7 * [[Tutorial for Internationalizing a Form>>Documentation.DevGuide.Tutorials.TranslationsTutorial.WebHome]]
8
9 = Using properties located in XWiki pages =
10
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}}
18
19 NB: the Java MessageFormat syntax is described in the [[MessageFormat Javadoc>>https://docs.oracle.com/javase/7/docs/api/java/text/MessageFormat.html]]. 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 * Do the same for all the translations you want.(((
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:
29
30 {{code}}
31 {{translation key="key"/}}
32 {{/code}}
33
34 From Script (Velocity in this example):
35
36 {{code}}
37 $services.localization.render("key")
38 $services.localization.render("key", ["param1", "param2", ...])
39 {{/code}}
40
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 )))
43
44 == Old way ==
45
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.
47
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}}
51
52 Alternatively you could also specify the list of Internationalization Document Bundles in ##xwiki.cfg## under the key ##xwiki.documentBundles##.
53
54 = I18n of XWiki Objects =
55
56 This is currently not implemented (see our logged issue: [[XWIKI-69>>https://jira.xwiki.org/browse/XWIKI-69]]). There are 2 workarounds you can use:
57
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 )))
73
74 = I18n of XWiki Macros =
75
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]].
78
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
82
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}}
86
87 = Using the static Resource Bundles =
88
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}}
93
94 This will get the value from the Resource Bundle corresponding to the current language you are using in XWiki.
95
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