diff --git a/simple_translation/templates/simple_translation/language_choices.html b/simple_translation/templates/simple_translation/language_choices.html new file mode 100644 index 0000000..1115ecc --- /dev/null +++ b/simple_translation/templates/simple_translation/language_choices.html @@ -0,0 +1,7 @@ +{% spaceless %} +{% if translations %} + ({% for translation in translations %} + {{ translation.language|upper }}{% if not forloop.last %} {% endif %} + {% endfor %}) +{% endif %} +{% endspaceless %} \ No newline at end of file diff --git a/simple_translation/templatetags/simple_translation_tags.py b/simple_translation/templatetags/simple_translation_tags.py index bd5a4c9..cf64c5f 100644 --- a/simple_translation/templatetags/simple_translation_tags.py +++ b/simple_translation/templatetags/simple_translation_tags.py @@ -1,4 +1,5 @@ from django import template +from django.template.loader import render_to_string from django.db import models from simple_translation.translation_pool import translation_pool @@ -34,4 +35,18 @@ def get_preferred_translation_from_lang(obj, language): return obj.translations[0] register.filter(get_preferred_translation_from_lang) - \ No newline at end of file +def render_language_choices(obj, request): + from cms.utils import get_language_from_request + if not hasattr(obj, 'translations'): + annotate_with_translations(obj) + language = get_language_from_request(request) + translations = [translation for translation in obj.translations if translation.language != language] + opts = obj.__class__._meta + app_label = opts.app_label + return render_to_string([ + 'simple_translation/%s/%s/language_choices.html' % (app_label, opts.object_name.lower()), + 'simple_translation/%s/language_choices.html' % app_label, + 'simple_translation/language_choices.html' + ], {'translations': translations}) +register.filter(render_language_choices) + \ No newline at end of file