mirror of https://github.com/zulip/zulip.git
compilemessages: Switch to canonical override_language().
This commit is contained in:
parent
536bd3188e
commit
812af977d3
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue