deschler / django-modeltranslation

Translates Django models using a registration approach.
BSD 3-Clause "New" or "Revised" License
1.38k stars 257 forks source link

How to registered model for translation using Django1.10 and django-moddeltranslation0.12 #402

Open vedvins09 opened 7 years ago

vedvins09 commented 7 years ago

Hello django-modeltranslation dev team.

I'm using Django-modeltranlation 0.12 with Django 1.10 i'm not able to registered my model for translation

in setting.py

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'v@rim034=hc&605d114^mq*6jvtn5+_w%k2e4zmab%b)xjvwug'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

MODELTRANSLATION_DEBUG = True

# Application definition

INSTALLED_APPS = (
    'modeltranslation',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'i18ntest',

)

MIDDLEWARE_CLASSES = (
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.middleware.security.SecurityMiddleware',

)

ROOT_URLCONF = 'i18n.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.i18n',
            ],
        },
    },
]

WSGI_APPLICATION = 'i18n.wsgi.application'

# Database
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/

from django.utils.translation import ugettext_lazy as _
gettext = lambda s: s
LANGUAGES = (
    ('hi', gettext('Hindi')),
    ('en', gettext('English')),    
    ('ru', gettext('Russian')),
    ('ur', gettext('Urdu')),
    ('zh', gettext('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',
)
MODELTRANSLATION_CUSTOM_FIELDS = ( ) 
MODELTRANSLATION_AUTO_POPULATE = False
MODELTRANSLATION_DEBUG = False
MODELTRANSLATION_ENABLE_FALLBACKS = True
MODELTRANSLATION_LOADDATA_RETAIN_LOCALE = True

in translations.py

from modeltranslation.translator import *#register,translator, TranslationOptions
from i18ntest.models import MyThing

@register(MyThing)
class MyThingTranslationOptions(TranslationOptions):
    fields = ('name',)

my 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(max_length = 150,null = True, blank = True)
    def __unicode__(self):
        return self.name

my server status is:

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

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

Pls solve issue

SalahAdDin commented 7 years ago

:+1: