"""
This code is based on code found in satchmo, in turn
based on samples found here -
http://www.b-list.org/weblog/2006/06/14/django-tips-template-context-processors

It is used to add some common variables to all the templates
"""
from django.utils import translation
from ghestalt.i18n.utils import *

def settings(request):
    from django.conf import settings
    site_name = _(settings.SITE_NAME)
    site_base = i18n_site_base(request)
    try:
        other_lang = str(request.session['other_lang'])
    except KeyError:
        other_lang = None
    gui_lang = request.LANGUAGE_CODE[:2]
    try:
        otro_lang = str(request.session['otro_lang'])
    except KeyError:
        otro_lang = None
    if i18n_lang_suffix(request.path)[1:] in settings.LANGUAGES_BIDI:
        content_bidi = True
    else:
        content_bidi = False
    return {'site_base': site_base,
            'site_root': settings.SITE_BASE,
            'site_name': site_name,
            'media_url': settings.MEDIA_URL,
            'url_path': request.path,
            'other_lang': other_lang,
            'gui_lang': gui_lang,
            'base_lang': settings.LANGUAGE_CODE[:2],
            'otro_lang': otro_lang,
            }
