1 # -*- coding: utf-8 -*-
4 from django.conf import settings
5 from django.core.exceptions import ImproperlyConfigured
6 from django.db import models
8 from modeltranslation.translator import translator
10 # Every model registered with the modeltranslation.translator.translator
11 # is patched to contain additional localized versions for every
12 # field specified in the model's translation options.
14 # Import the project's global "translation.py" which registers model
15 # classes and their translation options with the translator object.
16 if getattr(settings, 'TRANSLATION_REGISTRY', False):
18 __import__(settings.TRANSLATION_REGISTRY, {}, {}, [''])
20 sys.stderr.write("modeltranslation: Can't import module '%s'.\n"
21 "(If the module exists, it's causing an "
22 "ImportError somehow.)\n" %\
23 settings.TRANSLATION_REGISTRY)
24 # For some reason ImportErrors raised in translation.py or in modules
25 # that are included from there become swallowed. Work around this
26 # problem by printing the traceback explicitly.
30 # After importing all translation modules, all translation classes are
31 # registered with the translator.
34 if sys.argv[1] in ('runserver', 'runserver_plus'):
35 translated_model_names = ', '.join(
36 t.__name__ for t in translator._registry.keys())
37 print('modeltranslation: Registered %d models for '
38 'translation (%s).' % (len(translator._registry),
39 translated_model_names))
43 raise ImproperlyConfigured("You haven't set the TRANSLATION_REGISTRY "