Last modified by Vincent Massol on 2017/09/05

Hide last authors
Vincent Massol 8.1 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
Sorin Burjan 1.1 4
Vincent Massol 8.1 5 There are multiple ways you can integrate translation in XWiki. If you are a web developer which builds custom applications on top of XWiki, you certainly tried to create pages that contain multiple translations.
Sorin Burjan 1.1 6
Vincent Massol 8.1 7 In order to facilitate these tasks, here is a tutorial which uses the best practices for achieving the following goals:
Manuel Smeria 8.2 8
Vincent Massol 8.1 9 * The first section shows how to create properly a small inline form.
10 * The second section shows you how to add translations in Romanian language to that form in the proper and recommended way. If you are interested only on the translations tutorial, you can skip the first section.
Sorin Burjan 1.1 11
Vincent Massol 8.1 12 = Step 1: Creating the XWiki Class =
Sorin Burjan 1.1 13
Manuel Smeria 8.2 14 * Create a page called **MyCoolClass.** This will hold the definition of the class.
15 * Add the following fields:
Sorin Burjan 1.1 16 * name of Type String
17 * Fill the Pretty Name field with "Your Name"
18 [[image:addNameProprety.png]]
19
20 * street of Type String
21 * Fill the Pretty Name field with "Your Street Name"
22 [[image:addStreetProprety.png]]
23
24 * favColor of Type Static List
25 * Fill the Pretty Name with Favourite Color
26 * Fill the Values field with "red|blue|green|yellow"
27 [[image:addFavColorProprety.png]]
28
Vincent Massol 10.1 29 * edit the document in wiki mode and add the following line:(((
Sorin Burjan 1.1 30 {{code}}
31 {{include document="XWiki.ClassSheet"/}}
32 {{/code}}
Manuel Smeria 8.2 33 )))
34 * Click on the "Save & View" button
Sorin Burjan 1.1 35
Vincent Massol 8.1 36 = Step 2: Creating the XWiki Sheet =
Sorin Burjan 1.1 37
38 * Create a page called **MyCoolSheet**
Vincent Massol 10.1 39 * Edit the page in wiki mode and add the following(((
Sorin Burjan 1.1 40 {{code}}
41 {{velocity}}
42 {{html}}
43 <dl><dt><label>$doc.displayPrettyName('name', false, false)</label></dt>
44 <dd>$doc.display('name')</dd>
45 </dl>
46
47
48 <dl><dt><label>$doc.displayPrettyName('street', false, false)</label></dt>
49 <dd>$doc.display('street')</dd>
50 </dl>
51
52 <dl><dt><label>$doc.displayPrettyName('favColor', false, false)</label></dt>
53 <dd>$doc.display('favColor')</dd>
54 </dl>
55 {{/html}}
56 {{/velocity}}
57 {{/code}}
Manuel Smeria 8.2 58 )))
59 * Add a new class of type ##XWiki.SheetClass## and set its only property to "inline".
60 * Click on the "Save & View" button
Sorin Burjan 1.1 61
Vincent Massol 8.1 62 = Step 3: Creating the XWiki Template =
Sorin Burjan 1.1 63
64 * Create a page called **MyCoolTemplate**
Vincent Massol 10.1 65 * Edit the page in wiki mode and add the following line:(((
Sorin Burjan 1.1 66 {{code}}
67 {{include document="MyCoolSheet"/}}
68 {{/code}}
Manuel Smeria 8.2 69 )))
70 * Click on the "Save & View" button
Sorin Burjan 1.1 71
Vincent Massol 8.1 72 = Step 4: Internationalizing the display =
Sorin Burjan 1.1 73
Manuel Smeria 8.2 74 Before being able to add translations, XWiki must be set to support multiple languages:
Sorin Burjan 1.1 75
Manuel Smeria 8.2 76 * Go to the administration section of the wiki
77 ** Click on "Localization"
78 ** Set Multilingual to yes
79 ** in the "Supported Languages" field add the languages you want your wiki to support in this format: "fr, en, ro" (without the quotes)
80 ** Click the "Save" button
81 * Create a page called **MyCoolTranslations**; this page will hold the translations to other languages other than the default one.
82 * Open the page in Wiki mode, and on the Document Translations panel from the right side of the page, click the "ro" button; now we will add the translation for the Romanian language.
Sorin Burjan 1.1 83 [[image:MyCoolTranslationsAddTranslations.png]]
Vincent Massol 10.1 84 * Insert this text into the content:(((
Manuel Smeria 8.2 85 {{code}}
Sorin Burjan 1.1 86 Main.MyCoolClass_name=Numele Tau
87 Main.MyCoolClass_street=Numele Strazii
88 Main.MyCoolClass_favColor=Culoarea Preferata
Manuel Smeria 8.2 89
90 Main.MyCoolClass_favColor_red=Rosu
Sorin Burjan 1.1 91 Main.MyCoolClass_favColor_green=Verde
92 Main.MyCoolClass_favColor_blue=Albastru
93 Main.MyCoolClass_favColor_yellow=Galben
Manuel Smeria 8.2 94 {{/code}}
Sorin Burjan 1.1 95 )))
Manuel Smeria 8.2 96 * The rule for creating translation keys is the following:
Sorin Burjan 1.1 97 ** For class proprieties : spacename.classname + _ + property name
Marius Dumitru Florea 9.1 98 ** For static lists and boolean properties : spacename.classname + _ + property name + _ + property value(((
99 Note that for boolean properties the possible values are 0 (=false), 1 (=true) and 2 (=undecided). E.g. SomeSpace.SomeClass_enabled_0=Disabled
100 )))
Manuel Smeria 8.2 101 * Click on the "Save & View" button
102 * To test your translation, append **?language=ro** to your URL. For a better comparison you can see the English and the Romanian versions below.
103 * For example, if your are using your xwiki on localhost use the following URLs:
104 ** English version: http://localhost:8080/xwiki/bin/view/Main/MyCoolTemplate or http://localhost:8080/xwiki/bin/view/Main/MyCoolTemplate?language=en
105 ** Romanian version: http://localhost:8080/xwiki/bin/view/Main/MyCoolTemplate?language=ro
Sorin Burjan 1.1 106
Manuel Smeria 8.2 107 * English Version:
Sorin Burjan 1.1 108 [[image:MyCoolTemplateENView.png]]
109
Manuel Smeria 8.2 110 * Romanian Version:
Vincent Massol 10.1 111 [[image:MyCoolTemplateROView.png]](((
Sorin Burjan 1.1 112 {{warning}}
Manuel Smeria 8.2 113 Only the Translation document needs to have translations. The class, sheet, template and instance pages don't need to be translated; the localized messages will automatically be displayed in the selected language.
Sorin Burjan 1.1 114 {{/warning}}
Manuel Smeria 8.2 115 )))

Get Connected