Module mod_translation

Translation support.

Copyright © 2010-2020 Marc Worrell, Arthur Clemens

Authors: Marc Worrell (marc@worrell.nl).

Description

Translation support. Handle the language list and manage translations.

Function Index

event/2Set the current session (and user) language, reload the user agent's page.
generate/1Generate all .po templates for the given site.
generate_core/0Generate consolidated translation file zotonic.pot for all core modules.
init/1Make sure that we have the i18n.language_list setting when the site starts up.
language_add/3Add a language to the i18n configuration.
language_delete/2Remove a language from the i18n configuration.
language_status/3Set/reset the is_enabled flag of a language.
observe_admin_menu/3
observe_dispatch_rewrite/3Grabs the language from the path parts and sets it as the page language (if that language is enabled).
observe_request_context/3Check if the user has a preferred language (in the user's config).
observe_scomp_script_render/2
observe_set_user_language/3
observe_url_rewrite/3
observe_user_context/3
set_default_language/2Set the default language.
set_language/2Set the language of the context.
set_language_url_rewrite/2Set/reset the state of the 'rewrite URL' setting.
set_user_language/2Set the language, as selected by the user.
url_strip_language/1Strip the language code from the location (if the language code is recognized).
valid_config_language/2Returns a valid language from the config language.

Function Details

event/2

event(Postback, Context) -> any()

Set the current session (and user) language, reload the user agent's page. Called from language switch. Reloads the page to reflect the new setting.

generate/1

generate(Host) -> any()

Generate all .po templates for the given site

generate_core/0

generate_core() -> ok | {error, needs_core_zotonic}

Generate consolidated translation file zotonic.pot for all core modules. Both active and inactive modules are indexed, so the generated translation files are always complete.

init/1

init(Context) -> any()

Make sure that we have the i18n.language_list setting when the site starts up.

language_add/3

language_add(NewLanguageCode::atom() | binary(), IsEnabled::boolean(), Context::z:context()) -> ok | {error, not_a_language}

Add a language to the i18n configuration

language_delete/2

language_delete(LanguageCode::atom(), Context::z:context()) -> z:context()

Remove a language from the i18n configuration

language_status/3

language_status(Code::atom(), Status::boolean() | editable, Context::z:context()) -> ok | {error, nolang | default}

Set/reset the is_enabled flag of a language.

observe_admin_menu/3

observe_admin_menu(Admin_menu, Acc, Context) -> any()

observe_dispatch_rewrite/3

observe_dispatch_rewrite(Dispatch_rewrite, Dispatch, Context) -> any()

Grabs the language from the path parts and sets it as the page language (if that language is enabled). Note that this works irrespectively of the rewrite_url setting: when rewrite_url is false and the URL includes the language, we will still read the language instead of returning a 404. For handling 'id' (which can either mean /id/PageId or the language Indonesian): if id is followed by a number, do not use it as language.

observe_request_context/3

observe_request_context(Request_context, Context, X3) -> any()

Check if the user has a preferred language (in the user's config). If not then check the accept-language header (if any) against the available languages.

observe_scomp_script_render/2

observe_scomp_script_render(Scomp_script_render, Context) -> any()

observe_set_user_language/3

observe_set_user_language(Set_user_language, Context, X3) -> any()

observe_url_rewrite/3

observe_url_rewrite(Url_rewrite, Url, Context) -> any()

observe_user_context/3

observe_user_context(User_context, Context, X3) -> any()

set_default_language/2

set_default_language(Code::atom(), Context::z:context()) -> z:context()

Set the default language.

set_language/2

set_language(Code0::atom() | binary() | string(), Context::z:context()) -> z:context()

Set the language of the context. Sets to the given language if the language exists in the config language and is enabled; otherwise tries the language's fallback language; if this fails too, sets language to the site's default language.

set_language_url_rewrite/2

set_language_url_rewrite(Value::boolean(), Context::z:context()) -> z:context()

Set/reset the state of the 'rewrite URL' setting.

set_user_language/2

set_user_language(Code::atom(), Context::z:context()) -> z:context()

Set the language, as selected by the user. Persist this choice.

url_strip_language/1

url_strip_language(Url::binary()) -> binary()

Strip the language code from the location (if the language code is recognized). For instance: <<"/nl-nl/admin/translation">> becomes <<"/admin/translation">>

valid_config_language/2

valid_config_language(Code::atom() | undefined, Context::z:context()) -> z_language:language_code() | undefined

Returns a valid language from the config language. If the language is not available or not enabled, tries the language's fallback language (retrieve from z_language); if this fails too, returns the data for the site's default language.


Generated by EDoc