Skip to content

Latest commit

 

History

History
54 lines (45 loc) · 1.91 KB

File metadata and controls

54 lines (45 loc) · 1.91 KB

Selectors

emails =
    { $unreadEmails ->
        [one] You have one unread email.
       *[other] You have { $unreadEmails } unread emails.
    }

One of the most common cases when a localizer needs to use a placeable is when there are multiple variants of the string that depend on some external variable. In the example above, the emails message depends on the value of the $unreadEmails variable.

FTL has the select expression syntax which allows to define multiple variants of the translation and choose between them based on the value of the selector. The * indicator identifies the default variant. A default variant is required.

The selector may be a string, in which case it will be compared directly to the keys of variants defined in the select expression. For selectors which are numbers, the variant keys either match the number exactly or they match the CLDR plural category for the number. The possible categories are: zero, one, two, few, many, and other. For instance, English has two plural categories: one and other.

If the translation requires a variant for a specific value, it will be matched according to its numerical value. This applies even if the number will be formatted differently, e.g. with trailing zeros. Selection on non-integral numbers should be avoided.

your-score =
    { NUMBER($score, minimumFractionDigits: 1) ->
        [0] You scored zero points. What happened?
       *[other] You scored { NUMBER($score, minimumFractionDigits: 1) } points.
    }

Using formatting options also allows for selectors using ordinal rather than cardinal plurals:

your-rank = { NUMBER($pos, type: "ordinal") ->
   [1] You finished first!
   [one] You finished {$pos}st
   [two] You finished {$pos}nd
   [few] You finished {$pos}rd
  *[other] You finished {$pos}th
}