如何安装翻译“.po”在 Django 应用程序中?

发布于 2024-12-03 03:39:25 字数 309 浏览 0 评论 0原文

几天前,我完成了为我的母语 (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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

将您的 .po 文件放在路径中:

<your_django_project>/conf/locale/pt_BR/LC_MESSAGES/

并运行
django-admin makemessages -a

put you .po file in the path:

<your_django_project>/conf/locale/pt_BR/LC_MESSAGES/

and run
django-admin makemessages -a

如何视而不见 2024-12-10 03:39:26

如果您还没有,请创建一个名为 Locale 的文件夹。然后在您的 settings.py 文件夹中,您必须告诉它在哪里可以找到区域设置路径。像这样的事情:

LOCALE_PATHS{
C:/sdalfjasd/dfalsdjkf/locale
}

还要确保您的中间件中有区域设置中间件...

既然我为您指出了正确的方向,您可能可以有效地跟踪语法和细节。

设置完这些内容后,您可以运行 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:

LOCALE_PATHS{
C:/sdalfjasd/dfalsdjkf/locale
}

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...

皓月长歌 2024-12-10 03:39:26

我使用以下设置使其正常工作:

import os
DIRNAME = os.path.dirname(__file__)

USE_I18N = True
USE_L10N = True

LANGUAGE_CODE = 'pt-br'
LANGUAGES = (
    ('pt-br', u"Português"),
)

LOCALE_PATHS = [
    DIRNAME + '/locale',
]

然后在 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 中:

# Fix for LC_MONETARY bug: http://www.sourceware.org/bugzilla/show_bug.cgi?id=1294
import locale
locale._override_localeconv.update({'p_cs_precedes': 1, 'n_cs_precedes': 1})

祝你好运。

I made it to work using the following settings:

import os
DIRNAME = os.path.dirname(__file__)

USE_I18N = True
USE_L10N = True

LANGUAGE_CODE = 'pt-br'
LANGUAGES = (
    ('pt-br', u"Português"),
)

LOCALE_PATHS = [
    DIRNAME + '/locale',
]

Than create a locale folder aside of the settings.py folder and follow Django official instructions. The desired path for your django.po file is: locale/pt_BR/LC_MESSAGES/django.po. After that, use compilemessages 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 show 1234,00 R$ instead of R$ 1234,00. If it bites you, put the following into your settings.py:

# Fix for LC_MONETARY bug: http://www.sourceware.org/bugzilla/show_bug.cgi?id=1294
import locale
locale._override_localeconv.update({'p_cs_precedes': 1, 'n_cs_precedes': 1})

Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文