即使使用LOCALE_PATHS,Django翻译也不起作用 [英] Django Translation not working even with LOCALE_PATHS

查看:291
本文介绍了即使使用LOCALE_PATHS,Django翻译也不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在使用django 1.8创建必须转换为葡萄牙语的新网站。

So I'm using django 1.8 to create a new web site that has to be translated into portuguese.

因此,要使用我添加到中间件中的django自己的工具:

So to use django's own tools I added to my middlewares:

'django.middleware.locale.LocaleMiddleware',

我还添加了我的context_processors:

I also added to my context_processors:

'django.template.context_processors.i18n',

,然后我配置我的语言设置:

and the i configure my language settings:

USE_I18N = True
gettext = lambda s: s
LANGUAGE_CODE = 'en'
LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)
print LOCALE_PATHS
LANGUAGES = (
    ('pt-br', gettext('Portuguese')),
    ('en', gettext('English')),
)

TIME_ZONE = 'America/Sao_Paulo'
USE_L10N = True
USE_TZ = True

我也已在文档顶部导入:

I also have imported on the top of my document:

from django.utils.translation import ugettext as _

然后我添加了标签:

{% trans "text" %}

在我的模板上适当的文本。之后,我运行了:

on my templates with the appropriate texts. After that i ran:

python manage.py makemessages -l pt-br

然后我翻译了.po文件中的所有内容,最后用以下命令对其进行了编译:

then i translated everything on my .po file, and finally i compiled it with:

python manage.py compilemessages

但是当我运行我的网站时还是英文。
我的浏览器位于pt-br上,我也有一个有效的示例,但此特定网站未得到翻译。
我确实添加了i18n网址。

But when I ran my site it was still in english. My Browser is on pt-br, and i also have a working example but this specific site is not being translated. I did add the i18n urls.

有人可以帮助我吗?我缺少什么?

Can anybody help me out? What Am I missing?

推荐答案

因此,显然Django必须将语言环境文件夹视为pt_br而不是pt-br,但设置具有与pt-br在一起。那就是我的诀窍。

So Apparently Django has to see the locale folder as pt_br not pt-br, but the settings have to be with pt-br. That's that did the trick for me.

这篇关于即使使用LOCALE_PATHS,Django翻译也不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆