Internal
Internal
Key-value pairs of the translation strings to use.
Optional
config: { locale?: string } = {}Configuration options for the function.
Optional
locale?: stringAn overriding locale for the PluralRules functionality.
Static
Internal
pluralDifferent pluralisation rule sets
Returns the appropriate suffix for the plural form associated with n
.
Possible suffixes: 'zero', 'one', 'two', 'few', 'many', 'other' (the actual
meaning of each differs per locale). 'other' should always exist, even in
languages without plurals, such as Chinese.
https://cldr.unicode.org/index/cldr-spec/plural-rules
The count must be a positive integer. Negative numbers and decimals aren't accounted for
Static
Internal
pluralMap of plural rules to languages where those rules apply.
Note: These groups are named for the most dominant or recognisable language that uses each system. The groupings do not imply that the languages are related to one another. Many languages have evolved the same systems independently of one another.
Code to support more languages can be found in the i18n spike: https://github.com/alphagov/govuk-frontend/blob/spike-i18n-support/src/govuk/i18n.mjs
Languages currently supported:
Arabic: Arabic (ar) Chinese: Burmese (my), Chinese (zh), Indonesian (id), Japanese (ja), Javanese (jv), Korean (ko), Malay (ms), Thai (th), Vietnamese (vi) French: Armenian (hy), Bangla (bn), French (fr), Gujarati (gu), Hindi (hi), Persian Farsi (fa), Punjabi (pa), Zulu (zu) German: Afrikaans (af), Albanian (sq), Azerbaijani (az), Basque (eu), Bulgarian (bg), Catalan (ca), Danish (da), Dutch (nl), English (en), Estonian (et), Finnish (fi), Georgian (ka), German (de), Greek (el), Hungarian (hu), Luxembourgish (lb), Norwegian (no), Somali (so), Swahili (sw), Swedish (sv), Tamil (ta), Telugu (te), Turkish (tr), Urdu (ur) Irish: Irish Gaelic (ga) Russian: Russian (ru), Ukrainian (uk) Scottish: Scottish Gaelic (gd) Spanish: European Portuguese (pt-PT), Italian (it), Spanish (es) Welsh: Welsh (cy)
Internal
Work out which pluralisation rules to use for the current locale
The locale may include a regional indicator (such as en-GB), but we don't usually care about this part, as pluralisation rules are usually the same regardless of region. There are exceptions, however, (e.g. Portuguese) so this searches by both the full and shortened locale codes, just to be sure.
The name of the pluralisation rule to use (a key for one of the functions in this.pluralRules)
Internal
Get the appropriate suffix for the plural form.
Uses Intl.PluralRules (or our own fallback implementation) to get the 'preferred' form to use for the given count.
Checks that a translation has been provided for that plural form – if it hasn't, it'll fall back to the 'other' plural form (unless that doesn't exist either, in which case an error will be thrown)
The lookup key of the string to use.
Number used to determine which pluralisation to use.
The suffix associated with the correct pluralisation for this locale.
Internal
Check to see if the browser supports Intl.PluralRules
It requires all conditions to be met in order to be supported:
https://browsersl.ist/#q=supports+es6-module+and+not+supports+intl-pluralrules
Returns true if all conditions are met. Returns false otherwise.
Internal
Takes a translation string with placeholders, and replaces the placeholders with the provided data
The translation string
Any options passed with the translation string, e.g: for string interpolation.
The translation string to output, with ${} placeholders replaced
Internal
Get the plural form using our fallback implementation
This is split out into a separate function to make it easier to test the fallback behaviour in an environment where Intl.PluralRules exists.
Number used to determine which pluralisation to use.
The pluralisation form for count in this locale.
Internal
The most used function - takes the key for a given piece of UI text and returns the appropriate string.
The lookup key of the string to use.
Optional
options: { [key: string]: unknown }Any options passed with the translation string, e.g: for string interpolation.
The appropriate translation string.
Internal support for selecting messages to render, with placeholder interpolation and locale-aware number formatting and pluralisation