-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranslate.vtl
48 lines (48 loc) · 2.15 KB
/
translate.vtl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#*
ADD/CREATE A TRANSLATION
@use #addTranslation($country $atText $atVarName $atLangVar)
$atCtry => (required) "FR" (or any TWO LETTER country code)
$atVarName => (optional, but strongly recommended) for custom var name (for use with translate)
$atText => (required) "String of atText to translate"
$atLangVar => (optional) dotCMS lang var (glossary term) to look up
*#
#macro( addTranslation $atCtry $atVarName $atText $atLangVar )##
#if( $UtilMethods.isSet($atCtry) && $UtilMethods.isSet($atText) && $UtilMethods.isSet($atVarName) )##
## DYNAMICALLY CREATE THE COUNTRY SPECIFIC LANGUAGE VARIABLE (name)
#if( $UtilMethods.isSet($atVarName) && $atVarName != false )##
#set( $_langVarName = "${atCtry.toUpperCase()}_${atVarName.toLowerCase()}" )##
#else##
#set( $_langVarName = "${atCtry.toUpperCase()}_${atText.toLowerCase()}" )##
#end##
## CHECK THAT COUNTRY IS TWO LETTER CODE (LIKE FR, US, UK, NL, JP, FR, AU)
#if( $atCtry.length() != 2 )##
<!-- M: The country endered (${country}) is not valid for the atText "${atText}" -->
#else##
## LOOK UP DICTIONARY DEFINITION?
#if( $UtilMethods.isSet($!context.get($atLangVar)) && $!UtilMethods.isSet($!languageVariables.get($atLangVar)) )##
#set( $_dummy = $context.put($_langVarName, $languageVariables.get($atLangVar)) )
#else##
#set( $_dummy = $context.put($_langVarName, $atText) )
#end## isset $atLangVar
#end## $atCtry.lenght()
#end## isset $country & $atText
#end##
#*
PRINT A TRANSLATION
@use #translate($atText $country)
$atText = "String of atText to translate" OR "variable name"
$atCtry = "FR" (or any TWO LETTER country code)
*#
#macro( translate $atText $atCtry $atNoFallBack )##
#if( $UtilMethods.isSet($atCtry) && $UtilMethods.isSet($atText) )##
## DYNAMICALLY CREATE THE COUNTRY SPECIFIC LANGUAGE VARIABLE
#set( $_langVarName = "${atCtry.toUpperCase()}_${atText.toLowerCase()}" )##
#if( $UtilMethods.isSet($_langVarName) )##
#if( $UtilMethods.isSet($context.get( "$_langVarName" )) )##
$context.get( "$_langVarName" )
#elseif( !$UtilMethods.isSet($atNoFallBack) )##
$!context.get( "US_${atText.toLowerCase()}" )##
#end##
#end##
#end## isset $atCtry & $atText
#end## translate