Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
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.
6
7 In order to facilitate these tasks, here is a tutorial which uses the best practices for achieving the following goals:
8
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.
11
12 = Step 1: Creating the XWiki Class =
13
14 * Create a page called **MyCoolClass.** This will hold the definition of the class.
15 * Add the following fields:
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
29 * edit the document in wiki mode and add the following line:(((
30 {{code}}
31 {{include document="XWiki.ClassSheet"/}}
32 {{/code}}
33 )))
34 * Click on the "Save & View" button
35
36 = Step 2: Creating the XWiki Sheet =
37
38 * Create a page called **MyCoolSheet**
39 * Edit the page in wiki mode and add the following(((
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}}
58 )))
59 * Add a new class of type ##XWiki.SheetClass## and set its only property to "inline".
60 * Click on the "Save & View" button
61
62 = Step 3: Creating the XWiki Template =
63
64 * Create a page called **MyCoolTemplate**
65 * Edit the page in wiki mode and add the following line:(((
66 {{code}}
67 {{include document="MyCoolSheet"/}}
68 {{/code}}
69 )))
70 * Click on the "Save & View" button
71
72 = Step 4: Internationalizing the display =
73
74 Before being able to add translations, XWiki must be set to support multiple languages:
75
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.
83 [[image:MyCoolTranslationsAddTranslations.png]]
84 * Insert this text into the content:(((
85 {{code}}
86 Main.MyCoolClass_name=Numele Tau
87 Main.MyCoolClass_street=Numele Strazii
88 Main.MyCoolClass_favColor=Culoarea Preferata
89
90 Main.MyCoolClass_favColor_red=Rosu
91 Main.MyCoolClass_favColor_green=Verde
92 Main.MyCoolClass_favColor_blue=Albastru
93 Main.MyCoolClass_favColor_yellow=Galben
94 {{/code}}
95 )))
96 * The rule for creating translation keys is the following:
97 ** For class proprieties : spacename.classname + _ + property name
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 )))
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
106
107 * English Version:
108 [[image:MyCoolTemplateENView.png]]
109
110 * Romanian Version:
111 [[image:MyCoolTemplateROView.png]](((
112 {{warning}}
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.
114 {{/warning}}
115 )))

Get Connected