即使使用LOCALE

编程入门 行业动态 更新时间:2024-10-09 15:17:03
本文介绍了即使使用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

本文发布于:2023-10-26 06:52:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529398.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LOCALE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!