### Navigation

- index
- modules |
- next |
- previous |
- FeinCMS 1.7.4 documentation »

# Translations

This module offers functions and abstract base classes that can be used to store translated models. There isn’t much magic going on here.

Usage example:

    class News(models.Model, TranslatedObjectMixin):
        active = models.BooleanField(default=False)
        created = models.DateTimeField(default=timezone.now)

    class NewsTranslation(Translation(News)):
        title = models.CharField(max_length=200)
        body = models.TextField()

Print the titles of all news entries either in the current language (if available) or in any other language:

    for news in News.objects.all():
        print news.translation.title

Print all the titles of all news entries which have an english translation:

    from django.utils import translation
    translation.activate('en')
    for news in News.objects.filter(translations__language_code='en'):
        print news.translation.title

class `feincms.translations.``TranslatedObjectManager`

  This manager offers convenience methods.

  `only_language`(language=<function short_language_code at 0xb722e2c>)

    Only return objects which have a translation into the given language.

    Uses the currently active language by default.

class `feincms.translations.``TranslatedObjectMixin`

  Mixin with helper methods.

  `get_translation_cache_key`(language_code=None)

    Return the cache key used to cache this object’s translations so we can purge on-demand

`feincms.translations.``Translation`(model)

  Return a class which can be used as inheritance base for translation models

`feincms.translations.``admin_translationinline`(model, inline_class=<class 'django.contrib.admin.options.StackedInline'>, **kwargs)

  Returns a new inline type suitable for the Django administration:

      from django.contrib import admin
      from myapp.models import News, NewsTranslation

      admin.site.register(News,
          inlines=[
              admin_translationinline(NewsTranslation),
              ],
          )

`feincms.translations.``is_primary_language`(language=None)

  Returns true if current or passed language is the primary language for this site. (The primary language is defined as the first language in settings.LANGUAGES.)

`feincms.translations.``lookup_translations`(language_code=None)

  Pass the return value of this function to .transform() to automatically resolve translation objects

  The current language is used if `language_code` isn’t specified.

`feincms.translations.``short_language_code`(code=None)

  Extract the short language code from its argument (or return the default language code).

      >>> from django.conf import settings
      >>> short_language_code('de')
      'de'
      >>> short_language_code('de-at')
      'de'
      >>> short_language_code() == short_language_code(settings.LANGUAGE_CODE)
      True

### Navigation

- index
- modules |
- next |
- previous |
- FeinCMS 1.7.4 documentation »