2010-05-09 91 views
1

我已经创建了翻译字符串。Django的国际化不起作用模板和应用程序视图

然后我跑:

django-admin.py makemessages -l it 

,并/ LC_MESSAGES/django.po已经创造了django.po文件

我现在已经翻译字符串的文件,然后我跑:

django-admin.py compilemessages 

我收到:

processing file django.po in /home/jobber/Desktop/library/books/locale/it/LC_MESSAGES 

我的settings.py看起来是这样的:

LANGUAGE_CODE = 'it' 
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth", 
"django.core.context_processors.debug", 
"django.core.context_processors.i18n", 
"django.core.context_processors.media",) 
USE_I18N = True 
MIDDLEWARE_CLASSES = ('django.middleware.common.CommonMiddleware', 
'django.middleware.locale.LocaleMiddleware', 
'django.contrib.sessions.middleware.SessionMiddleware', 
'django.contrib.auth.middleware.AuthenticationMiddleware', 
) 

但我还是经常看到英文文本。为什么?

回答

9

也许你的浏览器语言是英语。所述LocaleMiddleware尝试检测基于this algorithm的语言(即接受语言HTTP标头)。
所以,你可以删除的LocaleMiddleware避免这种情况或使用set_language redirect view

+0

哈哈你rightttttt!谢谢 :) – xRobot 2010-05-09 11:29:23

2

除了公认的答案:如果你使用Firefox,你可以安装Quick Locale Switcher测试使用不同语言的应用程序(基于浏览器的语言)。它在屏幕底部添加一个按钮,您可以轻松更改浏览器语言。