Foundry Virtual Tabletop - API Documentation - Version 14
    Preparing search index...

    Class Localization

    A helper class which assists with localization and string translation

    The default language configuration setting for the server

    Index

    Properties

    _fallback: Object

    Fallback translations if the target keys are not found

    defaultModule: string

    The package authorized to provide default language configurations

    lang: string

    The target language for localization

    translations: Object

    The translation dictionary for the target language

    Accessors

    • get pluralRules(): PluralRules

      A reusable PluralRules instance

      Returns PluralRules

    Methods

    • Retrieve list formatter configured to the world's language setting.

      Parameters

      • Optionaloptions: { style?: ListFormatStyle; type?: ListFormatType } = {}
        • Optionalstyle?: ListFormatStyle

          The list formatter style, either "long", "short", or "narrow".

        • Optionaltype?: ListFormatType

          The list formatter type, either "conjunction", "disjunction", or "unit".

      Returns ListFormat

    • Return whether a certain string has a known translation defined.

      Parameters

      • stringId: string

        The string key being translated

      • Optionalfallback: boolean = true

        Allow fallback translations to count?

      Returns boolean

    • Initialize the Localization module Discover available language translations and apply the current language setting

      Returns Promise<void>

      A Promise which resolves once languages are initialized

    • Localize a string by drawing a translation from the available translations dictionary, if available. Variables can be included in the template enclosed in curly braces and will be substituted using those named keys.

      Parameters

      • stringId: string

        The string ID to translate

      • Optionaldata: Record<string, unknown>

        Data for variable formating: values can be anything meaningfully stringifiable.

      Returns string

      The translated string, if a translation was found, or else the inputted stringId

      {
      "MYMODULE.MYSTRING": "Hello, this is my module!"
      }
      _loc("MYMODULE.MYSTRING"); // Hello, this is my module!
      {
      "MYMODULE.GREETING": "Hello {name}, this is my module!"
      }
      _loc("MYMODULE.GREETING" {name: "Andrew"}); // Hello Andrew, this is my module!
      {{localize "MYMODULE.MYSTRING"}} <!-- Hello, this is my module! -->
      {{localize "MYMODULE.GREETING" name="Andrew"}} 
      
    • Set a language as the active translation source for the session

      Parameters

      • lang: string

        A language string in CONFIG.supportedLanguages

      Returns Promise<void>

      A Promise which resolves once the translations for the requested language are ready

    • Sort an array of objects by a given key in a localization-aware manner.

      Parameters

      • objects: object[]

        The objects to sort, this array will be mutated.

      • key: string

        The key to sort the objects by. This can be provided in dot-notation.

      Returns object[]

    • Perform one-time localization of the fields in a DataModel schema, translating their label and hint properties.

      Parameters

      • model: typeof DataModel

        The DataModel class to localize

      • options: { prefixes?: string[]; prefixPath?: string } = {}

        Options which configure how localization is performed

        • Optionalprefixes?: string[]

          An array of localization key prefixes to use. If not specified, prefixes are learned from the DataModel.LOCALIZATION_PREFIXES static property.

        • OptionalprefixPath?: string

          A localization path prefix used to prefix all field names within this model. This is generally not required.

      Returns void

      DataModel.LOCALIZATION_PREFIXES for an example of the class definition and localization file structure.

    • Localize the "label" and "hint" properties for all fields in a data schema.

      Parameters

      • schema: SchemaField
      • prefixes: string[] = []
      • Optionaloptions: { prefixPath?: string; seenFields?: Set<DataField> } = {}

      Returns void