Help Center Translation Management
Adding Variables to Phrases

Adding Variables to Phrases

Last updated: 13 days ago
3 minute read
Steven Wise
CEO at SiteTran

ALL ARTICLES

Help Center

What variables are for

Use a variable when a word in a phrase changes: a name, a month, a color, and so on.

This is different from popups, tooltips, and other content that appears after the page loads. SiteTran translates that automatically. See Translating Dynamic Content.

Prefer auto numbers when only numbers change

If the only thing that changes is a number, such as a year, a price, or a count, use Automatic Number Variables instead. They are simpler to set up, and a bit faster. Use them whenever they will do the job.

If words change, or words and numbers both change, use variables. SiteTran does not mix auto numbers and variables in the same phrase, so make variables for the numbers too.

How to add a variable

  1. Open Pages & Phrases.
  2. Click the three-dot menu on the phrase, then click Edit.
  3. Replace the changing part with a variable, such as {{name}}. Keep spaces and punctuation outside the braces.
  4. Translate the phrase as usual, and put the same {{name}} in the translation where it belongs.

SiteTran fills in the live value on the website.

Optional: add a phrase note with an original example, so translators can see what the phrase looks like with real text.

A changing name

This phrase:

Hello, Jonathan! Welcome to our site.

becomes:

Hello, {{name}}! Welcome to our site.

The French translation keeps the variable:

Bonjour, {{name}}! Bienvenue sur notre site.

On the live website, that shows as “Bonjour, Jonathan! Bienvenue sur notre site.”

More than one variable

Use a separate variable for each changing part. That also lets you reorder them in another language.

This date needs variables because the month name changes, not just the numbers:

English:

Joined: March 10, 2022

becomes:

Joined: {{month_name}} {{month_day}}, {{year}}

Spanish can move the pieces:

Unió: el {{month_day}} de {{month_name}} de {{year}}

When the value inside a variable is also a phrase

Usually, SiteTran puts the original variable value back into the translation. That is what you want for a name like “Jonathan”.

If that same value also exists as its own published phrase, SiteTran uses that translation inside the longer phrase.

Your shop might have:

Available in Blue
Available in Green
Available in Red

Turn them into one phrase:

Available in {{color}}

If “Blue” is also a phrase, translated as “Bleu”, and the parent translation is:

Disponible en {{color}}

the live website shows:

Disponible en Bleu

This only happens when the variable value is an exact match for another published phrase.

Rules and gotchas

  • Do not use the same variable name twice in one phrase. Use {{name}} and {{name_again}} instead.

If a variable is too loose, it can match other phrases by accident. Say you turn:

March 2022

into:

{{month_name}} 2022

That pattern also matches:

I was born in 2022

SiteTran would treat “I was born in” as the month, so that phrase would stay untranslated. Tighten the regex in Settings > Variables so {{month_name}} only matches real month names.

If the month stays “March” and only the year changes, don’t use a {{month_name}} variable. Use Automatic Number Variables instead.

To see why variables save translation work, read Translate Names, Dates, and Prices Without a Developer.

Couldn't find what you were looking for?

In this article