国际化不起作用,或者我不知道如何使其工作 [英] Internationalization doesn't work or I don't know how to make it work

查看:98
本文介绍了国际化不起作用,或者我不知道如何使其工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Settings.py常量

  TIME_ZONE ='欧洲/维尔纽斯'
LANGUAGE_CODE ='lt'
USE_I18N = True
USE_L10N = True
USE_TZ = True

MIDDLEWARE_CLASSES =(
'django.middleware.common.CommonMiddleware',
'django。 contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages。 middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',

如果我向中间件类添加了 LocaleMiddleware 并编辑源代码,以便打印我的区域设置,它将打印 lt 如预期的那样。



此外:



./ manage.py makemessages - l 生成文件和我翻译的文本。



./ manage.py compilemessage s 在/ Users / aemdy / PycharmProjects / rezervavau_v2 / locale / lt / LC_MESSAGES


中返回处理文件django.po

但是可惜的是,我仍然在我的网页上看到英文文本。



我使用django管理员,基本的django管理员中包含的短语被翻译密码,密码,编辑等)。仍然,我自己定义的短语显示为英文。

解决方案

嗯,我已经找到了答案。 b
$ b

我需要在 settings.py 中添加以下行:



LOCALE_PATHS =(os.path.join(os.path.dirname(__ file__),'../ locale /'),)


Settings.py constants

TIME_ZONE = 'Europe/Vilnius'
LANGUAGE_CODE = 'lt'
USE_I18N = True
USE_L10N = True
USE_TZ = True

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

If I add LocaleMiddleware to the middleware classes and edit source code so that it would print my locale, it prints lt as expected.

Moreover:

./manage.py makemessages -l lt generated the file and I translated text occurences.

./manage.py compilemessages returns processing file django.po in /Users/aemdy/PycharmProjects/rezervavau_v2/locale/lt/LC_MESSAGES

But sadly I still see english text in my pages.

I use django admin and the phrases included in the basic django admin are translated (Change password, password, edit and some others). Still, my own defined phrases are shown in english.

解决方案

Well, I have found the answer myself.

I needed to add the following line in settings.py:

LOCALE_PATHS = (os.path.join(os.path.dirname(__file__), '../locale/'),)

这篇关于国际化不起作用,或者我不知道如何使其工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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