Skip to main content

How to translate ICU plural and select messages in XML files

Apps often store strings that change with a number or a choice in ICU MessageFormat, such as {count, plural, one {# trip} other {# trips}}. Translated as one block, that syntax is easy to break. With ICU MessageFormat turned on in the XML filter, wxrks splits each message into one segment per variant and protects the syntax as tags, so translators only translate words and the exported file stays valid ICU.

💡 Who is this for? Account Admins who save XML filters, Project Managers who set the import settings of one XML file, and Vendors who translate those messages in the Editor.

Contents

How wxrks reads an ICU message

ICU MessageFormat is a syntax for strings whose wording depends on a value. A plural picks a variant by number (one, other, =0…), and a select picks one by a keyword (for example male, female, other). Each variant is a branch.

Take this string:

<value>You completed {trip_count, plural, one {# trip} other {# trips}} today.</value>

With ICU MessageFormat on, wxrks creates three segments:

Segment

What the translator sees

Branch one

1 trip — tag 1 is the number (#)

Branch other

1 trips

The sentence around the plural

You completed 1 today. — tag 1 is the whole plural

The ICU syntax ({trip_count, plural, …}, the branch keywords and #, which stands for the number) becomes numbered tags, and simple placeholders such as {name} become tags too. A message that is only a plural or a select, with no text around it, gives only its branch segments. On export, wxrks rebuilds the full ICU message with the translation of each branch.

Without the option, the whole value is a single segment and only a RegEx for tags can protect the syntax.

Before you start

Turn on ICU MessageFormat

  1. Open the XML filter (Settings > Translation > Filter settings, then Add filter or Edit) or the file's Import settings, with Custom selected in Filter for XML.

  2. Turn on ICU MessageFormat. It is off by default.

  3. Save the filter, or continue creating the project.

Import settings of an XML file with a red box and badge 1 on the ICU MessageFormat switch, turned on, and its guide text: each branch becomes its own segment and the ICU syntax becomes tags.

The option applies to files imported after you turn it on. Files already in a project keep the segments they were imported with.

💡 Tip: Run Extraction preview with a sample file before saving: each branch should be listed as its own segment.

Extraction preview with the ICU option on: 9 segments, where "1 trip", "1 trips" and "You completed 1 today." show the number and the plural as tag 1, and the select branches "Go online" and the others are separate segments.

Translating ICU segments in the Editor (Vendors)

The branches of a message come first, followed by the sentence around them. Each branch segment shows a badge with the message's argument and its branch, such as trip_count · one or count · =0. Hover it to see the type, for example "ICU plural, branch one".

Editor with an ICU message: badge 1 on the trip_count · other badge of a branch row; badge 2 on the target of the outer sentence "Você completou 1 hoje.", whose header shows Max 29 / 30.

When you translate:

  • Translate each branch as a complete phrase for its case: one for a single item, other for the rest, =0 for exactly zero.

  • Keep the tags. In a branch, place the number tag where the number goes in your language; in the outer sentence, place the plural's tag where the whole phrase goes. You can move tags; don't delete them.

  • Don't type # yourself. Use the number tag: a # typed into the translation is read as the number in the exported file.

  • Machine translation and Context Sensitive still run on each branch. Context Sensitive also receives the sentence around the branch and the branch's case, so it can agree in number.

⚠️ Warning: Your target language only gets the branches the source file has. If your language needs more plural forms than the source (Russian few and many, for example, when the English file only has one and other), those numbers use the other branch in the app, as ICU does. Write other so it reads acceptably for them.

Character limits with ICU

If the strings have a character limit (read with Record fields), the limit applies to each version of the message that the app can display, not to the sum of all branches: wxrks counts the sentence around the plural plus the longest branch of each plural or select. The Editor counter, the QA check Target exceeds the segment's character limit and the Block mode all use that same count.

Every row of the message shows that same total. For example, with a limit of 30 and You completed {trip_count, plural, one {# trip} other {# trips}} today. translated as "Você completou 1 hoje." with the branches "1 viagem" and "1 viagens", each row shows Max 29 / 30: the outer sentence plus "viagens", the longer branch.

Limitations

  • Only plural and select are read. Messages in the older choice format make the import fail.

  • The option is available on XML files only.

  • Apostrophes can come out doubled in some ICU positions in the exported file. The message is still valid ICU.

Troubleshooting

Problem

Cause and fix

The import fails with "… has an ICU message in the choice format, which is not supported."

Rewrite that message with plural or select in the source file and import it again.

The import fails with "… has an ICU message that cannot be read: …"

A message has an ICU syntax error, such as an unclosed brace. Fix it in the source file; the message names the problem.

The import fails with "Could not read … with ICU MessageFormat on."

The file couldn't be read as ICU. Check that the filter extracts only the element with the messages.

The whole message is still one segment

The file was imported before the option was turned on, or the filter used for it doesn't have ICU MessageFormat on. Import the file again with the right filter.

A number shows in the wrong place in the app

A # was typed in a translation. Replace it with the number tag.

Related articles

Did this answer your question?