Skip to content

Commit

Permalink
Add option to disable key translation
Browse files Browse the repository at this point in the history
  • Loading branch information
tibue99 committed Feb 6, 2025
1 parent 7a876a9 commit 9440f82
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions ezcord/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,8 @@ class I18N:
ignore_discord_ids:
Whether to not localize numbers that could be a Discord ID. Default to ``True``.
This only has an effect if ``localize_numbers`` is set to ``True``.
do_not_localize:
If a key starts with this string, it will not be localized. Defaults to ``".."``.
exclude_methods:
Method names to exclude from the search of keys in the language file.
disable_translations:
Expand All @@ -349,6 +351,7 @@ class I18N:
prefer_user_locale: bool = False
localize_numbers: bool
ignore_discord_ids: bool
do_not_localize: str = ".."
exclude_methods: list[str] | None

_general_values: dict = {} # general values for the current localization
Expand All @@ -368,6 +371,7 @@ def __init__(
prefer_user_locale: bool = False,
localize_numbers: bool = True,
ignore_discord_ids: bool = True,
do_not_localize: str = "..",
exclude_methods: list[str] | None = None,
disable_translations: (
list[
Expand Down Expand Up @@ -410,6 +414,7 @@ def __init__(
if not exclude_methods:
exclude_methods = []
I18N.exclude_methods = exclude_methods
I18N.do_not_localize = do_not_localize
I18N._custom_language_settings = language_settings

if not disable_translations:
Expand Down Expand Up @@ -594,6 +599,9 @@ def _get_text(
) -> str:
"""Looks for the specified key in different locations of the language file."""

if key.startswith(I18N.do_not_localize):
return key.replace(I18N.do_not_localize, "", 1)

file_name, method_name, class_name = I18N.get_location()

lookups: list[list | tuple]
Expand Down

0 comments on commit 9440f82

Please sign in to comment.