# Path: statirator/core/utils.py
# def path_to_lang(path, lang):
#     "Translate one path to another languge, takes into account "
# 
#     prefix = postfix = ''
# 
#     if path.startswith('/'):
#         path = path[1:]
#         prefix = '/'
#     if path.endswith('/'):
#         path = path[:-1]
#         postfix = '/'
# 
#     bits = path.split('/')
# 
#     #TODO fix for multi domain or prefixed default language
#     if bits[0] in LANGS_DICT:
#         bits.pop(0)
#     else:  # assume it's the default language.
#         pass
# 
#     if lang != settings.LANGUAGE_CODE:
#         bits.insert(0, lang)
# 
#     return prefix + '/'.join(bits) + postfix
# 
# LANGS_DICT = dict(settings.LANGUAGES)


from django.conf import settings
from .utils import path_to_lang, LANGS_DICT
        slug = {self.SLUG_FIELD_FOR_TRANSLATIONS + '__exact': self_slug}
        lang = {self.LANG_FIELD_FOR_TRANSLATIONS + '__exact': self_lang}
        return self.__class__.objects.filter(**slug).exclude(**lang)

    def get_language(self):
        "Get the language display for this item's language"

        attr = 'get_{0}_display'.format(self.LANG_FIELD_FOR_TRANSLATIONS)
        return getattr(self, attr)()


class DummyTranslation(object):
    """Dummy translations for views to put in template context in case there's no
    actual object"""

    def __init__(self, request, language=None, title=None, path=None):
        self.title = title
        self.request = request
        self.language = language or request.LANGUAGE_CODE
        self.path = path or request.path

    def get_translations(self):
        for code, name in settings.LANGUAGES:
            if code != self.language:
                yield DummyTranslation(self.request, code, name, self.path)

    def get_language(self):
        return LANGS_DICT.get(self.language)

    def get_absolute_url(self):

# Path: statirator/core/utils.py
# def path_to_lang(path, lang):
#     "Translate one path to another languge, takes into account "
# 
#     prefix = postfix = ''
# 
#     if path.startswith('/'):
#         path = path[1:]
#         prefix = '/'
#     if path.endswith('/'):
#         path = path[:-1]
#         postfix = '/'
# 
#     bits = path.split('/')
# 
#     #TODO fix for multi domain or prefixed default language
#     if bits[0] in LANGS_DICT:
#         bits.pop(0)
#     else:  # assume it's the default language.
#         pass
# 
#     if lang != settings.LANGUAGE_CODE:
#         bits.insert(0, lang)
# 
#     return prefix + '/'.join(bits) + postfix
# 
# LANGS_DICT = dict(settings.LANGUAGES)


# Path: statirator/core/models.py
from django.conf import settings
from .utils import path_to_lang, LANGS_DICT

        slug = {self.SLUG_FIELD_FOR_TRANSLATIONS + '__exact': self_slug}
        lang = {self.LANG_FIELD_FOR_TRANSLATIONS + '__exact': self_lang}
        return self.__class__.objects.filter(**slug).exclude(**lang)

    def get_language(self):
        "Get the language display for this item's language"

        attr = 'get_{0}_display'.format(self.LANG_FIELD_FOR_TRANSLATIONS)
        return getattr(self, attr)()


class DummyTranslation(object):
    """Dummy translations for views to put in template context in case there's no
    actual object"""

    def __init__(self, request, language=None, title=None, path=None):
        self.title = title
        self.request = request
        self.language = language or request.LANGUAGE_CODE
        self.path = path or request.path

    def get_translations(self):
        for code, name in settings.LANGUAGES:
            if code != self.language:
                yield DummyTranslation(self.request, code, name, self.path)

    def get_language(self):
        return LANGS_DICT.get(self.language)

    def get_absolute_url(self):

        return path_to_lang(self.path, self.language)