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

5
我不是Pythongettext工具包的专家。我有一个Django项目,其中包含几个应用程序模块。 我需要为每个模块维护单独的.po翻译文件,在部署时将它们合并。例如,除了django-cms-2模块外,还有一个Dictionary模块,我想要分别使用不同的.po文件(例如dict.podjango-cms-master.po)。 然后,我将使用gettext和Django中的msgmergecompilemessages来创建最终的django.mo文件。是否有解决我所需的任何解决方案?
1个回答

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接