Django翻译不与Django-cms和djangocms-blog合作

时间:2014-07-31 13:59:11

标签: django internationalization django-cms

我的Django翻译有问题。 我的Django没有翻译我的标签。

我使用django-cms而在django-cms中我有一个插件djangocms-blog

Django == 1.6.5

Django-cms == 3.0.3

Djangocms-blog == 0.2b5

我的transstag未翻译。

示例标记:

{% trans "read more" %}

我正确安装了所有内容,我的settings.py包含以下内容:

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,
    }
}

在我的中间件课程中:

    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',
)

我的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

在我的blog_items.html页面(我覆盖的djangocms-blog插件模板中的页面)

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

我通过

在虚拟环境中创建了我的语言
  1. 通过&#34; workon app&#34;
  2. 转到虚拟环境
  3. 我运行命令django-admin.py makemessages -l nl(po文件已正确创建)
  4. 我运行命令django-admin.py compilemessages,一切似乎都很好
  5. 在我的程序的根目录中是包含3个子文件夹的locale文件夹:en,fr和nl。它们包含所有LC_MESSAGES文件夹,其中包含带有正确消息字符串的django.mo和django.po文件。

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

2 个答案:

答案 0 :(得分:1)

这已经解决了。

  1. 首先,必须删除模糊。

  2. 我必须将parler设置正确添加到我的常规设置中:

  3. 在Django-parler(https://pypi.python.org/pypi/django-parler)的文档中,他们建议下一个设置:

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

    而不是

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

答案 1 :(得分:0)

标记为fuzzy的AFAIK翻译未在mo文件中编译,您必须在其可用之前“取消模糊”