Wiki source code of Translate a Wiki Macro

Last modified by Eleni Cojocariu on 2026/10/12 13:22

Hide last authors
Eleni Cojocariu 3.1 1 Translate the name, the description and the parameter labels of a [[wiki macro>>doc:documentation.xs.dev.rendering-macros.wiki-macros.WebHome]] so the editor displays them in the reader's interface language.
2
3 The macro itself is not modified. The translations are matched to it by the **name of the keys**, which carry the macro id, and they are written in a translation document like any other translation, see [[Writing Internationalized XWiki Applications>>doc:Documentation.DevGuide.Tutorials.InternationalizingApplications.WebHome]].
4
5 1. Create a page to hold the translations, add an object of type ##XWiki.TranslationDocumentClass## to it in the object editor, and set its "Scope" to the value that matches the macro's visibility: ##GLOBAL## for a ##Global## macro, ##WIKI## for a ##Current Wiki## macro, ##USER## for a ##Current User## macro. (((
6 {{warning}}
7 A translation document narrower than the macro only reaches part of the pages the macro can be called from, and the macro keeps its untranslated name everywhere else. Each scope requires the rights the matching visibility requires, see [[Wiki Macros>>doc:documentation.xs.dev.rendering-macros.wiki-macros.WebHome]].
8 {{/warning}}
9 )))
10 1. Write the keys in the content of that page, one ##key=value## pair per line, with the values in the language the page itself is written in. ##<macro id>## is the "Macro id" field of the macro, ##<parameter name>## the "Parameter name" field of one of its parameters: (((
11 |=Key|=Translates
12 |##rendering.macro.<macro id>.name##|The name the macro is listed under in the editor's macro picker.
13 |##rendering.macro.<macro id>.description##|The description displayed under that name, and at the top of the "Edit Macro" dialog.
14 |##rendering.macro.<macro id>.parameter.<parameter name>.name##|The label of that parameter's field in the "Edit Macro" dialog.
15 |##rendering.macro.<macro id>.parameter.<parameter name>.description##|The help text displayed under that field.
16 |##rendering.macro.<macro id>.content.description##|The help text displayed under the macro's "Content" field.
17 )))
18 1. Translate that page into every language you support, and write the values of that language in the translation. The French translation of the ##hello## macro built in [[Write a Macro in a Wiki Page>>doc:documentation.xs.dev.rendering-macros.wiki-macros.write-wiki-macro.WebHome]] is: (((
19 {{code language="properties"}}
20 rendering.macro.hello.name=Macro pour dire bonjour
21 rendering.macro.hello.description=Salue la personne qui lit la page
22 rendering.macro.hello.parameter.greetUser.name=Personnaliser le message
23 rendering.macro.hello.parameter.greetUser.description=Saluer par son nom la personne connectée
24 rendering.macro.hello.content.description=Le texte affiché après la salutation
25 {{/code}}
26 )))
27 1. Save, then open any page in the WYSIWYG editor with the interface in that language. The macro picker lists the macro under its translated name and description, and the "Edit Macro" dialog labels its parameters with theirs: (((
Eleni Cojocariu 8.1 28 {{image reference="translated-macro-picker.png" size="large" alt="The editor's macro picker in French, listing the hello macro as Macro pour dire bonjour with its translated description"/}}
Eleni Cojocariu 3.1 29 )))

Get Connected