0
votes

I have a problem with my Django Translations. My Django doesn't translate my tags.

I use django-cms and in django-cms I have a plugin djangocms-blog.

Django == 1.6.5

Django-cms == 3.0.3

Djangocms-blog == 0.2b5

My transtags are not translated.

Example tag:

{% trans "read more" %}

I installed everything correctly, my settings.py contains this:

gettext = lambda s: s

# Internationalization
LANGUAGE_CODE = 'nl'
TIME_ZONE = 'Europe/Brussels'
USE_I18N = True
USE_L10N = True
USE_TZ = True

LOCALE_PATHS = (
    os.path.join(BASE_DIR, 'locale'),
)

LANGUAGES = (
    ('nl', _(u'Dutch')),
    ('fr', _(u'French')),
    ('en', _(u'English')),
)

CMS_LANGUAGES = {
    1: [
        {
            'code': 'nl',
            'name': gettext('Dutch'),
            'fallbacks': ['en', 'fr'],
            'public': True,
            'hide_untranslated': True,
            'redirect_on_fallback':False,
        },
        {
            'code': 'en',
            'name': gettext('English'),
            'fallbacks': ['nl'],
            'public': False,
            'hide_untranslated': True,
            'redirect_on_fallback':False,
        },
        {
            'code': 'fr',
            'name': gettext('French'),
            'public': False,
            'hide_untranslated': True,
        },
    ],
    2: [
        {
            'code': 'nl',
            'name': gettext('Dutch'),
            'public': True,
            'fallbacks': ['en'],
        },
    ],
    'default': {
        'fallbacks': ['en', 'fr'],
        'redirect_on_fallback': True,
        'public': False,
        'hide_untranslated': False,
    }
}

In My Middleware classes:

    MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.middleware.doc.XViewMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',

    'cms.middleware.page.CurrentPageMiddleware',
    'cms.middleware.user.CurrentUserMiddleware',
    'cms.middleware.toolbar.ToolbarMiddleware',
    'cms.middleware.language.LanguageCookieMiddleware',
)

My urls.py:

from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.conf import settings

admin.autodiscover()

urlpatterns = i18n_patterns(
    '',
    url(r'^i18n/', include('django.conf.urls.i18n')),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^products/', include('catalog.urls')),
    url(r'^contact/', 'contact.views.contact'),
    url(r'^pages/', include('django.contrib.flatpages.urls')),
    url(r'^taggit_autosuggest/', include('taggit_autosuggest.urls')),
    url(r'^', include('cms.urls')),
)

if settings.DEBUG:
    import debug_toolbar
    urlpatterns = i18n_patterns('',
        url(r'^__debug__/', include(debug_toolbar.urls)),
        url(r'^404/$', 'django.views.defaults.page_not_found'), # TODO MOET NOG VERPLAATST WORDEN
        url(r'^500/$', 'django.views.defaults.server_error'), # TODO MOET NOG VERPLAATST WORDEN
        url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
        url(r'', include('django.contrib.staticfiles.urls')),
    ) + urlpatterns

In my blog_items.html page (a page from the djangocms-blog plugin template that I override)

{% load i18n thumbnail cms_tags %}
{% load url from future %}

I created my languages within the virtual env by

  1. Going to the virtual env by "workon app"
  2. I run the command django-admin.py makemessages -l nl (the po files are created correctly)
  3. I run the command django-admin.py compilemessages and everything seems fine
  4. In the root of my program is the locale folder with 3 subfolders: en, fr and nl. They contain all the LC_MESSAGES folder with a django.mo and django.po file with the correct message strings.

    #: .\templates\djangocms_blog\includes\blog_item.html:37 #, fuzzy msgid "read more" msgstr "lees meer"

2
Have you enabled i18n in django-cms? docs.django-cms.org/en/latest/advanced/i18n.html - petkostas
Yes, this is my urls: ` urlpatterns = i18n_patterns( url(r'^', include('cms.urls')), )` - RVE
Is the Middleware (cms.middleware.language.LanguageCookieMiddleware) also in your settings? - petkostas
Yes: 'cms.middleware.language.LanguageCookieMiddleware', - RVE

2 Answers

1
votes

This is solved.

  1. First of all the fuzzy had to be removed.

  2. I had to add the parler settings correct into my general settings:

In the documentation of Django-parler (https://pypi.python.org/pypi/django-parler ) they suggest the next settings:

PARLER_LANGUAGES = {
    None: (
        {'code': 'nl',},
        {'code': 'en',},
        {'code': 'fr',},
    ),
}

Instead of

PARLER_LANGUAGES = {
    1: (
        {'code': 'nl',},
        {'code': 'en',},
        {'code': 'fr',},
    ),
}
0
votes

AFAIK translations marked as fuzzy are not compiled in the mo files and you must "unfuzzy" them before being available