govuk-frontend
    Preparing search index...

    Class I18nInternal

    Internal support for selecting messages to render, with placeholder interpolation and locale-aware number formatting and pluralisation

    Index

    Constructors

    • Internal

      Parameters

      • translations: { [key: string]: string | TranslationPluralForms } = {}

        Key-value pairs of the translation strings to use.

      • Optionalconfig: { locale?: null | string } = {}

        Configuration options for the function.

        • Optionallocale?: null | string

          An overriding locale for the PluralRules functionality.

      Returns I18n

    Properties

    locale: string
    translations: { [key: string]: string | TranslationPluralForms }

    Methods

    • 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)

      Parameters

      • lookupKey: string

        The lookup key of the string to use.

      • count: number

        Number used to determine which pluralisation to use.

      Returns PluralRule

      The suffix associated with the correct pluralisation for this locale.

      Plural form .other required when preferred plural form is missing

    • Internal

      Check to see if the browser supports Intl.PluralRules

      It requires all conditions to be met in order to be supported:

      • The implementation of Intl supports PluralRules (NOT true in Safari 10–12)
      • The browser/OS has plural rules for the current locale (browser dependent)

      https://browsersl.ist/#q=supports+es6-module+and+not+supports+intl-pluralrules

      Returns boolean

      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

      Parameters

      • translationString: string

        The translation string

      • options: { [key: string]: unknown }

        Any options passed with the translation string, e.g: for string interpolation.

      Returns string

      The translation string to output, with ${} placeholders replaced

    • Internal

      The most used function - takes the key for a given piece of UI text and returns the appropriate string.

      Parameters

      • lookupKey: string

        The lookup key of the string to use.

      • Optionaloptions: { [key: string]: unknown }

        Any options passed with the translation string, e.g: for string interpolation.

      Returns string

      The appropriate translation string.

      Lookup key required

      Options required for ${} placeholders