Skip to main content
Setting Translation Checks

Learn how to set translation checks and automatically make sure specific conditions are met in translations.

Jacob Doulkeridis avatar
Written by Jacob Doulkeridis
Updated over a month ago

📝Note

  • Custom Translation Checks are available on our Growth plan and up.

  • On-demand Checks and Regex Validation Checks are available on our Enterprise Plus plan.

Translations missing key elements, such as a variable or link, could break your website or app. To help prevent this, Transifex automatically checks every translation against a set of conditions.

Whenever a condition is not met, e.g., an HTML element is missing, the translator will be shown either a warning or an error message telling them what needs to be fixed. Translators can still save a translation when there's a warning. But if there's an error, they must address the issue before saving the translation.


Configuring translation checks

Each file format has a set of translation checks by default. You can change whether a failed check results in an error or warning or turn off a check altogether. You need to have an administrator role to perform the following changes.

To customize translation checks:

  1. Go to your Organization Settings from the main navigation.

  2. Click on Translation Checks in the left menu.

  3. Click on a file format to see the checks available for that file format.

  4. Click on the toggles next to each rule to change whether a check should show a warning, error message, or be off.

    translation-checks.png#asset:809

  5. Hit Save to confirm the changes.

You can always restore the translation check settings by clicking the Set to default checks next to the Save button.

📝Note: The file format for Transifex Live projects is "Transifex Format (.json) checks".


Checking for custom variables

If you use custom variables in your code, you can set up custom translation checks and make sure they are left untouched in the translation. This is done by adding a custom check for a file format and specifying either the characters your custom variables start and end with or the exact characters your variables consist of.

To do this:

  1. Head to the Translation Checks settings page.

  2. Click on the file format you want to add custom checks for.

  3. Click Set up custom placeholders.

  4. In the popup:

    • If you provide a start and end value, Transifex will try to detect text that starts and ends with the specified words. So, to protect variables like {address}, %email%, [username], etc., during the translation process, you will just need to complete the fields "Starts with" and "Ends with" as shown below:

    create_custom_variables.png#asset:6674

    • If you want the system to look for exact matches instead (e.g., %ld, %temperature), then you can enter the variable in the "Enter a custom variable" field, including all the characters the variable consists of

  5. Click Add placeholder to finish adding this check. You can add more if you like by creating more placeholders.

    added_custom_placeholders.png#asset:6673

📝Note: When adding multiple placeholder delimiters, remember that they are executed in the order they are added.

In the following example, both placeholders will be executed. However, only the first expression would be executed if the order were reversed.

Macaque in the trees

Like the default checks, you can change whether a failed check results in an error or warning or turn it off altogether.


Translation checks based on regular expressions

With custom translation checks, you, as an organization administrator, can add your own regular expressions and ensure that nothing will break your website or application due to an invalid translation.

These checks can be created per file format as follows:

  • Click on the file format where you want to create your custom translation check.

  • Click 'Add a translation check' at the bottom of the checks list.

  • Provide a description for the check you want to create - This message will be displayed in the editor every time your rule is violated.

  • Add your custom regular expression.

  • Define where the custom translation check will be applied, i.e., Translations only (the translation check will fail if there is a match) or Translations and source strings (the translation check will fail if the matches found in the source string are different than the matches found in the translation). In the case of the latter, you also have the option to enable the setting "Respect the matching order," which ensures that the order in the source is preserved in the translation text.

  • Test the regular expression you created before saving your configuration.

  • Define the status of the check (Error, Warning, Off)

📝Note

  • The regular expression has a maximum timeout of 100ms.

  • Whenever an existing custom translation check is updated, it is automatically triggered only for newly submitted translations. You can run an on-demand translation check to trigger the updated check for existing translations.


Use cases and examples using Regex

1. Match quotes

When the source text contains double or single quotes, and you want to check that there are quotes also in the translation text, you can use the following regular expression:

Regex: \"|\'

You can omit the double or the single quote from this regex if you want to check only for one of them, e.g. \"

This expression instructs the system to find if double or single quotes exist in the translation text. Depending on where this check will be applied, translations only or both source and translation string, the following can happen:

  • If the check is on translations only and the text does not contain double or single quotes, then no error will be returned.

  • If the check is on translations only and the translation text contains double or single quotes, an error is returned.

  • If the check is on the source and translation strings and the source text contains double or single quotes, whereas the translation text does not, an error will be returned.


  • If the check is on the source and translation strings and both the source and translation text contain double or single quotes, no error is returned.

The setup will look like this:

Screenshot-2022-01-13-at-1.35.46-PM.png#asset:9906

Your regex expression can easily be tested using the test area.

Message returned when translation check fails:

Screenshot-2022-01-17-at-12.03.56-PM.png#asset:9918

Message returned when translation check is successful:

Screenshot-2022-01-13-at-2.10.20-PM.png#asset:9908

More examples can be found below:

2. Special characters (excluding whitespaces)

You can use the following regular expression to check whether there are characters apart from alphanumeric ones and whitespace in the translation text or both the source and translation texts. Special characters include: !@#$%&* and others.

Regex: [^a-zA-Z0-9\s]

3. Spaces, tabs, or newlines at the end of a string

Often, translators add a space, tab, or newline at the end of their translation text, which is not present in the source text. You can use the following regular expression to check whether there are such cases.

Regex: [\s\t\n]+$

Using the + in the regular expression, there will be a match even if there is more than one space, tab, or new line. The $ sign denotes the end of the string. If you apply it to both the source and the translation text, then the following can happen:

  • No error will be returned if the source and translation text contain a space at the end.

  • An error will be returned if the source or translation text contains a space at the end.

If the check is applied only to the translation text, an error will be raised whenever there is a space, tab, or newline at the end of the string, regardless of whether the source text contains them.

4. Find whitespace at the start or end of a string

Like the example above, if you want to locate whitespace at the beginning or the end of a string, you can use the following regular expression.

Regex: ^\s+|\s$

The | sign is used as the logical OR, and the ^ sign marks the beginning of the string. If you apply this check to the translation text, for example, the following can happen:

  • If the translation text contains one or more whitespaces at the beginning of a string or whitespace at the end, an error will be returned.

  • No error will be returned if the translation text doesn't start or end with whitespace.

5. Bold text wrapped with **double asterisks**

Often, source strings contain inline formatting. This formatting usually needs to be applied to the translation text, too. If you want to ensure that your translators preserve the formatting of words emphasized in the source language when translating content, then you can use the following regular expression.

Regex: \*\*

When this check is applied to the translation and source strings, the following can happen:

  • If part of your source string is wrapped with double asterisks and this formatting is not detected in the translation text applied, an error message will be returned upon saving the translation.

  • If part of your translation string is wrapped with **double asterisks** and such formatting is not found in the source string, an error message will be returned upon saving the translation.

6. Find multiple whitespaces

Sometimes, the translators accidentally add more than one whitespace in their translations. To catch such cases, you can use the following regular expression.

Regex: \s{2,}

The curly brackets signify how many repetitions of the previous character we're looking for, in our case, the whitespace. The lower limit is two times, and there is no upper limit. When this check is applied to the translation text, the following can happen:

  • An error will be returned if the translation text contains two or more consecutive whitespaces somewhere in the string (beginning, middle, end).

  • No error will be returned if the translation text doesn't contain two or more consecutive whitespaces.

7. Placeholders that start and end with % (no whitespace in between)

The source text often contains variables the translator should leave intact while translating the source string. If whitespaces are added by mistake, the developers' code will break, and the app or page might not load correctly.

Let's take, for example, the following source string: "There are %no_of_countries% in %continent%". The translator adds the following as a Greek translation: "Υπάρχουν %no_of countries% χώρες στην %continent%". There is a whitespace added by accident in the first variable. When the following regular expression is used, these mistakes can be corrected before the translations reach production.

Regex: %(?!%)(?!%)\S+?%

The negative lookaheads (?!%) denote that the first character, the %, should not be followed directly by one or two of the same characters. It should be followed by one or more non-whitespace characters and end with the % character.

Given the example above, and considering that you have a translation check with the above regular expression configured for both the source and the translation text, an error (or a warning) will be raised for the translation entered.

8. Match everything except an unwanted pattern

When you want to identify instances where any character except a list of excluded characters is enclosed in brackets, you can use the following regular expression.

Regex: \[([^w|W])\]

To match any character except a list of excluded characters put the excluded characters between [^ and ]. The caret ^ must immediately follow the [.

When this check is applied to the translation text only, the following can happen:

  • If the translation text contains a character enclosed in brackets and this character is either w or W, then no errors will be returned.

  • If the translation text contains a character enclosed in brackets and this character is neither w nor W, then an error will be returned.

9. Consecutive duplicate words

You can use the following regular expression to identify instances where translation text contains consecutive duplicate words.

Regex: \b(\w+)\s+\1\b

The \b character is a word boundary that allows you to perform a “whole words only” search. For instance, regexp \bJava\b will be found in Hello, Java!, where Java is a standalone word, but not in Hello, JavaScript!.

The \w+ character matches word characters. A word character is a character a-z, A-Z, 0-9, including _ (underscore). The parentheses around this group of characters create a capturing group, which allows you to refer to the matched characters later in the expression.

The \s+ character matches one or more whitespace characters (such as a space, tab, or newline).

Finally, the \1 at the end of the expression, the text matches exactly the one matched by the first capturing group.

When this check is applied to the translation text only, the following can happen:

  • An error will be returned if the translation text contains consecutive duplicate words.

  • If the translation text contains the same word twice, but one does not follow after the other in order, then no errors will be returned.

10. Mismatched colon

You can use the following regular expression to check if both source and translation text end with a colon(:).

Regex: ^(?!.*:$).*$

When this check is applied to translations and source strings, the following can happen:

  • If the source string contains a colon (:) character at the end of the text but the translation string doesn't, then an error will be returned.

  • If the source AND translation strings contain a colon (:) character at the end of the text, then no errors will be returned.

11. Preserve style and tone in translations

To check if the translation accurately reflects the style and tone of the original text, you can use a regular expression to identify words or phrases that shouldn't be there in the first place. For example:

Regex: \b(yo|dude|bro)\b

When this check is applied to translations only, the following can happen:

  • An error will be returned if the translation text contains at least one of the words in the expression above (i.e., yo, dude, bro).

  • No errors will be returned if the translation text doesn't contain any of the words included in the expression above (i.e., yo, dude, bro).

12. Variable substitution specifiers (like "%s") are preserved in the translations

For a custom variable, it makes no sense to have a variable that begins with a dash (-),

Regex: %-var%

So we exclude the variable if character "-" is right after the start of the placeholder. In that way, from string '30%-70%', the part %-70% is not going to be identified as a variable if we enable placeholder for %....%. The code is written in such a way to include later other characters that we may decide to exclude as well.


On-demand translation checks

On-demand translation checks are available under the settings page of your Transifex project. This feature allows you to run translation checks on translation strings that have already been submitted.

To run translation checks on demand, you need to:

  1. Visit the Settings page of your project in Transifex.

  2. Click on the Workflow tab.

  3. Scroll down to the "Quality Assurance" section.

  4. Click on the highlighted text "Check now" as shown below:

    Screenshot-2021-06-07-at-2.48.34-PM.png#asset:9128

  5. After that, the system will start running translation checks on the existing translations.

Check-on-demand-image-after-pressed.png#asset:9138

When the task is completed, an email notification will be sent to the user who performed this action (admins, maintainers) where a detailed report will be included:

ton_demand_translation_checks_emails.png#asset:9142


💡Tip

Looking for more help? Get support from our Transifex Community Forum!

Find answers or post to get help from Transifex Support and our Community.

Did this answer your question?