How it works

Placeholders and plurals

A placeholder the translation drops or changes breaks your app at runtime, and a plural short of a form shows the wrong word for some numbers. TolkBot checks both on every key it writes.


Placeholders

TolkBot reads the placeholders off each source string. There is no setting for the style, and it recognizes all of these:

StyleExample
ICU{count, plural, one {1 item} other {# items}}
MustacheHello {{name}}
Simple{variable}

The model is told which placeholders the string has and that each must come back as it is. After translation, TolkBot compares the result with the source token by token:

  • A changed brace count is repaired. {{name}} that came back as {name} is put back as {{name}}.
  • A dropped or invented placeholder is refused. The key is translated again with the problem described to the model, and then by the stronger model. If all three attempts are refused, the key fails and nothing is written for it.

Why the braces count

The number of braces is part of a placeholder, not decoration. Under i18next, {{name}} is replaced with the value and {name} is printed as it is, so a translation that says Hallo {name} greets your user with the literal text {name}. TolkBot compares {{name}} and {name} as different placeholders for that reason.

Translations from other places

The same comparison runs on every value TolkBot writes, not only fresh translations: one served from translation memory, a fix from the review pass, and a correction from feedback in a pull request. When you edit a value in the dashboard, the key inspector warns when a placeholder is missing.

For translations already in your repository, the health scan reports Placeholders differ from the source. To check in your own CI, run tolkbot validate, which uses the same comparison.


ICU plurals

An ICU plural takes the forms the target language needs, not the ones the source has. English needs one and other. Other languages need more, or fewer:

LanguageForms
English, German, Frenchone, other
Polish, Russianone, few, many, other
Arabiczero, one, two, few, many, other
Japanese, Koreanother

So from

{
    "files": "{count, plural, one {# file} other {# files}}"
}

a Polish translation has four branches:

{
    "files": "{count, plural, one {# plik} few {# pliki} many {# plików} other {# pliku}}"
}

TolkBot uses the plural rules your users' browsers use (Unicode CLDR) to decide which forms a language needs. A form a language uses only for fractions or for numbers of a million and up, like French many, is not required.

A branch for a single number may say the number in words: Arabic two {ملفان} ("two files") without # is correct. The argument, count here, must stay the same, and so must the type, plural or selectordinal.

A plural stays a plural

Sometimes the target language doesn't need different words for one and many. Norwegian says "er" for both "isn't" and "aren't". The plural still stays, with the same word in each branch:

{
    "status": "{count, plural, one {Det er # feil} other {Det er # feil}}"
}

TolkBot keeps it rather than folding it into the sentence, because it can't tell this case from a language that does need the forms. Polish needs nie jest and nie są in the same place.

A plural short of a form

A translation missing a form the language needs is flagged plural_incomplete and sent to the stronger model. If the value written still lacks a form, the pull request's File checks line says so. It is written anyway, since your library falls back to other rather than failing.


i18next suffix plurals

i18next can also keep a plural as one key per form, with the form as a suffix:

{
    "items_one": "{{count}} item",
    "items_other": "{{count}} items"
}

It picks the key with the same plural rules as above, so the target file needs the target language's forms. TolkBot works that out from the base file:

  • A Polish file gets items_one, items_few, items_many and items_other from an English items_one and items_other.
  • A Japanese file gets items_other alone, and a missing items_one is not reported as missing.
  • items_zero is added when the base file has it.

A form the base file has is translated from that form. A form only the target language has, such as items_few, is translated from items_other. When the source items_other changes, every form translated from it is updated too.

These keys move as a group. Removing items_other from the base file removes all of the target's forms; see Removed and renamed keys.


Locale codes

Locale codes are matched however your files spell them: pt-BR, pt_BR and ptBR are the same language. A new file follows the spelling your other files use. In a TypeScript or JavaScript locale file, a code that isn't a valid name, like pt-pt, is exported as ptPT. See Supported languages.

Previous
Translation memory