# Path: simple_cms/contrib/translated_model/models.py
# class LocalizationTranslation(models.Model):
#     language = models.ForeignKey(Language)
#     localization = models.ForeignKey(Localization)
#     text = models.TextField()
#     
#     class Meta:
#         unique_together = ('language', 'localization')
#     
#     def __unicode__(self):
#         return u'%s' % self.text
# 
# Path: simple_cms/models.py
# class CommonAbstractModel(models.Model):
#     """
#     Common ABC for most models.
#     Provides created/updated_at, and active/inactive status.
#     """
#     created_at = CreationDateTimeField()
#     updated_at = ModificationDateTimeField()
#     active = models.BooleanField(default=True, verbose_name="published")
#     objects = CommonAbstractManager()
# 
#     class Meta:
#         get_latest_by = 'updated_at'
#         ordering = ('-updated_at', '-created_at')
#         abstract = True
# 
#     def get_class_name(self):
#         return self.__class__.__name__


from django.utils.safestring import mark_safe
from simple_cms.contrib.translated_model.models import LocalizationTranslation
from simple_cms.models import CommonAbstractModel
from django import template
from django.conf import settings
    except KeyError:
        pass
    return instance

@register.assignment_tag(takes_context=True)
def translated_field(context, instance, field):
    return translate_field(context, instance, field)

@register.simple_tag(takes_context=True)
def translate_field(context, instance, field):
    try:
        code = context['request'].LANGUAGE_CODE
        if code != get_default_language():
            # now try to find a translation
            try:
                translations = instance.translations.filter(language__code=code, active=True)
                if len(translations):
                    p = getattr(translations[0], field)
                    if len(p):
                        return p
            except AttributeError:
                pass
    except KeyError:
        pass
    return getattr(instance, field)

@register.simple_tag(takes_context=True)
def translate_string(context, key, default=''):
    try:
        return mark_safe(LocalizationTranslation.objects.get(localization__name=key, language__code=context['request'].LANGUAGE_CODE).text)

# Path: simple_cms/contrib/translated_model/models.py
# class LocalizationTranslation(models.Model):
#     language = models.ForeignKey(Language)
#     localization = models.ForeignKey(Localization)
#     text = models.TextField()
#     
#     class Meta:
#         unique_together = ('language', 'localization')
#     
#     def __unicode__(self):
#         return u'%s' % self.text
# 
# Path: simple_cms/models.py
# class CommonAbstractModel(models.Model):
#     """
#     Common ABC for most models.
#     Provides created/updated_at, and active/inactive status.
#     """
#     created_at = CreationDateTimeField()
#     updated_at = ModificationDateTimeField()
#     active = models.BooleanField(default=True, verbose_name="published")
#     objects = CommonAbstractManager()
# 
#     class Meta:
#         get_latest_by = 'updated_at'
#         ordering = ('-updated_at', '-created_at')
#         abstract = True
# 
#     def get_class_name(self):
#         return self.__class__.__name__


# Path: simple_cms/contrib/translated_model/templatetags/translation_tags.py
from django.utils.safestring import mark_safe
from simple_cms.contrib.translated_model.models import LocalizationTranslation
from simple_cms.models import CommonAbstractModel
from django import template
from django.conf import settings

    except KeyError:
        pass
    return instance

@register.assignment_tag(takes_context=True)
def translated_field(context, instance, field):
    return translate_field(context, instance, field)

@register.simple_tag(takes_context=True)
def translate_field(context, instance, field):
    try:
        code = context['request'].LANGUAGE_CODE
        if code != get_default_language():
            # now try to find a translation
            try:
                translations = instance.translations.filter(language__code=code, active=True)
                if len(translations):
                    p = getattr(translations[0], field)
                    if len(p):
                        return p
            except AttributeError:
                pass
    except KeyError:
        pass
    return getattr(instance, field)

@register.simple_tag(takes_context=True)
def translate_string(context, key, default=''):
    try:
        return mark_safe(LocalizationTranslation.objects.get(localization__name=key, language__code=context['request'].LANGUAGE_CODE).text)

    except LocalizationTranslation.DoesNotExist: