翻译字符串的问题 [英] Issues with translating the strings

查看:169
本文介绍了翻译字符串的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用多个翻译

为此,我将设置文件更新为

    LANGUAGE_CODE = 'en-us'

    gettext = lambda s: s


    LANGUAGES = (

        ('es', gettext('Spanish')),
        ('en', gettext('English')),
    )


    LOCALE_PATHS = (
        '/mnt/aviesta/pythondev/django/locale',
    )

    USE_I18N = 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.locale.LocaleMiddleware',


TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.static",
    "django.core.context_processors.request",
)

我的模板文件为:

{% load i18n %}

{% trans "Hello" %}


<p>Already a user <a href="/login/"><b>{% trans "login here" %}</b></a></p>

之后,我创建一个与我的应用程序并行的区域设置文件夹,而不是创建其中的特定语言文件夹: django-admin.py makemessages -l es ,它会创建.po文件,然后将.po文件更新为:

after that I create a locale folder parallel to my app and than create the specific language folders in it as :django-admin.py makemessages -l es which creates the .po file and then update this .po file as:

#: customer_reg/customer_register.html:14
msgid "Hello"
msgstr "¡Hola"

#: customer_reg/customer_register.html:17
msgid "login here"
msgstr "ingresa aquí"

最后我编译我的msg django-admin.py compilemessages

删除我的字符串你好和在这里登录在英文中,他们没有翻译。我不知道为什么会这样。

BUt my strings "hello" and "login here" is remain in English, they are not translated.I don't know why it happens ??

推荐答案

一切看起来都很好用你的代码。我从未见过的唯一的事情是 LOCALE_PATHS settings.py

Everything looks great with your code. The only thing I've never seen is the LOCALE_PATHS in settings.py

Mabye这个答案,我做了很久以前,可以帮助你:多语言问题

Mabye this answer, I did some time ago, could help you: Issues with multiple languages

编辑//回覆评论

from django.utils import translation
translation.activate('es')

这篇关于翻译字符串的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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