Utils
This package contains utilities shared among all Django apps
Decorators
This file contains decorators that are used in core.
Machine Translation API Client
This module contains utilities for machine translation API clients
- class integreat_cms.core.utils.machine_translation_api_client.MachineTranslationApiClient(request: HttpRequest, form_class: ModelFormMetaclass)[source]
Bases:
ABC
A base class for API clients interacting with machine translation APIs
- Parameters:
request (HttpRequest)
form_class (ModelFormMetaclass)
- __init__(request: HttpRequest, form_class: ModelFormMetaclass) None [source]
Constructor initializes the class variables
- Parameters:
region – The current region
form_class (ModelFormMetaclass) – The
CustomContentModelForm
subclass of the current content typerequest (HttpRequest)
- Return type:
None
- alert_exceeds_limit() None [source]
Add messages alerting the user that machine translation failed due to insufficient translation budget
- Return type:
None
- alert_failed_translations() None [source]
Add messages informing the user about failed translations
- Return type:
None
- alert_insufficient_hix_score() None [source]
Add messages alerting the user that machine translation failed due to insufficient HIX scores
- Return type:
None
- alert_no_source_translation() None [source]
Add messages alerting the user that machine translation failed due to missing source translations
- Return type:
None
- alert_successful_translations() None [source]
Add messages informing the user about successful translations
- Return type:
None
- failed_because_exceeds_limit: list[str] = [][source]
Content objects untranslatable due to insufficient translation budget
- failed_because_insufficient_hix_score: list[str] = [][source]
Content objects untranslatable due to too-low hix score
- failed_because_no_source_translation: list[str] = [][source]
Content objects untranslatable due to missing source translations
- filter_exceeds_limit() None [source]
This method removes content objects from the main queryset if translating them would exceed the translation budget.
The removed elements are stored in order to show users batched error messages after all objects have been handled.
- Parameters:
source_language – The source language slug
- Return type:
None
- filter_insufficient_hix_score() None [source]
This method removes content objects from the main queryset if they do not have the required HIX score.
The removed elements are stored in order to show users batched error messages after all objects have been handled.
- Parameters:
source_language – The source language slug
- Return type:
None
- filter_no_source_translation() None [source]
This method removes content objects from the main queryset if they do not have the required source translation.
The removed elements are stored in order to show users batched error messages after all objects have been handled.
- Parameters:
source_language – The source language slug
- Return type:
None
- form_class: ModelFormMetaclass[source]
- abstract static get_target_language_key(target_language: Language) str [source]
This function decides the correct target language key Needs to be implemented by subclasses of MachineTranslationApiClient.
- abstract invoke_translation_api() None [source]
Translate all content objects stored in self.queryset. Needs to be implemented by subclasses of MachineTranslationApiClient.
- Return type:
None
- mark_successful(content_object: Event | Page | POI) None [source]
Mark a content object as having been translated successfully
- mark_unsuccessful(content_object: Event | Page | POI, errors: bool) None [source]
Mark a translation as unuccessfull (usually due to API errors)
- prepare_content_objects() None [source]
Prepare the content objects to be translated by annotating them with information which otherwise would need to be recalculated multiple times.
- Return type:
None
- request: HttpRequest[source]
The current request
- reset() None [source]
A single instance of a MachineTranslationApiClient may be used multiple times in succession, requiring a reset of the stored results and failures.
Forgetting to call this function will not result in additional machine translation budget use, but will produce nonsense messages shown to the user.
- Return type:
None
- save_translation(content_object: Event | Page | POI, translation_data: dict) None [source]
Create a translation form based on the extracted content object data, save it, and validate the translation.
- translate_object(obj: Event | Page | POI, language_slug: str) None [source]
This function translates one content object
Machine Translation Provider
This module contains utilities for machine translations
- class integreat_cms.core.utils.machine_translation_provider.MachineTranslationProvider[source]
Bases:
object
A base class for machine translation providers. It should be used as static class, without instantiating it.
- classmethod is_enabled(region: Region, language: Language) bool [source]
Whether this provider is enabled for a given region and language. Call this from the parent class.
- is_needed(queryset: QuerySet[Event | Page | POI], target_language: Language) list[Event | Page | POI] [source]
Checks if a machine translation is needed, thus checking if the translation status is UP_TO_DATE or MACHINE_TRANSLATED and then returns a lit of translations which are to be updated
- static is_permitted(region: Region, user: SimpleLazyObject, content_type: ModelBase) bool [source]
Checks if a machine translation is permitted, i.e. if for the given region, MT of the given content type is allowed and MT into the target language is enabled for the requesting user.
Strtobool
General utility functions that are used by multiple modules within our project.