Skip to content

Commit a0e3eee

Browse files
committed
fix: handle missing msgfmt command by falling back to polib for PO to MO compilation
1 parent 032e908 commit a0e3eee

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

apps/common/locale/manager.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,14 @@ def _compile_po_to_mo(po_file: str):
223223
"""编译 PO 文件为 MO 文件"""
224224
mo_file = po_file[:-3] + ".mo"
225225
os.makedirs(os.path.dirname(mo_file), exist_ok=True)
226-
subprocess.run(["msgfmt", po_file, "-o", mo_file], check=True)
226+
227+
try:
228+
subprocess.run(["msgfmt", po_file, "-o", mo_file], check=True)
229+
except FileNotFoundError:
230+
import polib
231+
po = polib.pofile(po_file)
232+
po.save_as_mofile(mo_file)
233+
logger.info(f"Compiled {po_file} to {mo_file} using polib")
227234

228235
@staticmethod
229236
def _reload_django_mo(lang_code: str = None):

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ dependencies = [
6363
"cohere==5.17.0",
6464
"jsonpath-ng==1.8.0",
6565
"markdownify==1.2.2",
66+
"polib==1.2.0",
6667
]
6768

6869
[tool.uv]

0 commit comments

Comments
 (0)