Can't see my project's strings in Django Rosetta

1k Views Asked by At

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.

I have already used gettext() in my code but I can't see those strings in rosetta.

This is an example of the use of gettext() in 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'))
    )

This is the configuration of languages in 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

I don't know what I am missing.

1

There are 1 best solutions below

0
On

Developers should know that when you are adding a language's region or specific written script form, your command for making the messages must use "_" (underscore) as the region separator and your project's settings.py must use the "-" (hyphen) as the region separator.

For example, let's say we are adding the "UK" version of English, both Traditional and Simplified Chinese, and the Hong Kong region for Chinese (Cantonese). Here are the commands to create the language translation files:

$ django-admin makemessages -l en_uk
$ django-admin makemessages -l zh_hk
$ django-admin makemessages -l zh_hans
$ django-admin makemessages -l zh_hant

And the project's settings.py needs the LANGUAGES tuple to contain them using the hyphen:

LANGUAGES = (
    ('en-uk', _('English (UK)')),
    ('zh-hk', _('Cantonese')),
    ('zh-hans', _('Chinese (Simplified)')),
    ('zh-hant', _('Chinese (Traditional)')),
)