User macro displayed content depending on language
Hi,
is it somehow possible to write a user macro, which displays different content in dependance of the chosen language? For example to display a header like "Inhalt", "Contents", "Contenu" etc. within the title of a panel maro. We don't want to write a user macro for every language which has to be changed while translating. There should be only one macro. We also do not want to translate this static headers on every page.
It is possible to use a variable in the title parameter of the panel macro, and it is also possible to display some content but for some reason it is not possible to do something like this:
1. Create a page with translated (static) content.
2. Create a user macro "include_content" which only includes this content (per include-macro).
3. Call this macro in a user macro and assign it to a variable.
#set ($title = $action.getHelper().renderConfluenceMacro("{include_content}"))
4. Use this variable in the title-parameter of panel macro
...<ac:parameter ac:name="title">$title</ac:parameter>...
-> macro error
Thanks,
Volker
-
Hi Volker.
Technically translations created with Scroll Translations are all stored on the same page; each translation is wrapped in a special macro (SV translations macro). If the macro can't be found on a page, Scroll Translations marks this page to not be translated.
You need to put the output of your macro into a sv-translation macro for the current language. Unfortunately, there is no way to get the current language within the user macro, so you have to have a sv-translataion macro for each language in the space, like the following (where you need to change the languageKey, and the content to be displayed):
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">{languageKey}</ac:parameter><ac:rich-text-body>
{content to be displayed}
</ac:rich-text-body></ac:structured-macro>
The best would probably be to have a copy the user macro for spaces with Scroll Translations, in which a sv-translation macro is added for each language you are using.
Here is an example of a user macro that prints "Content in English" when added in English (United States) and "Content in French" when added to French (France):## @noparams
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">en_US</ac:parameter><ac:rich-text-body>
Content in English
</ac:rich-text-body></ac:structured-macro>
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">fr_FR</ac:parameter><ac:rich-text-body>
Content in French
</ac:rich-text-body></ac:structured-macro>
Hope this helps.Roman.
Please sign in to leave a comment.
Comments
2 comments