Jump to content

Guides

Plural phrases

Why plurals are treated differently

Many of the phrases used in the IPS Community Suite are plurals. Some examples are:

  • 21 replies
  • 3 comments
  • You have 10 new notifications

In English, a plural typically has an 's' for multiple, and no 's' for singular. In other languages, the rules may be more complex and require a specific format depending on the exact number.

To facilitate these nuances, the IPS Community Suite uses a special syntax for phrases that refer to a plural items. The language system passes the value being used into the phrase, and the special syntax can use this value to determine which words to show.

 

Syntax

The syntax for plural phrases looks like this:

{# [1:reply][?:replies]}

There's a lot that this syntax allows, but this is the basic usage. It's made up of definitions that are applied depending on the number passed into the phrase for replacement. Let's step through each part of this.

 

{...}

The plural replacement always needs to be enclosed in curly braces so that the suite core can recognize it. Note that the plural replacement can appear inside another phrase if the rest of the phrase isn't plural-dependent. For example:

"You have {# [1:new notification][?:new notifications]}"

 

#

The next character is typically the pound/hash symbol. When it appears at the start of the replacement, this symbol is replaced with the actual number passed into the plural. Alternatively, if you use !# then the number is not included.

{# [1:reply][?:replies]}
{!# [1:reply][?:replies]}

becomes:

10 replies
replies

 

[x:reply]

The next block is the replacement option, of which there can be several. These are enclosed in square braces, and you can have as many as needed for your language. The block begins x:, where x is a number, indicating that this replacement is used when the number passed into the phrase is exactly x. If your language requires a different plural form for certain numbers, you can repeat the block for each.

There's three special symbols you can use for 'x' here:

  • *1: Matches all numbers that end in 1, e.g. 1, 11, 21, 251
  • %1: Matches all numbers that start with 1, e.g. 1, 10, 12, 163
  • ?: Matches all other values that aren't matched by another block

After the colon : is the string value used if this block matches.

Note that the values in these blocks can use the special character #, which like above is replaced with the actual value passed into the phrase. This is particularly useful where the phrase does not need to show the number except in certain circumstances. For example:

"Every {!#[1:year][?:# years]}"

In English, saying "Every 1 year" would be odd, but for other values you would say "Every 3 years". So in this case, we use !# at the start of the replacement so that the number isn't automatically added, and then use # in the second block so that our string contains the number only if that block is used.


  Report Guide


×