ICU Message Format
All Tolgee SDKs are following ICU (International Components for Unicode) Message Format. Let's see, how to work with it.
Providing values
The easiest example is how to include external parameters in your message.
If your parameter name
is John
, the output will be Hello, I am John
.
Plurals
Sometimes you need to specify the form of some part of the message depending on provided number value.
In English this is relatively easy. We need just 2 forms of the word dog
and be
verb. If we would like to be even cooler,
we could provide special form for 0 dogs.
If we are translating into other languages, this could be much more complicated. Fortunately, it's simple to cover all the cases. For example in Czech language we will need to cover these cases:
Notice, that you can also use tags like few
or many
.
All supported tags are:
=#
– used for matching on an exact number (=0
,=1
, etc.)zero
one
– singulartwo
– dualfew
– paucalmany
– also used for fractions if they have a separate classother
– required, general plural form (also used if the language only has a single form)
This will cover all the cases we need. For more information about plural rules, read Unicode's Plural rules documentation.
Selecting value
Sometimes we need to change the form of some part of translation depending on exact value match. One of these cases is selecting proper form by gender. Again, this is something you will need in Czech language.
Combining the rules
Sometimes, you would like to combine the rules. This is no problem, you can provide messages like this:
To read more about ICU format, you can follow the ICU User Guide.
Source: userguide.icu-project.org.