z_trans (zotonic_core v1.0.0-rc.17)

Translate english sentences into other languages, following the GNU gettext principle.

Summary

Functions

Strict translation lookup of a language version using the languages in the context. If no translation is found or the input is undefined, then undefined is returned.

Strict translation lookup of a language version using the given language or languages. If no translation is found or the input is undefined, then undefined is returned.

Non strict translation lookup of a language version. In order check: requested languages, default configured language, english, any If no translation is found, then the empty binary string is returned.

Non strict translation lookup of a language version. In order check: requested languages, default configured language, english, any If no translation is found, then the empty binary string is returned.

Return the language that would be selected, given the context languages.

Prepare a translations table based on all .po files in the active modules. Returns a map of English sentences with all their translations

translate a string or trans record into another language. Prefer the language translations from the .po files over the translations in the trans record itself.

Fetch all translations for the given English string. If no translations are found then a trans record with the given string is returned.

Functions

lookup(Text, Context)

-spec lookup(Text, Context) -> Translation
                when
                    Text :: z:trans() | binary() | string() | undefined,
                    Context :: z:context(),
                    Translation :: binary() | undefined.

Strict translation lookup of a language version using the languages in the context. If no translation is found or the input is undefined, then undefined is returned.

lookup(Text, Language, Context)

-spec lookup(Text, Language, Context) -> Translation | undefined
                when
                    Text :: z:trans() | binary() | string() | undefined,
                    Language :: z_language:language_code() | [z_language:language_code()],
                    Context :: z:context(),
                    Translation :: binary().

Strict translation lookup of a language version using the given language or languages. If no translation is found or the input is undefined, then undefined is returned.

lookup_fallback(Text, OptContext)

-spec lookup_fallback(Text, OptContext) -> Translation
                         when
                             Text :: z:trans() | binary() | string() | list() | undefined,
                             OptContext :: z:context() | undefined,
                             Translation :: binary().

Non strict translation lookup of a language version. In order check: requested languages, default configured language, english, any If no translation is found, then the empty binary string is returned.

lookup_fallback(Text, Language, OptContext)

-spec lookup_fallback(Text, Language, OptContext) -> Translation
                         when
                             Text :: z:trans() | binary() | string() | list() | undefined,
                             Language ::
                                 z_language:language_code() | [z_language:language_code()] | binary(),
                             OptContext :: z:context() | undefined,
                             Translation :: binary().

Non strict translation lookup of a language version. In order check: requested languages, default configured language, english, any If no translation is found, then the empty binary string is returned.

lookup_fallback_language(Langs, Context)

-spec lookup_fallback_language([atom()], z:context()) -> atom().

lookup_fallback_language(Langs, Lang, Context)

-spec lookup_fallback_language([atom()], atom(), z:context()) -> atom().

lookup_fallback_languages(Available, Context)

-spec lookup_fallback_languages(Available, Context) -> Language
                                   when
                                       Available :: [atom()], Context :: z:context(), Language :: atom().

Return the language that would be selected, given the context languages.

parse_translations(Context)

-spec parse_translations(z:context()) -> map().

Prepare a translations table based on all .po files in the active modules. Returns a map of English sentences with all their translations

trans(Text, ContextOrLanguage)

-spec trans(Text, ContextOrLanguage) -> Translation
               when
                   Text :: z:trans() | binary() | string(),
                   ContextOrLanguage :: z:context() | [atom()] | atom(),
                   Translation :: binary().

translate a string or trans record into another language. Prefer the language translations from the .po files over the translations in the trans record itself.

trans(Text, Language, Context)

-spec trans(Text, Language, Context) -> Translation
               when
                   Text :: z:trans() | binary() | string(),
                   Language :: [atom()] | atom(),
                   Context :: z:context(),
                   Translation :: binary().

translations(Trans, Context)

-spec translations(z:trans() | binary() | string(), z:context()) -> z:trans().

Fetch all translations for the given English string. If no translations are found then a trans record with the given string is returned.