Options
All
  • Public
  • Public/Protected
  • All
Menu

Module src/core/prelude/i18n/helpers

Index

Functions

  • i18nFactory(keysetNameOrNames: string | string[], customLocale?: Language): (key: string, params?: I18nParams) => string
  • Creates a function to internationalize strings in an application based on the given locale and keyset. Keyset allows you to share the same keys in different contexts. For example, the key "Next" may have a different value in different components of the application, therefore, we can use the name of the component as a keyset value.

    Parameters

    • keysetNameOrNames: string | string[]

      the name of keyset or array with names of keysets to use. If passed as an array, the priority of the cases will be arranged in the order of the elements, the first one will have the highest priority.

    • Optional customLocale: Language

    Returns (key: string, params?: I18nParams) => string

      • Creates a function to internationalize strings in an application based on the given locale and keyset. Keyset allows you to share the same keys in different contexts. For example, the key "Next" may have a different value in different components of the application, therefore, we can use the name of the component as a keyset value.

        Parameters

        Returns string

  • Returns the correct plural form to translate based on the given count

    example
    const result = pluralizeText([
    {count} product, // One
    {count} products, // Some
    {count} products, // Many
    {count} products, // None
    ], 5);

    console.log(result); // '{count} products'

    Parameters

    Returns string

  • Returns the form for plural sentences and resolves variables from the passed template

    example
    const example = resolveTemplate('My name is {name}, I live in {city}', {name: 'John', city: 'Denver'});

    console.log(example); // 'My name is John, I live in Denver'

    const examplePluralize = resolveTemplate([
    {count} product, // One
    {count} products, // Some
    {count} products, // Many
    {count} products, // None
    ], {count: 5});

    console.log(examplePluralize); // '5 products'

    Parameters

    • value: Translation

      a string for the default case, or an array of strings for the plural case

    • Optional params: I18nParams

      a dictionary with parameters for internationalization

    Returns string