From 3ffb0ce0a657cf55ffb741e8a7e74b8bd284fcd4 Mon Sep 17 00:00:00 2001 From: Jacek Tomaszewski Date: Wed, 22 Jan 2014 22:32:59 +0100 Subject: [PATCH] Add MODELTRANSLATION_LANGUAGES setting. --- docs/modeltranslation/installation.rst | 33 +++++++++++++++++++++++++- modeltranslation/settings.py | 3 ++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/docs/modeltranslation/installation.rst b/docs/modeltranslation/installation.rst index 64d9170..66aad1c 100644 --- a/docs/modeltranslation/installation.rst +++ b/docs/modeltranslation/installation.rst @@ -116,9 +116,18 @@ and ``en`` in your project, set the ``LANGUAGES`` variable like this (where rather required for Django to be able to (statically) translate the verbose names of the languages using the standard ``i18n`` solution. +.. note:: + If, for some reason, you don't want to translate objects to exactly the same languages as + the site would be displayed into, you can set ``MODELTRANSLATION_LANGUAGES`` (see below). + For any language in ``LANGUAGES`` not present in ``MODELTRANSLATION_LANGUAGES``, the *default + language* will be used when accessing translated content. For any language in + ``MODELTRANSLATION_LANGUAGES`` not present in ``LANGUAGES``, probably nobody will see translated + content, since the site wouldn't be accessible in that language. + .. warning:: Modeltranslation does not enforce the ``LANGUAGES`` setting to be defined - in your project. When it isn't present, it defaults to Django's + in your project. When it isn't present (and neither is ``MODELTRANSLATION_LANGUAGES``), it + defaults to Django's `global LANGUAGES setting `_ instead, and that are quite a number of languages! @@ -147,6 +156,28 @@ Example:: MODELTRANSLATION_DEFAULT_LANGUAGE = 'en' +``MODELTRANSLATION_LANGUAGES`` +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. versionadded:: 0.8 + +Default: same as ``LANGUAGES`` + +Allow to set languages the content will be translated into. If not set, by default all +languages listed in ``LANGUAGES`` will be used. + +Example:: + + LANGUAGES = ( + ('en', 'English'), + ('de', 'German'), + ('pl', 'Polish'), + ) + MODELTRANSLATION_LANGUAGES = ('en', 'de') + +.. note:: We doubt this setting will ever be needed, but why not add it since we can? + + .. _settings-modeltranslation_fallback_languages: ``MODELTRANSLATION_FALLBACK_LANGUAGES`` diff --git a/modeltranslation/settings.py b/modeltranslation/settings.py index 68b3997..95325ce 100644 --- a/modeltranslation/settings.py +++ b/modeltranslation/settings.py @@ -5,7 +5,8 @@ from django.core.exceptions import ImproperlyConfigured TRANSLATION_FILES = tuple(getattr(settings, 'MODELTRANSLATION_TRANSLATION_FILES', ())) -AVAILABLE_LANGUAGES = [l[0] for l in settings.LANGUAGES] +AVAILABLE_LANGUAGES = getattr(settings, 'MODELTRANSLATION_LANGUAGES', + [l[0] for l in settings.LANGUAGES]) DEFAULT_LANGUAGE = getattr(settings, 'MODELTRANSLATION_DEFAULT_LANGUAGE', None) if DEFAULT_LANGUAGE and DEFAULT_LANGUAGE not in AVAILABLE_LANGUAGES: raise ImproperlyConfigured('MODELTRANSLATION_DEFAULT_LANGUAGE not in LANGUAGES setting.')