L20n by example

7. Advanced Selectors

Selectors are pretty powerful. A localizer can use any builtin explicitly and select a string variant depending on its output. In case of available-users entity, we used the LEN builtin and select the variant of the string depending on its output.

Explicit values can be used in the PLURAL selector example to specify a special case for when there are no unread emails.

Additionally, the code specifies the default variant to be used if none of the others match. It's denoted with a * operator in front of the variant name.

{ "users": ["John", "Mary"], "unreadEmails": 0 }
available-users = { LEN($users) -> [0] No users [1] One user. [2] Two users. *[other] { LEN($users) } users. } unread-emails = You have { $unreadEmails -> [0] no unread emails. [one] one unread email. *[other] { $unreadEmails } unread emails. }