It’s possible to create Custom text variables, which you can use with or without the language switcher. In the latter case, you can create a dictionary where custom text variables can provide separate values for each configured language.
For an overview and walkthrough of the feature see the written tutorial: Dynamic text on sites and portals
Go to the Refined Administration > the Languages tab.
Go to the under the Dictionary section.
Add text variabbles or import/export a dictionary.
Define text variable keys by surrounding text with two $
characters, for example: $myKey$
.
Each variable has a Default value. This is where the value should be entered. If used together with the Languages feature, if the users current language is not present, the variable will fallback on the Default value.
When adding values for languages you also have the option to copy the value from the Default Value field. Useful to easily start from the same value or even keeping it the same for this language without having to manually retype it.
From the Admin UI under Languages you can filter on custom text variables in the Dictionary section. It’s possible to filter on Empty / Translated values and text/key search. You can also further filter the result by language or tags.
For each text variable you can add Tags. This can be done when creating the text variable or added in later. Tags are meant to be a tool to help you organize or group your text variables in whatever way you see fit.
You cannot nest custom text variables, i.e. the following will not work properly:
-- Not supported -- $first$ = Coffee $second$ = I like $first$ |
However, it is possible to use the list of pre-defined variables found here: Make content dynamic:
-- Works! -- $welcome$ = Welcome to $sitename, $userfirstname! |
If using the custom text variables with nested text variables in the Site builder (How to find the Site Builder) note that only the $user*
text variables are supported.
The custom text variables support executing small scripts. This can be useful for displaying dynamic values or adding a condition to them. You could for example have a message to say “Good morning” during the morning and “Good afternoon” during the afternoon.
You’ll wrap your script in curly brackets: {
script }
. Whatever the script-part defined as the returned value is what will be used to replace the brackets section.
Examples:
$copyrightMessage$: "Copyright ACME {return (new Date()).getFullYear()}" $greeting$: "{if ((new Date).getHours() < 12) { return "Good morning" } else { return "Good afternoon" }}" |
The variables will find whatever content is present inside the curly brackets and executes it using a Function() constructor.
The logic syntax is not supported when adding custom text variables to the Site structure items via the Site builder.
It’s possible to import and export the custom text variables as .properties
files.
When exporting a zip
file is created containing a .properties
file for each language. When importing you can import a zip with multiple languages, or you can upload single language files as well.
When importing a dictionary all current keys will be merged with new ones. Duplicates will be overwritten by the imported file. |
You can edit and create the files in whatever tool you see fit but it’s important that they are saved using the UTF-8 encoding to ensure they are read properly upon importing. When the files are exported any non-ascii characters are escaped and written as their unicode counterpart.