Translate a Wiki Macro

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

Steps

Translate the name, the description and the parameter labels of a wiki macro so the editor displays them in the reader's interface language.

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.

  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.
    Warning

    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.

  2. 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:
    KeyTranslates
    rendering.macro.<macro id>.nameThe name the macro is listed under in the editor's macro picker.
    rendering.macro.<macro id>.descriptionThe description displayed under that name, and at the top of the "Edit Macro" dialog.
    rendering.macro.<macro id>.parameter.<parameter name>.nameThe label of that parameter's field in the "Edit Macro" dialog.
    rendering.macro.<macro id>.parameter.<parameter name>.descriptionThe help text displayed under that field.
    rendering.macro.<macro id>.content.descriptionThe help text displayed under the macro's "Content" field.
  3. 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 is:
    rendering.macro.hello.name=Macro pour dire bonjour
    rendering.macro.hello.description=Salue la personne qui lit la page
    rendering.macro.hello.parameter.greetUser.name=Personnaliser le message
    rendering.macro.hello.parameter.greetUser.description=Saluer par son nom la personne connectée
    rendering.macro.hello.content.description=Le texte affiché après la salutation
  4. 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:

    The editor's macro picker in French, listing the hello macro as Macro pour dire bonjour with its translated description

FAQ

Can I translate a macro I did not write?

Yes. The translations live in a page of your own and nothing on the macro page changes, so what you need is the right the "Scope" of that page calls for, not access to the macro.

Why is my macro still displayed under its untranslated name?

Most often because the translation document does not reach the page you are editing. Its "Scope" has to match the macro's visibility, and the key has to use the macro id, not its name.

Related

Get Connected