z_language (zotonic_core v1.0.0-rc.11)

Mandatory background read on language tags: [1].

Some quotes from [1]:

The golden rule when creating language tags is to keep the tag as short as possible. Avoid region, script or other subtags except where they add useful distinguishing information. For instance, use 'ja' for Japanese and not 'ja-JP', unless there is a particular reason that you need to say that this is Japanese as spoken in Japan, rather than elsewhere.

The entries in the registry follow certain conventions with regard to upper and lower letter-casing. For example, language tags are lower case, alphabetic region subtags are upper case, and script tags begin with an initial capital. This is only a convention!

Note that we use lower case subtags in subtag identifiers and URLs.

Language+extlang combinations are provided to accommodate legacy language tag forms, however, there is a single language subtag available for every language+extlang combination. That language subtag should be used rather than the language+extlang combination, where possible. For example, use 'yue' rather than 'zh-yue' for Cantonese, and 'afb' rather than 'ar-afb' for Gulf Arabic, if you can.

Link to this section Summary

Functions

List of language data. Returns a flattened list of property lists; sub-languages are added to the list of main languages. For each language a property list is returned - see properties/1.
Fetch the available translations by checking for all .po files in zotonic_core
Returns the configured default language for this server; if not set, 'en' (English).
Return list of languages enabled in the user interface.
Get the list of configured languages that are editable.
Return list of languges enabled in the user interface.
Get the list of configured languages that are enabled.
Returns the English language name.
Return the list of fallback languages (atoms) for the language.
Return the fallback language (the base language); if no fallback language is found, returns the default language.
Initialize the i18n language configurations
Check if a language code is allowed to be edited. This is a superset of the enabled languages.
Check if a language code is allowed to be used as an user selectable language for the interface.
Check if the given language is a rtl language.
Check if the language code code is a valid language.
Get the list of configured languages.
Return the currently configured list of languages
Returns the local language name.
Map of language data of main languages.
Returns a list of properties from a language item retrieved from *all* languages. Proplists key: language code - this is the ISO 639-1 language code or otherwise the ISO 639-3, combined with region or script extension (lowercase). Properties: - name: native language name. - name_en: English language name. - language: base language; functions as fallback language if translation is not available for the sub-language - region (only for region variations): Alpha-2 code of country/region (ISO 3166-2). - script (only for script variations): 4-letter script code (ISO 15924); if omitted: Latn. - direction: (if omitted: LTR) or RTL.
Save a new language config list
Translate a language-code to an atom; only return known codes. Also map aliased language codes to their preferred format. Eg. 'zh-tw' to 'zh-hant'

Link to this section Types

-type language() :: language_code() | binary() | string().
Link to this type

language_code/0

-type language_code() :: atom().

Link to this section Functions

Link to this function

acceptable_languages(Context)

-spec acceptable_languages(z:context()) -> [{binary(), [binary()]}].
Link to this function

all_languages()

-spec all_languages() -> map().
List of language data. Returns a flattened list of property lists; sub-languages are added to the list of main languages. For each language a property list is returned - see properties/1.
Link to this function

available_translations(Context)

-spec available_translations(z:context()) -> [atom()].
Fetch the available translations by checking for all .po files in zotonic_core
Link to this function

default_language(Context)

-spec default_language(z:context() | undefined) -> language_code().
Returns the configured default language for this server; if not set, 'en' (English).
Link to this function

editable_language_codes(Context)

-spec editable_language_codes(z:context()) -> [language_code()].
Return list of languages enabled in the user interface.
Link to this function

editable_languages(Context)

-spec editable_languages(z:context()) -> [atom()].
Get the list of configured languages that are editable.
Link to this function

enabled_language_codes(Context)

-spec enabled_language_codes(z:context()) -> [language_code()].
Return list of languges enabled in the user interface.
Link to this function

enabled_languages(Context)

-spec enabled_languages(z:context()) -> [atom()].
Get the list of configured languages that are enabled.
Link to this function

english_name(Code)

-spec english_name(language()) -> binary() | undefined.
Returns the English language name.
Link to this function

fallback_language(Code)

-spec fallback_language(language()) -> [language_code()].
Return the list of fallback languages (atoms) for the language.
Link to this function

fallback_language(Code, Context)

-spec fallback_language(language() | undefined, z:context()) -> language_code().
Return the fallback language (the base language); if no fallback language is found, returns the default language.
Link to this function

initialize_config(Context)

-spec initialize_config(z:context()) -> ok.
Initialize the i18n language configurations
Link to this function

is_language_editable(Code, Context)

-spec is_language_editable(language(), z:context()) -> boolean().
Check if a language code is allowed to be edited. This is a superset of the enabled languages.
Link to this function

is_language_enabled(Code, Context)

Check if a language code is allowed to be used as an user selectable language for the interface.
-spec is_rtl(language()) -> boolean().
Check if the given language is a rtl language.
-spec is_valid(language()) -> boolean().
Check if the language code code is a valid language.
Link to this function

language_config(Context)

-spec language_config(z:context()) -> [{atom(), boolean()}].
Get the list of configured languages.
Link to this function

language_list(Context)

-spec language_list(z:context()) -> [{language_code(), list()}].
Return the currently configured list of languages
Link to this function

local_name(Code)

-spec local_name(language()) -> binary() | undefined.
Returns the local language name.
Link to this function

main_languages()

-spec main_languages() -> map().
Map of language data of main languages.
Link to this function

properties(Code)

-spec properties(language()) -> map() | undefined.
Returns a list of properties from a language item retrieved from *all* languages. Proplists key: language code - this is the ISO 639-1 language code or otherwise the ISO 639-3, combined with region or script extension (lowercase). Properties: - name: native language name. - name_en: English language name. - language: base language; functions as fallback language if translation is not available for the sub-language - region (only for region variations): Alpha-2 code of country/region (ISO 3166-2). - script (only for script variations): 4-letter script code (ISO 15924); if omitted: Latn. - direction: (if omitted: LTR) or RTL.
Link to this function

set_language_config(NewConfig, Context)

-spec set_language_config(list(), z:context()) -> ok.
Save a new language config list
Link to this function

to_language_atom(Code)

-spec to_language_atom(language()) -> {ok, language()} | {error, not_a_language}.
Translate a language-code to an atom; only return known codes. Also map aliased language codes to their preferred format. Eg. 'zh-tw' to 'zh-hant'