简体   繁体   English

python django translation .po和.mo文件未翻译文件

[英]python django translation .po and .mo file not translating the files

I am trying to create a project using for 2 languages german and English 我正在尝试创建一个使用2种语言的德语和英语项目

My Settings File 我的设置文件

  LOCALE_PATHS = (os.path.join(BASE_DIR, 'app /locale'),)

MIDDLEWARE = (
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',
)

How I am running this tool 我如何运行此工具

python manage.py makemessages -a 
This tool runs in debug mode
processing locale en
processing locale de
python manage.py compilemessages
This tool runs in debug mode
processing file django.po in app/locale/de/LC_MESSAGES
processing file django.po in app/locale/en/LC_MESSAGES

File Location app_ac/locale/de/LC_MESSAGES 文件位置app_ac / locale / de / LC_MESSAGES

-rw-rw-r--. 1 root root 421 May 11 11:44 django.mo
-rw-rw-r--. 1 root root 44K May 11 11:43 django.po

I am not getting the desired translations, I feel might be something is going wrong in .mo file as the size is just 421bytes as comparted to .po file which is 44Kb 我没有得到所需的翻译,我觉得.mo文件可能出了问题,因为与.po文件相比,大小仅为421bytes,它是44Kb

EDIT 1 编辑1

I have just figured out that in django.po file 我刚刚在django.po文件中弄清楚了

The file looks like this 该文件看起来像这样

#: project/settings.py:184
msgid "German"
msgstr ""

#: project/settings.py:185
msgid "English"
msgstr ""

Instead of (What would ideally be, Sorry for my poor German) 而不是(理想情况下,对不起我可怜的德国人)

#: .\project\settings.py:185 
msgid "German" 
msgstr "Deutsch" 

#: .\project\settings.py:186 
msgid "English" 
msgstr "Englisch" 

我只是想知道po文件中缺少翻译消息,将它们替换为适当的消息,然后运行python manage.py compilemessages命令,现在翻译就像一个魅力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django翻译创建po和mo文件,但在翻译中失败并显示翻译占位符 - Django translation creates po and mo files, but fails in translation and displays translation placeholders Django 不创建翻译 .po 文件 - Django doesn't create translation .po files 在Django翻译(.po)文件中指定版权和作者 - Specify copyright and author in Django translation (.po) file Django-自定义翻译(.mo文件)字符串不起作用 - Django - custom translation (.mo file) strings doesn't work Django 翻译文件 - 将旧版翻译集成到 .po 文件中 - Django Translation Files - Integrating legacy translations into .po files 如何将gettext .mo文件转换为.po文件 - How to convert gettext .mo file into .po file 如何在 Windows 上安装 gnu gettext (>0.15)? 所以我可以在 Django 中生成 .po/.mo 文件 - How to install gnu gettext (>0.15) on windows? So I can produce .po/.mo files in Django 当django从.po和.mo文件明确转换时,gettext的用途是什么? - What is the use of gettext when django explicitly translates from .po and .mo files? Django:如何在django管理区域中添加/删除/更新翻译短语(在po文件中)? - Django : How to add/remove/update translation phrases (in po files) in django admin area? 为什么Python gettext模块需要编译步骤(.po-> .mo)? - Why does the Python gettext module require a compilation step (.po -> .mo)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM