[英]Django doesn't create translation .po files
I have my translation strings only in templates (stored in the project_dir/Templates), I tried running the $ django-admin.py createmessages -l ru
both in the project root directory and in the app directories that use templates with trans.我的翻译字符串仅在模板中(存储在 project_dir/Templates 中),我尝试在项目根目录和使用模板和 trans 的应用程序目录中运行
$ django-admin.py createmessages -l ru
。 strings.字符串。 It created folders locale/ru/LC_MESSAGES but the folders were empty.
它创建了文件夹 locale/ru/LC_MESSAGES 但文件夹是空的。 I tried to add the django.po files manually (with the syntax mentioned in the l10n docs).
我尝试手动添加 django.po 文件(使用l10n文档中提到的语法)。 And ran the createmessages -a and compilemessages commands.
并运行 createmessages -a 和 compilemessages 命令。 It created the .mo files, but the translations didn't appear in the browser.
它创建了 .mo 文件,但翻译没有出现在浏览器中。
did you try :你试过了吗 :
python manage.py makemessages -a
from project root and app ?从项目根和应用程序?
this should create a .po that you have to edit.这应该会创建一个您必须编辑的 .po。 be sure to remove 'fuzzy' stuff everywhere.
一定要删除到处都是“模糊”的东西。
then :然后 :
python manage.py compilemessages
You need to restart the server您需要重新启动服务器
For newer versions of Django (eg 3.2):对于较新版本的 Django(例如 3.2):
in the root directory create folder "locale"在根目录中创建文件夹“locale”
run command django-admin makemessages -l ru
运行命令
django-admin makemessages -l ru
update your language files (located in the locale folder)更新您的语言文件(位于语言环境文件夹中)
run django-admin compilemessages
运行
django-admin compilemessages
Configure the LOCALE_PATHS in settings.py, otherwise you won't see the translations:在settings.py中配置LOCALE_PATHS,否则看不到翻译:
LOCALE_PATHS = [os.path.join(BASE_DIR, 'locale')]
LANGUAGE_CODE = 'ru'
To fix empty po files:修复空的 po 文件:
locale
directory in your templates
directory and add its path to the LOCALE_PATHS
list.templates
目录中添加locale
目录并将其路径添加到LOCALE_PATHS
列表。 (Optional, but helpful to make sure that the template directory is included in step 4) django-admin makemessages -l ru
django-admin makemessages -l ru
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.