如何检查django i18n翻译与一个更明亮?

时间:2022-12-02 07:40:23

I have the very first experience of using django i18n. I've done the following steps:

我有使用django i18n的第一次经历。我已经完成了以下步骤:

Added to settings.py:

添加到settings.py:

USE_TZ = True    
USE_I18N = True
USE_L10N = True    
LANGUAGE_CODE = 'en'    
LANGUAGES = (
    ('ru', _('Russian')),
    ('en', _('English')),
)    
ugettext = lambda s: s    
LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

template:

模板:

{% blocktrans %}WTS{% endblocktrans %}

console:

安慰:

./env/bin/django-admin.py makemessages -l ru
./env/bin/django-admin.py makemessages -l ru

.po file:

.po文件:

msgid "WTS"
msgstr "ВИС"

console:

安慰:

./env/bin/django-admin.py compilemessages

Now I want to check translation. I'm using firefox browser that sends request.META['LANG'] as 'en_US.utf8' and I get only original content of blocktrans. How to check translations and what I forgout to implement before testing?

现在我想检查翻译。我正在使用firefox浏览器将request.META ['LANG']作为'en_US.utf8'发送,我只获得blocktrans的原始内容。在测试之前如何检查翻译以及我要执行的内容?

1 个解决方案

#1


1  

A very rough workaround: add translation.activate(user_language) code to your view, where user_language - required locale (e.g.: user_language = 'ru').

一个非常粗略的解决方法:将translation.activate(user_language)代码添加到您的视图中,其中user_language - 必需的区域设置(例如:user_language ='ru')。

For a solid solution - implement code for switching languages or play with browser's locale settings.

对于可靠的解决方案 - 实现切换语言的代码或使用浏览器的区域设置。

See more details here: https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#how-django-discovers-language-preference

在此处查看更多详细信息:https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#how-django-discovers-language-preference

#1


1  

A very rough workaround: add translation.activate(user_language) code to your view, where user_language - required locale (e.g.: user_language = 'ru').

一个非常粗略的解决方法:将translation.activate(user_language)代码添加到您的视图中,其中user_language - 必需的区域设置(例如:user_language ='ru')。

For a solid solution - implement code for switching languages or play with browser's locale settings.

对于可靠的解决方案 - 实现切换语言的代码或使用浏览器的区域设置。

See more details here: https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#how-django-discovers-language-preference

在此处查看更多详细信息:https://docs.djangoproject.com/en/1.8/topics/i18n/translation/#how-django-discovers-language-preference