我在 django 国际化(i18n)中有问题。翻译不起作用。我的 django 版本是:1.5.4 这是我的代码:
设置.py
ugettext = lambda s:s
LANGUAGES = [
('en','English'),
('fa','Farsi'),
]
LANGUAGE_CODE = 'en_us'
USE_I18N = True
USE_L10N = True
TEMPLATE_DIRS = (
os.path.join(PROJECT_PATH,'templates'),
)
网址.py
from django.conf.urls import patterns, include, url
from main import *
urlpatterns = patterns('',
url(r'$^',index),
)
主文件
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
def index(request):
alert = _('this is my page')
return render(request,'index.html',{'alert':alert})
索引.html
{% load i18n %}
{{alert}}
进而:
$mkdir conf/locale -p
$django-admin.py makemessages -l fa
processing language fa
$django-admin.py compilemessages
processing file django.po in /home/mori/Desktop/salam/salam/locale/fa/LC_MESSAGES
django.po
# 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: 2013-10-15 13:12+0330\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"
"Plural-Forms: nplurals=1; plural=0;\n"
#: main.py:4
msgid "this is my page"
msgstr "in safeye mane"
我在中间件类中有“django.middleware.locale.LocaleMiddleware”,在 TEMPLATE_COTEXT_PROCESSORS 中有“django.core.context_processors.i18n”。
输出
this is my page
我该如何解决?