How can I add variables to my translations?
In this article, you'll see the variable feature, when and why it is useful, and how to set up a variable.
1. What is the variable feature, and why is it used?
2. How to set up variable(s)?
1. What is the variable feature, and why is it used?
Weglot automatically translates your original content to its translated equivalent. It also reuses the translations already present in your Translation List if some contents have already been translated.
If you have the exact same content displayed on several pages, Weglot will only translate it once and display the translation on those pages.
However, if you have very similar (but not identical) content on several pages, you may have multiple translations that would increase your total word count.
For example, if you have content such as" Order #324", "Order#325" and so on, or if a client is logged in to your website and if you display a message such as "Hello John," you may have several translations like the following:
In this case, the variable feature will allow you to aggregate all those translations into a single one with a variable to reduce your word count.
For instance, here's what the result looks like with a variable:
2. How to setup variable(s)?
Next to each translation, you will see a three-line button when you hover on a translation ("See details" button).
Click on it to access the panel:
You should now see the information panel of the translation you've selected.
Click on the "Variables" tab:
Then click on "define variables":
You are now on the tab where you'll create your variable. As it is mentioned, you have to highlight the content you'd like to transform into a variable.
In our example, the content we need to replace is the customer's name, so you need to highlight the content like this:
If the content is just a single word, you can double-click on it to highlight it automatically.
After that, you have to name your variable and select a type.
In our example, we will name the variable "CustomerName" and select the type "Alphabetical Only" as the content only contains characters (without numbers):
Please note that you can name the variable as you prefer as long as it doesn't contain any special characters.
Finally, click on "Add variable" at the bottom right to see a preview of all the translations related to your variable:
This preview lets you ensure your variable is valid and matches the correct translations. These matched translations will be deleted when you click on "Save" and replace with a unique translation that contains a variable
If everything is alright, click on "Save" at the bottom right corner, and you're done.
You now have set up a variable that reduces your word count. You can still manually edit the translation if you need to (see How to edit my translations).