Module z_language

Mandatory background read on language tags: [1].

Description

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.

Data Types

language()

language() = language_code() | binary() | string()

language_code()

language_code() = atom()

Function Index

acceptable_languages/1
all_languages/0List of language data.
available_translations/1Fetch the available translations by checking for all .po files in zotonic_core.
default_language/1Returns the configured default language for this server; if not set, 'en' (English).
editable_language_codes/1Return list of languages enabled in the user interface.
editable_languages/1Get the list of configured languages that are editable.
enabled_language_codes/1Return list of languges enabled in the user interface.
enabled_languages/1Get the list of configured languages that are enabled.
english_name/1Returns the English language name.
fallback_language/1Return the list of fallback languages (atoms) for the language.
fallback_language/2Return the fallback language (the base language); if no fallback language is found, returns the default language.
initialize_config/1Initialize the i18n language configurations.
is_language_editable/2Check if a language code is allowed to be edited.
is_language_enabled/2Check if a language code is allowed to be used as an user selectable language for the interface.
is_rtl/1Check if the given language is a rtl language.
is_valid/1Check if the language code code is a valid language.
language_config/1Get the list of configured languages.
language_list/1Return the currently configured list of languages.
local_name/1Returns the local language name.
main_languages/0Map of language data of main languages.
properties/1Returns a list of properties from a language item retrieved from *all* languages.
set_language_config/2Save a new language config list.
to_language_atom/1Translate a language-code to an atom; only return known codes.

Function Details

acceptable_languages/1

acceptable_languages(Context::z:context()) -> [{binary(), [binary()]}]

all_languages/0

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.

available_translations/1

available_translations(Context::z:context()) -> [atom()]

Fetch the available translations by checking for all .po files in zotonic_core

default_language/1

default_language(Context::z:context() | undefined) -> language_code()

Returns the configured default language for this server; if not set, 'en' (English).

editable_language_codes/1

editable_language_codes(Context::z:context()) -> [language_code()]

Return list of languages enabled in the user interface.

editable_languages/1

editable_languages(Context::z:context()) -> [atom()]

Get the list of configured languages that are editable.

enabled_language_codes/1

enabled_language_codes(Context::z:context()) -> [language_code()]

Return list of languges enabled in the user interface.

enabled_languages/1

enabled_languages(Context::z:context()) -> [atom()]

Get the list of configured languages that are enabled.

english_name/1

english_name(Code::language()) -> binary() | undefined

Returns the English language name.

fallback_language/1

fallback_language(Code::language()) -> [language_code()]

Return the list of fallback languages (atoms) for the language.

fallback_language/2

fallback_language(Code::language() | undefined, Context::z:context()) -> language_code()

Return the fallback language (the base language); if no fallback language is found, returns the default language.

initialize_config/1

initialize_config(Context::z:context()) -> ok

Initialize the i18n language configurations

is_language_editable/2

is_language_editable(Code::language(), Context::z:context()) -> boolean()

Check if a language code is allowed to be edited. This is a superset of the enabled languages.

is_language_enabled/2

is_language_enabled(Code, Context) -> any()

Check if a language code is allowed to be used as an user selectable language for the interface.

is_rtl/1

is_rtl(Code::language()) -> boolean()

Check if the given language is a rtl language.

is_valid/1

is_valid(Code::language()) -> boolean()

Check if the language code code is a valid language.

language_config/1

language_config(Context::z:context()) -> [{atom(), boolean()}]

Get the list of configured languages.

language_list/1

language_list(Context::z:context()) -> [{language_code(), list()}]

Return the currently configured list of languages

local_name/1

local_name(Code::language()) -> binary() | undefined

Returns the local language name.

main_languages/0

main_languages() -> map()

Map of language data of main languages.

properties/1

properties(Code::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.

set_language_config/2

set_language_config(NewConfig::list(), Context::z:context()) -> ok

Save a new language config list

to_language_atom/1

to_language_atom(Code::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'


Generated by EDoc