API Reference

Public API

modeltrans.admin

class modeltrans.admin.ActiveLanguageMixin[source]

Add this mixin to your admin class to hide the untranslated field and all translated fields, except:

  • The field for the default language (settings.LANGUAGE_CODE)
  • The field for the currently active language.

modeltrans.apps

class modeltrans.apps.RegistrationConfig(app_name, app_module)[source]

modeltrans.fields

class modeltrans.fields.TranslatedVirtualField(original_field, language=None, *args, **kwargs)[source]

A field representing a single field translated to a specific language.

Parameters:
  • original_field – The original field to be translated
  • language – The lanuage to translate to, or None to track the current active Django language.
get_field_name()[source]

Returns the field name for the current virtual field.

The field name is <original_field_name>_<language> in case of a specific translation or <original_field_name>_i18n for the currently active language.

get_language()[source]

Returns the language for this field.

In case of an explicit language (title_en), it returns ‘en’, in case of title_i18n, it returns the currently active Django language.

class modeltrans.fields.TranslationField(fields=None, required_languages=None, virtual_fields=True, *args, **kwargs)[source]

This model field is used to store the translations in the translated model.

Parameters:
  • fields (iterable) – List of column names to make translatable.
  • required_languages (iterable) – List of languages required for the model.
  • virtual_fields (bool) – If False, do not add virtual fields to access translated values with. Set to True during migration from django-modeltranslation to prevent collisions with it’s database fields while having the i18n field available.

Internal API

There should be no need to interact with these APIs, but it might be interesting when working on django-modeltrans or to gain better understending of the internals.

modeltrans.manager

class modeltrans.manager.MultilingualManager[source]

When adding the modeltrans.fields.TranslationField to a model, MultilingualManager is automatically mixed in to the manager class of that model.

class modeltrans.manager.MultilingualQuerySet(model=None, query=None, using=None, hints=None)[source]

Extends Queryset and makes the translated versions of fields accessible through the normal queryset methods, analogous to the virtual fields added to a translated model:

  • <field> allow getting/setting the default language
  • <field>_<lang> (for example, <field>_de) allows getting/setting a specific language. Note that if LANGUAGE_CODE == 'en', <field>_en is mapped to <field>.
  • <field>_i18n follows the currently active translation in Django, and falls back to the default language.

When adding the modeltrans.fields.TranslationField to a model, MultilingualManager is automatically mixed in to the manager class of that model.