panthus/elm-gettext/1.0.0

GetText

This library allows you to internationalize (i18n) your Elm application using GNU gettext MO/PO files.

Definition

The translations for a specific language.

Translation functions

t : Translations -> String -> List ( String, String ) -> String

Returns the translation of the given text and formats it with the given args. If the translation cannot be found the default text is returned.

The text can contain format items in format {<name>} where <name> can be letters, numbers and underscore. The format items must have a unique name, if there are duplicates the last format item wins. If the format item does not exist it will remain.

t translations "Hello {name}" [ ( "name", "Jay" ) ]


t translations "Hello" []
tn :
-> Int
-> String
-> String
-> List ( String, String )
-> String

Returns the translation of the given text or pluralText based on passing amount n to the plural-forms rule for the language and formats it with the given args. Note that it expects the default language to only have 2 plural forms, but translations can have any amount of plural forms. If the translation cannot be found the default text or pluralText is returned.

The text and pluralText can contain format items in format {<name>} where <name> can be letters, numbers and underscore. The format items must have a unique name. If there are duplicates the last format item wins. If the format item does not exist it will remain.

tn translations 1 "Apple" "Apples" []


tn translations 1 "{amount} apple" "{amount} apples" [ ( "amount", "1" ) ]


tn translations 5 "{amount} apple" "{amount} apples" [ ( "amount", "5" ) ]
tp : Translations -> String -> String -> List ( String, String ) -> String

Returns the translation of the given text and formats it with the given args. The context is used to indicate to the translator that text requires a particular translation. Only use contexts when the translation depends on the context such that the same text is normally only translated once. Note empty context is different from no context. If the translation cannot be found the default text is returned.

The text can contain format items in format {<name>} where <name> can be letters, numbers and underscore. The format items must have a unique name, if there are duplicates the last format item wins. If the format item does not exist it will remain.

tp translations "person" "{name} is spoiled" [ ( "name", "Jay" ) ]


tp translations "food" "Spoiled" []
tpn :
-> String
-> Int
-> String
-> String
-> List ( String, String )
-> String

Returns the translation of the given text or pluralText based on passing amount n to the plural-forms rule for the language and formats it with the given args. Note that it expects the default language to only have 2 plural forms, but translations can have any amount of plural forms. If the translation cannot be found the default text or pluralText is returned.

The context is used to indicate to the translator that text and pluralText require a particular translation. Only use contexts when the translation depends on the context such that the same text is normally only translated once. Note empty context is different from no context.

The text and pluralText can contain format items in format {<name>} where <name> can be letters, numbers and underscore. The format items must have a unique name. If there are duplicates the last format item wins. If the format item does not exist it will remain.

tpn translations "person" 1 "Is spoiled" "Are spoiled" []


tpn translations "food" 1 "{amount} is spoiled" "{amount} are spoiled" [ ( "amount", "1" ) ]


tpn translations "food" 5 "{amount} is spoiled" "{amount} are spoiled" [ ( "amount", "5" ) ]

Helpers

Create the default Translations. It defaults to language en and the English plural forms rules. It doesn't contain any translations and will use the default text and pluralText specified by the t* functions.

Takes a binary MO file and parses the file so it can be used for translations.

The MO file is required to have a Language and Plural-Forms header so we can parse it.

The language of the translations, in format ll, ll_CC or ll_CC@variant where:

  • ll is an ISO 639 two-letter language code (lowercase)
  • CC is an ISO 3166 two-letter country code (uppercase)
  • variant is a variant designator (lowercase)

See the Language header for more info.