I have installed and configured rosetta
on my Django
project and I can say it is working because I can see multi-language features with Django admin
and I can see strings to translate in third party
and django
tabs, but when a chose project
tab I get this message:
Nothing to translate!
You haven't specified any languages in your settings file, or haven't yet generated a batch of translation catalogs.
Please refer to Django's I18N documentation for a guide on how to set up internationalization for your project.
我已经gettext()
在我的代码中使用过,但在rosetta
.
这是gettext()
在 my中使用的示例models.py
:
from django.utils.translation import gettext as _
class Hotel(models.Model):
ONE_STAR = '*'
TWO_STARS = '**'
THREE_STARS = '***'
FOUR_STARS = '****'
FIVE_STARS = '****'
GRAND_TOURISM = 'GRAND_TOURISM'
NA = 'NA'
SPECIAL = 'SPECIAL'
ECO = 'ECO'
BOUTIQUE = 'BOUTIQUE'
HOTEL_CATEGORY_CHOICES = (
(ONE_STAR, _('*')),
(TWO_STARS, _('**')),
(THREE_STARS, _('***')),
(FOUR_STARS, _('****')),
(FIVE_STARS, _('*****')),
(GRAND_TOURISM, _('Grand Tourism')),
(NA, _('NA')),
(SPECIAL, _('Special')),
(ECO, _('Eco-Hotel')),
(BOUTIQUE, _('Boutique-Hotel'))
)
这是语言的配置settings.py
:
LOCALE_PATHS = (
os.path.join(BASE_DIR, 'locale'),
)
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
LANGUAGE_CODE = 'en-us'
gettext = lambda s: s
LANGUAGES = (
('en', gettext('English')),
('de', gettext('German')),
('es', gettext('Spanish')),
)
USE_I18N = True
我不知道我错过了什么。