Skip to main content

override

This class acts as a context manager and decorator to temporarily change the active language for a specific block of code or function. It stores the current language state upon entry and ensures the original language is restored or deactivated when the context exits. This is useful for executing localized logic in a multi-language environment without permanently altering global settings.

Attributes

AttributeTypeDescription
languagestringThe language code to be activated within the context, or None to deactivate all translations.
deactivateboolean = FalseA flag determining whether to fully deactivate translation on exit instead of restoring the previous language.
old_languagestringStores the language code that was active before entering the context to ensure it can be restored on exit.

Constructor

Signature

def override(
language: string,
deactivate: boolean = False
) - > null

Parameters

NameTypeDescription
languagestringThe language code to activate within the context.
deactivateboolean = FalseA flag indicating whether to deactivate the language upon exiting the context.

Signature

def override(
language: string,
deactivate: boolean = False
) - > null

Parameters

NameTypeDescription
languagestringThe language code to activate within the context, or None to deactivate all translations.
deactivateboolean = FalseA flag indicating whether to fully deactivate translation on exit instead of restoring the previous language.