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
| Attribute | Type | Description |
|---|---|---|
| language | string | The language code to be activated within the context, or None to deactivate all translations. |
| deactivate | boolean = False | A flag determining whether to fully deactivate translation on exit instead of restoring the previous language. |
| old_language | string | Stores 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
| Name | Type | Description |
|---|---|---|
| language | string | The language code to activate within the context. |
| deactivate | boolean = False | A flag indicating whether to deactivate the language upon exiting the context. |
Signature
def override(
language: string,
deactivate: boolean = False
) - > null
Parameters
| Name | Type | Description |
|---|---|---|
| language | string | The language code to activate within the context, or None to deactivate all translations. |
| deactivate | boolean = False | A flag indicating whether to fully deactivate translation on exit instead of restoring the previous language. |