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
- check_usage(region: Region, source_translation: EventTranslation | PageTranslation | POITranslation) tuple[bool, int] [source]
This function checks if the attempted translation would exceed the region’s word limit
- Parameters:
region (Region) – region for which to check usage
source_translation (EventTranslation | (PageTranslation | POITranslation)) – single content object
- Returns:
translation would exceed limit, region budget, attempted translation word count
- Return type:
- 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.
Word Count
- integreat_cms.core.utils.word_count.word_count(translation: EventTranslation | PageTranslation | POITranslation) int [source]
This function counts the number of words in a content translation
- Parameters:
translation (EventTranslation | (PageTranslation | POITranslation))
- Return type: