[英]Translating 'Django-Oscar'
I want to learn how to build an opensource e-commerce site.我想学习如何构建一个开源电子商务网站。 For this purpose I'm using 'Django' framework with 'Oscar' extension.
为此,我使用带有“Oscar”扩展名的“Django”框架。
I read the whole tutorial here: https://django-oscar.readthedocs.io/en/releases-1.5/index.html , where there is a Translation
tutorial.我在这里阅读了整个教程: https : //django-oscar.readthedocs.io/en/releases-1.5/index.html ,其中有一个
Translation
教程。 I followed it (must say that it has missing steps).我跟着它(必须说它缺少步骤)。 This part says that, in order to translate a page you must create two folders and a symbolic link:
这部分说,为了翻译一个页面,你必须创建两个文件夹和一个符号链接:
mkdir locale i18n
ln -s $PATH_TO_OSCAR i18n/oscar
Then, for each language you want to translate:然后,对于您要翻译的每种语言:
./manage.py makemessages --symlinks --locale=<language code>
That's correct but, besides that, you must compile .po
files in order to get the final traduction in locale
folder ( .mo
files).这是正确的,但除此之外,您必须编译
.po
文件才能获得locale
文件夹( .mo
文件)中的最终翻译。 After that you must include the traductions into settings.py
of project (or app).之后,您必须将翻译包含在项目(或应用程序)的
settings.py
中。 This is done with the following code:这是通过以下代码完成的:
$ django-admin.py compilemessages
$ django-admin.py compilemessages
In settings.py
add:在
settings.py
添加:
LANGUAGES = [ ('de', _('German')), ('en', _('English')), ('es', _('Spanish')), ] LANGUAGES = [ ('de', _('German')), ('en', _('English')), ('es', _('Spanish')), ]
( Note: This is my case, where I want to translate the store into German, Spanish and English) (注意:这是我的情况,我想将商店翻译成德语、西班牙语和英语)
After doing that, I run my server and only these three languages appear in the select language box, but when I push the button in order to translate the page, It returns the default language (English) every time, getting this in each translation petition:这样做之后,我运行我的服务器,只有这三种语言出现在选择语言框中,但是当我按下按钮以翻译页面时,它每次都返回默认语言(英语),在每个翻译请求中都得到这个:
"POST /i18n/setlang/ HTTP/1.1" 302 0
"GET / HTTP/1.1" 200 8379
Is there any step I'm skipping or anything I'm doing wrong?有没有我跳过的步骤或我做错了什么?
Thanks in advance.提前致谢。
I've got a partial (almost complete) solution.我有一个部分(几乎完整)的解决方案。 Due to languages I want to use are very common, I used Django translation middleware directly, without using the one Oscar provides.
由于我要使用的语言很常见,我直接使用了 Django 翻译中间件,没有使用 Oscar 提供的一个。 So, my solution is to edit
settings.py
by including in MIDDLEWARE
(or in MIDDLEWARE_CLASES
depending of Django version) the Django internacionalization middleware: django.middleware.locale.LocaleMiddleware
.因此,我的解决方案是通过在
MIDDLEWARE
(或MIDDLEWARE_CLASES
取决于 Django 版本)中包含 Django 国际化中间件来编辑settings.py
: django.middleware.locale.LocaleMiddleware
。
After that, without importing ugettext
( from django.utils.translation import ugettext as _
), feel free to add languages as follows:之后,不导入
ugettext
( from django.utils.translation import ugettext as _
),随意添加语言如下:
LANGUAGES = [
('es', 'Spanish'),
('de', 'German'),
('en', 'English'),
('pt-br', 'Brazilian'),
#... and so on
]
This solution doesn't need creating symbolic links or additional folders.此解决方案不需要创建符号链接或其他文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.