如何安装翻译“.po”在 Django 应用程序中?
几天前,我完成了为我的母语 (pt_BR) 创建 Django-LFS (Lightning Fast Shop) 的翻译文件。现在已经完成了,我需要安装在 Transifex 中完成翻译后下载的“.po”文件。
好的,我下载了该文件,但现在我需要安装它,我只是不知道如何安装。我尝试使用“bin/djangocompilemessages-a”将文件放入“lfs-installer”文件夹中,尝试了相同的操作,但文件位于许多不同的文件夹中,但我无法让我的LFS使用我的翻译文件。 ..
有谁知道如何使翻译包在 lfs 上工作吗?或者我做错了什么?
谢谢
I finished a few days ago, creating a translation file for Django-LFS (Lightning Fast Shop) for my native language (pt_BR). Now that it's done, I need to install the ".po" file that I downloaded after finishing my translation in Transifex.
Ok, I downloaded the file, but now that I need to install it, I just can't figure how. I tried putting the file in 'lfs-installer' folder, using "bin/django compilemessages -a", tried the same thing but with the file in many different folders, but I just can't make my LFS use my translation file...
Does anyone know how to make a translation package work on lfs? Or am I doing something wrong?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将您的 .po 文件放在路径中:
并运行
django-admin makemessages -a
put you .po file in the path:
and run
django-admin makemessages -a
如果您还没有,请创建一个名为 Locale 的文件夹。然后在您的 settings.py 文件夹中,您必须告诉它在哪里可以找到区域设置路径。像这样的事情:
还要确保您的中间件中有区域设置中间件...
既然我为您指出了正确的方向,您可能可以有效地跟踪语法和细节。
设置完这些内容后,您可以运行 makemessage -a 命令,该命令将在您的语言环境文件夹中为您输入的 -a 创建一个文件夹。然后您可以浏览到该文件夹,在其中应该有一个 .po 文件(可能没有)。如果没有,只需将您制作的 .po 文件放在那里即可。
然后在 CMD 中浏览到您的项目,并运行
compilemessages -a
。这应该将您的 .po 文件编译为 .mo 文件,这是翻译工作所需的文件。希望我没有疯狂偏离轨道......
If you do not already have one, create a folder called Locale. Then in your settings.py folder you must tell it where to find the locale paths. Something like this:
Also make sure you have locale middleware in your middleware...
You can probably effectively track down that syntax and specifics, now that I pointed you in the right direction.
Once you have those things set up, you can run your
makemessage -a
command, which will create a folder in your locale folder for the -a you put in. Then you can browse to this, inside it there should be a .po file (there might not be). If there is not, just put your .po file you made in there.Then browse to your project in your CMD, and run
compilemessages -a
. This should compile your .po files into .mo files, the files necessary for translations to work.Hopefully I did not go crazy off-track...
我使用以下设置使其正常工作:
然后在 settings.py 文件夹旁边创建一个
locale
文件夹并遵循 Django 官方说明。django.po
文件所需的路径是:locale/pt_BR/LC_MESSAGES/django.po
。之后,使用compilemessages
工具并重新启动服务器。它应该有效。
提示: django-lfs 使用
locale
模块来处理货币显示,但是 locale 模块存在一个错误,导致其显示1234,00 R$ 而不是
R$ 1234,00
。如果它咬了你,请将以下内容放入你的settings.py
中:祝你好运。
I made it to work using the following settings:
Than create a
locale
folder aside of the settings.py folder and follow Django official instructions. The desired path for yourdjango.po
file is:locale/pt_BR/LC_MESSAGES/django.po
. After that, usecompilemessages
tool and restart the server.It should work.
Tip: django-lfs uses
locale
module to handle currency display, but there is a bug for locale module that makes it to show1234,00 R$
instead ofR$ 1234,00
. If it bites you, put the following into yoursettings.py
:Good luck.