Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jokester committed Dec 15, 2024
1 parent 64f6112 commit 98c4ed9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 1 addition & 2 deletions app/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,7 @@ def init_db(app: Flask):

TeamRole.init_system_roles()
ProjectRole.init_system_roles()
with app.app_context():
Language.init_system_languages()
Language.init_system_languages()
SiteSetting.init_site_setting()
admin_user = create_or_override_default_admin(app)
create_default_team(admin_user)
6 changes: 3 additions & 3 deletions app/models/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from mongoengine import Document, BooleanField, StringField, IntField, QuerySet

from app.exceptions.language import LanguageNotExistError
from app.translations import hardcode_text, gettext
from app.translations import hardcode_text, gettext, server_gettext
from typing import List, Any, Dict, TypedDict, Optional

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -788,7 +788,7 @@ class Language(Document):
def init_system_languages(cls) -> None:
"""初始化语言表"""
if cls.objects.count() > 0:
logger.info(gettext("Language collection already initialized."))
logger.info(server_gettext("Language collection already initialized."))
return
sort = 0
for lang in cls.SYSTEM_LANGUAGES_DATA:
Expand All @@ -802,7 +802,7 @@ def init_system_languages(cls) -> None:
sort=sort,
).save()
sort += 1
logger.debug(gettext("Initialized Language collection with %d languages"), sort)
logger.debug(server_gettext("Initialized Language collection with %d languages"), sort)

@classmethod
def create(
Expand Down
6 changes: 6 additions & 0 deletions app/translations/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask import g, request
from app.constants.locale import Locale
import flask_babel
import app.config as _app_config

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
Expand Down Expand Up @@ -57,3 +58,8 @@ def hardcode_text(msgid: str) -> str:
used to capture hardcoded string as msgid
"""
return msgid


def server_gettext(msgid: str):
with flask_babel.force_locale(_app_config.BABEL_DEFAULT_LOCALE):
return gettext(msgid)

0 comments on commit 98c4ed9

Please sign in to comment.