在 Django 中管理单独的翻译文件 (.po)

nob*_*beh 5 django translation gettext internationalization

我不是Python或的专家gettext utilities。我有一个 Django 项目,其中应用程序中有几个模块。我需要为.po将在时间部署中合并的每个模块维护单独的翻译文件。例如,在Dictionary模块旁边有一个模块django-cms-2,我想为这两个模块创建不同的.po文件(例如dict.podjango-cms-master.po)。然后,我将使用msgmergeand compilemessagesfromgettext和 Django 创建最终django.mo文件。有什么我需要的解决方案吗?

luo*_*pio 3

这是我将 locale/LOCALE_CODE/ 下的多个 .po 文件合并到 locale/LOCALE_CODE/LC_MESSAGES/django.po 的快速技巧

#!/bin/bash

# quick hack to merge all .po-files found under ./locale/LOCALE/
# to a django.po-file and then compile the django.po to django.mo

for l in locale/*
do
    bn=$(basename $l)
    echo "translating locale $bn"
    cat $l/*.po > $l/LC_MESSAGES/django.po
    python manage.py compilemessages -l $bn
done
Run Code Online (Sandbox Code Playgroud)