Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compilemessages: Switch to canonical override_language().

Alex Vandiver812af977d389
diff --git a/zerver/lib/i18n.py b/zerver/lib/i18n.py
index 9c6d33c0a15..8587733915d 100644
--- a/zerver/lib/i18n.py
+++ b/zerver/lib/i18n.py
@@ -7,21 +7,8 @@ from typing import Any, Dict, List
import orjson
from django.conf import settings
-from django.utils import translation
-from django.utils.translation import ugettext as _
-def with_language(string: str, language: str) -> str:
- """
- This is an expensive function. If you are using it in a loop, it will
- make your code slow.
- """
- old_language = translation.get_language()
- translation.activate(language)
- result = _(string)
- translation.activate(old_language)
- return result
-
@lru_cache()
def get_language_list() -> List[Dict[str, Any]]:
path = os.path.join(settings.DEPLOY_ROOT, 'locale', 'language_name_map.json')
diff --git a/zerver/management/commands/compilemessages.py b/zerver/management/commands/compilemessages.py
index f1de9273300..e7056894473 100644
--- a/zerver/management/commands/compilemessages.py
+++ b/zerver/management/commands/compilemessages.py
@@ -10,10 +10,10 @@ from django.conf import settings
from django.conf.locale import LANG_INFO
from django.core.management.base import CommandParser
from django.core.management.commands import compilemessages
+from django.utils.translation import override as override_language
+from django.utils.translation import ugettext as _
from django.utils.translation.trans_real import to_language
-from zerver.lib.i18n import with_language
-
class Command(compilemessages.Command):
@@ -127,7 +127,8 @@ class Command(compilemessages.Command):
# Fallback to getting the name from PO file.
filename = self.get_po_filename(locale_path, locale)
name = self.get_name_from_po_file(filename, locale)
- name_local = with_language(name, code)
+ with override_language(code):
+ name_local = _(name)
info['name'] = name
info['name_local'] = name_local