Module tongue.codex

Language Codexes comprise zero or more language packs which together represent a multilingual translation for a single domain.

Codexes fundamentally consist of a number of loaders, some logic for managing the packs, and a mechanism for creating new blank packs on demand.

Class codex

codex:add_loader (loader) Add a loader to the codex.
codex:get_langpack (lang, sublang) Retrieve the given language pack from the codex.
codex:expand (lang, sublang, token, args) Expand a translation using the codex.

create (newpack) Create a new language codex.


Class codex

Tongue Language Codex.

A Tongue Language Codex is the entry point for applications into Tongue. Codexes are given loaders which can load language packs into the codex and they automatically invoke the loaders when needed, to reduce unnecessary disc access.

codex:add_loader (loader)
Add a loader to the codex.

Loaders are added to a list. The first loader added to a codex will be expected to construct the language pack, later loaders will be given the language pack to add to. If the loader determines that it needs to create a language pack which depends on another language pack, then it can request the pack from the codex. No protection is given to this causing loops, that is up to the loaders.

Parameters:

  • loader function The loader function to add to the codex.
codex:get_langpack (lang, sublang)
Retrieve the given language pack from the codex.

Note, if the language pack has not yet been loaded, or if new loaders have been added since the language pack was loaded, then loaders may be invoked to create or augment the language pack before it is returned.

Parameters:

  • lang string The base language of the desired pack.
  • sublang optional string The (optional) sub-language of the desired pack.

Returns:

    langpack The language pack from the codex for the given language.
codex:expand (lang, sublang, token, args)
Expand a translation using the codex.

Note, this can cause loaders to be invoked if the language in question has not yet been loaded.

Parameters:

  • lang string The base language of the desired expansion
  • sublang optional string The (optional) sub-language of the desired expansion
  • token string The token to expand
  • args table The token’s arguments for expansion

create (newpack)
Create a new language codex.

Codexes require only one important function to be created – namely a function which when called with language and sub-language will create an instance of langpack. If you do not pass a function to do this, then Tongue’s default behaviour will be to parent sub-languages to their base language, and otherwise to not parent languages. This means, for example, en/GB will be parented to en.

Parameters:

  • newpack optional function Function for creating a new langpack instance.

Returns:

    codex
generated by LDoc 1.4.3 Last updated 1476597862