kepler.api.translation_util module

The module contains utility functionality related to the database translations and session language.

class kepler.api.translation_util.SetLangParams

Bases: kepler.api.api_util.ApiParamsBase

The parameter class for the REST API calls set_session_language and set_user_language.

locale_name = The locale name of the language.
kepler.api.translation_util.add_translation(lang_id, translation, translation_id=None)

The function adds a translation to the Translation database table.

Parameters:
  • lang_id – The language to which the translation is added.
  • translation – The translation string added to the database.
  • translation_id – Optional ID for a translation that already exists in the database.
Returns:

The translation ID of the translation that was added to the database.

kepler.api.translation_util.change_session_language(request, locale_name)

The function changes the session language.

Parameters:
  • request – The Pyramid request object.
  • locale_name – The language part of the locale of the desired language.
kepler.api.translation_util.get_translated_string(translation_id, language_id)

The function returns the translated string from the database corresponding the given translation ID and language ID.

Parameters:
  • translation_id – The ID of the translation that is looked for from the translations.
  • langauge_id – The ID of the langauge the translation should be in.
Returns:

The translated string for the string or None if no translation was found.

kepler.api.translation_util.get_translation(request, translation_id)

The function returns the translation string from the database corresponding the given translation ID.

The language setting in session['lang_id'] is used as the language id of the query. If no translation for the translation_id is found for the given language, then the first found translation is returned. If no translation is found, None is returned.

Parameters:
  • request – The Pyramid request object for which the translation is needed.
  • translation_id – The ID of the translation that is looked for from the translations.
Returns:

The translation string for the current language corresponding to the translation_id.

kepler.api.translation_util.set_session_language(request)

The function implements the REST API call set_session_language.

kepler.api.translation_util.set_user_language(request)

The function implements the REST API call set_user_language.