Module tongue.langpack

Language packs comprise zero or more sources of translations for a given “language”.

Packs may be added to at any time. A pack can have a parent pack which will be used if the pack in question lacks a translation token. Tongue defines a single default pack (available as tongue.pack.fallback) which always returns a string comprising the token and its arguments flattened as strings. This is the only part of Tongue which assumes an ability to flatten token arguments as strings, all other parts of tongue preserve token arguments unchanged which allows the passing of complex arguments such as repository objects.

Fields

fallback Fallback language pack.

create (language, sublang, parent) Create a language pack.

Class langpack

langpack:add_token (token, expansion, strict) Add a token expansion to a pack.
langpack:expand (token, args) Expand a token and arguments into a message.


Fields

fallback
Fallback language pack.

The fallback language pack provides a mechanism to ensure that language packs can always expand a translation to some extent.

  • fallback

create (language, sublang, parent)
Create a language pack.

This creates a tongue language pack. Once the pack is created it can be populated in various ways by language loaders. The passed in language is used by other parts of Tongue (e.g. the message resolver) to manage language packs.

Parameters:

  • language string The language name (e.g. ‘en’)
  • sublang optional string The sub-language name (or nil if unwanted) e.g. “GB”
  • parent optional langpack The parent langauge pack (if nil, Tongue will use the fallback)

Returns:

    langpack The newly created language pack

Class langpack

Tongue Language Pack.

A Tongue language pack comprises zero or more translations associated with the language (and sub-language) chosen at construction time. Language packs may have a parent and can be augmented at any time with further translations.

langpack:add_token (token, expansion, strict)
Add a token expansion to a pack.

This adds the expansion of a token to a tongue language pack. On addition, if the expansion is a string then it will NOT be validated unless the strict argument is set.

Token names are automatically uppercased in the ASCII charset.

Parameters:

  • token string The token to be expanded
  • expansion string or function The expansion string (or function)
  • strict bool Whether to treat a bad expansion string as an error.

Returns:

    bool Whether or not the expansion was successfully added
langpack:expand (token, args)
Expand a token and arguments into a message.

This expands the given token and arguments into a full message. This will always succeed unless something has gone crazywrong with the internals of tongue or the language packs.

Passed-in tokens are always uppercased before expansion.

Parameters:

  • token string The token to be expanded
  • args table Arguments to the token expansion

Returns:

    string The expanded result
generated by LDoc 1.4.6 Last updated 2022-01-28 11:46:49