国际化工作不正常-似乎未采取任何行动 [英] Internationalization not working properly - No action seems to be happening

查看:102
本文介绍了国际化工作不正常-似乎未采取任何行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我按如下所示配置了setting.py:

LANGUAGE_CODE = 'pt-br'

USE_I18N = True

LANGUAGES = (
    ('pt_br', ('Portugues Brasileiro')),
    ('en_us', ('English'))
)

MIDDLEWARE_CLASSES = (
    ...
    'django.middleware.locale.LocaleMiddleware',
    ...
)

LOCALE_PATHS = ('/home/lucas/Documents/ProjectPython/test_internacionalizacao/test_internacionalizacao/locale/')

创建了一个名为core的应用,该应用的文件夹中有另一个文件夹结构为:

Created an app called core that has in its folder another folder structure as:

core
---- templates
-------- core
------------ core.html
------------ idiomas.html

core.html中的代码是:

{% load i18n %}

<html>

    <head>
        <title>Internacionalização - 01</title>
    </head>

    <body>
        {% include "core/idiomas.html" %}

        <p>{% trans "Esta string será transformada para Inglês" %}</p>

    </body>

</html>

idiomas.html中的代码是:

{% load i18n %}

{% get_available_languages as LANGUAGES %}

<div class="idiomas">
    <form action="/i18n/setlang/" method="POST">
        {% csrf_token %}
        <select name="languages">
            {% for lang in LANGUAGES %}
                <option value="{{ lang.0 }}">{{ lang.1 }}</option>
            {% endfor %}
        </select>
        <input type="submit" value="{% trans "Mudar idioma" %}">
    </form>
</div>

我的urls.py是:

from django.conf.urls import patterns, include, url
from django.conf import settings

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    url(r'^$', 'core.views.core_index'),
    url(r'^admin/', include(admin.site.urls)),
    (r'^i18n/', include('django.conf.urls.i18n')),
)

当我加载页面时,它看起来还不错,但是当我将组合框更改为English时,则无济于事.似乎页面已重新加载,但组合选项又回到了Portugues Brasileiro,仍然是葡萄牙语文本.

When I load the page it looks ok, but when I change the combobox to English nothing works. Seemingly the page reloads but the combo option is back to Portugues Brasileiro and still the text in portuguese.

我在项目基本路径上创建文件夹语言环境,并运行django-admin.py make messages -l pt_bren_us,并为en_us配置.po文件,如下所示:

I create the folder locale on my projects base path and runned django-admin.py make messages -l pt_br and en_us and configued the .po file for en_us which is like this:

# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-05-12 12:29-0300\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: core/templates/core/core.html:12
msgid "Esta string será transformada para Inglês"
msgstr "This string is being converted into English"

#: core/templates/core/idiomas.html:13
msgid "Mudar idioma"
msgstr "Change Language"

有人可以帮我弄清楚为什么它不起作用吗?这是我第一次使用国际化服务.

Could someone help me to figure out why it is not working? This is the first time I am using internationalization service.

提前谢谢!

推荐答案

您是否尝试过从.po文件的标题中删除"#, fuzzy"行?无论如何,您都应该这样做以加载翻译.

have you tried removing the "#, fuzzy" line from the header of your .po file? You should do this anyway for the translations to load.

如果问题仍然存在,请在idomas.html模板中打印当前语言-类似于

If the problem persists print the current language in the idomas.html template - something like

{% get_current_language as lang %}{{lang}}

检查选择框是否实际更改了语言.如果确实如此,那么问题就出在翻译机制上.如果没有,那就是您设置语言的方式.请报告您的发现,以查看下一步可以做什么.

to check if the select box actually changes the language. If it does, the problem lies in the translations mechanism. If not, it's in the way you set the language. Please report back your findings to see what can be done next.

这篇关于国际化工作不正常-似乎未采取任何行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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