2010-02-23 14:44:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-03-02 16:47:19 +00:00
|
|
|
import sys
|
2010-03-02 22:17:39 +00:00
|
|
|
|
2009-02-17 23:55:17 +00:00
|
|
|
from django.conf import settings
|
2010-03-17 10:00:29 +00:00
|
|
|
from django.core.exceptions import ImproperlyConfigured
|
2010-03-02 22:17:39 +00:00
|
|
|
from django.db import models
|
|
|
|
|
|
2009-02-17 21:08:19 +00:00
|
|
|
from modeltranslation.translator import translator
|
|
|
|
|
|
|
|
|
|
# Every model registered with the modeltranslation.translator.translator
|
2010-04-19 10:52:57 +00:00
|
|
|
# is patched to contain additional localized versions for every
|
2009-02-17 21:08:19 +00:00
|
|
|
# field specified in the model's translation options.
|
|
|
|
|
|
2010-04-19 10:52:57 +00:00
|
|
|
# Import the project's global "translation.py" which registers model
|
2010-03-17 10:00:29 +00:00
|
|
|
# classes and their translation options with the translator object.
|
2010-06-21 09:43:41 +00:00
|
|
|
# TODO: Rename setting to MODELTRANSLATION_TRANSLATION_REGISTRY.
|
2010-03-17 10:00:29 +00:00
|
|
|
if getattr(settings, 'TRANSLATION_REGISTRY', False):
|
2010-04-19 10:52:57 +00:00
|
|
|
try:
|
2010-03-17 10:00:29 +00:00
|
|
|
__import__(settings.TRANSLATION_REGISTRY, {}, {}, [''])
|
|
|
|
|
except ImportError:
|
|
|
|
|
sys.stderr.write("modeltranslation: Can't import module '%s'.\n"
|
|
|
|
|
"(If the module exists, it's causing an "
|
|
|
|
|
"ImportError somehow.)\n" %\
|
|
|
|
|
settings.TRANSLATION_REGISTRY)
|
|
|
|
|
# For some reason ImportErrors raised in translation.py or in modules
|
|
|
|
|
# that are included from there become swallowed. Work around this
|
|
|
|
|
# problem by printing the traceback explicitly.
|
|
|
|
|
import traceback
|
|
|
|
|
traceback.print_exc()
|
2009-02-17 21:08:19 +00:00
|
|
|
|
2010-04-19 10:52:57 +00:00
|
|
|
# After importing all translation modules, all translation classes are
|
2010-03-17 10:00:29 +00:00
|
|
|
# registered with the translator.
|
|
|
|
|
if settings.DEBUG:
|
|
|
|
|
try:
|
|
|
|
|
if sys.argv[1] in ('runserver', 'runserver_plus'):
|
|
|
|
|
translated_model_names = ', '.join(
|
|
|
|
|
t.__name__ for t in translator._registry.keys())
|
|
|
|
|
print('modeltranslation: Registered %d models for '
|
|
|
|
|
'translation (%s).' % (len(translator._registry),
|
|
|
|
|
translated_model_names))
|
|
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
raise ImproperlyConfigured("You haven't set the TRANSLATION_REGISTRY "
|
|
|
|
|
"setting yet.")
|