简体   繁体   English

Django的,Django的modeltranslation

[英]Django,django-modeltranslation

I'm new with modeltranslation and I have a problem. 我是modeltranslation的新手,但有问题。 When I do the manage.py makemigrations myapp command after creating my model and registering the fields to translate in translation.py the modeltranslation app doesn't add the translated field to the model. 在创建模型并注册要在translation.py中进行翻译的字段后,当我执行manage.py makemigrations myapp命令时,modeltranslation应用程序不会将已翻译的字段添加到模型中。 The fields are in the table though. 这些字段在表格中。

modeltranslation: Registered 0 models for translation () [pid: 8333]. modeltranslation:注册了0个要翻译的模型()[pid:8333]。

in my setting.py 在我的setting.py中

from django.utils.translation import ugettext_lazy as _
gettext = lambda s: s
LANGUAGES = (
    ('hi', _('Hindi')),
    ('en', _('English')),

    ('ru', _('Russian')),
    ('ur', _('Urdu')),
    ('zh', _('Chinese')),
)



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

LANGUAGE_CODE = 'hi'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.8/howto/static-files/
from modeltranslation.translator import translator
STATIC_URL = '/static/'

MODELTRANSLATION_DEFAULT_LANGUAGE = 'hi'

MODELTRANSLATION_LANGUAGES = ('hi', 'en')

MODELTRANSLATION_FALLBACK_LANGUAGES = ('hi', 'en')

MODELTRANSLATION_PREPOPULATE_LANGUAGE = 'hi'


MODELTRANSLATION_TRANSLATION_FILES = (
    'i18ntest.translation',
)

in my models.py 在我的models.py中

from django.db import models
from django.utils.translation import ugettext_lazy
from django.conf import settings

    class MyThing(models.Model):
        name = models.CharField(help_text=ugettext_lazy('This is the help text'),max_length = 150,null = True, blank = True)
        def __unicode__(self):
        return self.name

# Create your models here.


    class Profile(models.Model):
        name = models.CharField(max_length = 150,null = True, blank = True)

        def __unicode__(self):
            return self.name

in my translations.py 在我的translations.py中

from modeltranslation.translator import register,translator, TranslationOptions

from i18ntest.models import MyThing

@register(MyThing)

    class MyThingTranslationOptions(TranslationOptions):
        fields = ('name',

)

#translator.register(MyThing, MyThingTranslationOptions)

i'm using django-modeltranslation 0.12 with django 1.10 我在django 1.10中使用django-modeltranslation 0.12

and server status is 服务器状态为

(envi18n) vinod@vinod-H81M-S:~/vinod/i18n/i18n$ ./manage.py runserver
modeltranslation: Registered 0 models for translation () [pid: 9065].
modeltranslation: Registered 0 models for translation () [pid: 9068].
Performing system checks...

System check identified no issues (0 silenced).
February 22, 2017 - 12:26:35
Django version 1.10, using settings 'i18n.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

You have a typo in the translation file name. 您在翻译文件名中输入错误。 I must be translation.py , singular. 我必须是translation.py (单数)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM