我将我的配置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
在其文件夹中具有另一个文件夹结构:
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
并且仍然是葡萄牙语文本。
我在我的项目基本路径上创建文件夹区域设置django-admin.py make messages -l pt_br
并运行en_us
和配置.po
文件,en_us
如下所示:
# 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"
有人可以帮我弄清楚为什么它不起作用吗?这是我第一次使用国际化服务。
提前致谢!