fluent.js
    Preparing search index...

    Class Localization

    The Localization class is a central high-level API for vanilla JavaScript use of Fluent. It combines language negotiation, FluentBundle and I/O to provide a scriptable API to format translations.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • resourceIds: string[] = []

        List of resource IDs

      • generateBundles: Function

        Function that returns a generator over FluentBundles

      Returns Localization

    Properties

    bundles: any
    generateBundles: Function
    resourceIds: string[]

    Methods

    • Parameters

      • resourceIds: any
      • eager: boolean = false

      Returns number

    • Retrieve the translation corresponding to the id identifier.

      If passed, args is a simple hash object with a list of variables that will be interpolated in the value of the translation.

      Returns a Promise resolving to the translation string.

      Use this sparingly for one-off messages which don't need to be retranslated when the user changes their language preferences, e.g. in notifications.

      Parameters

      • id: string

        Identifier of the translation to format

      • Optionalargs: Object

        Optional external arguments

      Returns Promise<string>

      docL10n.formatValue(
      'hello', { who: 'world' }
      ).then(console.log);

      // 'Hello, world!'
    • Retrieve translations corresponding to the passed keys.

      A generalized version of DOMLocalization.formatValue. Keys must be {id, args} objects.

      Returns a Promise resolving to an array of the translation strings.

      Parameters

      • keys: Object[]

      Returns Promise<string[]>

      docL10n.formatValues([
      {id: 'hello', args: { who: 'Mary' }},
      {id: 'hello', args: { who: 'John' }},
      {id: 'welcome'}
      ]).then(console.log);

      // ['Hello, Mary!', 'Hello, John!', 'Welcome!']
    • This method should be called when there's a reason to believe that language negotiation or available resources changed.

      Parameters

      • eager: boolean = false

      Returns void

    • Parameters

      • resourceIds: any

      Returns number