Scroll Translations: How can I refer to the language key in a user macro written with Velocity
Hi,
I hope someone can help me with the following user macro:
I wrote a user macro that is able to interpret the language key of the sv-translation macro and to put the right quotation marks around the body (ui elements) depending on the language.
## @noparams
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">de</ac:parameter><ac:rich-text-body>„$body“</ac:rich-text-body></ac:structured-macro>
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">en</ac:parameter><ac:rich-text-body>“$body”</ac:rich-text-body></ac:structured-macro>
<ac:structured-macro ac:name="sv-translation" ac:schema-version="1"><ac:parameter ac:name="language">fr</ac:parameter><ac:rich-text-body>« $body »</ac:rich-text-body></ac:structured-macro>
Maybe there are easier ways but that works for me.
In a next step, I would like to write a new user macro for menu paths in the style like:
"File" > "Reports" > "Daily"
So far I have managed to add the quotation marks und the greater than sign and to differ between two and three menu items.
## @param Menu1:title=Menu 1|type=string|required=true
## @param Menu2:title=Menu 2|type=string|required=true
## @param Menu3:title=Menu 3|type=string|required=false
#set( $template_1 = "„$paramMenu1“ > „$paramMenu2“")
#set( $template_2 = "„$paramMenu1“ > „$paramMenu2“ > „$paramMenu3“")
#set( $template_1 = "“$paramMenu1” > “$paramMenu2”")
#set( $template_2 = "“$paramMenu1” > “$paramMenu2” > “$paramMenu3”")
#if( $paramMenu3)
$template_2
#else
$template_1
#end
But now I do not know how I can add the language key part into this macro so the macro automatically uses the right quotation marks depending on the language.
It would be great if anyone had an idea how I can refer to the language key using Velocity or how I could apply the sv-translation macro to my use case.
Thanks for any help and ideas in advance,
Nicole
-
Hello,
I have been trying the following JavaScript:
<SCRIPT type="text/javascript">
var element = document.getElementById('main-content').innerHTML=Scroll.Versions.Context.user.currentLanguage.toString();
</SCRIPT>
The script returns [object Object]. So it seems to me as if I am accessing the right thing but I do not know how to return the language.
Can anyone help?
Cheers,
Nicole
-
Nicole Fischer you can access this javascript object with this code:
var scroll = Scroll;
if(scroll != null) {
var scrollLanguage = Scroll.Versions.Context.user.currentLanguage;
var languageKey = scrollLanguage.key; // returns e.g. "en"
var languageName = scrollLanguage.displayName; // returns e.g. "English"
}Return Value of Scroll.Versions.Context.user.currentLanguage
{
displayName: "English"
encodedKey: "en"
isOriginal: false
key: "en"
}
Please sign in to leave a comment.
Comments
5 comments