# Path: easymode/utils/languagecode.py
# def get_real_fieldname(field, lang):
#     """
#     Depending on the language a field can have a different name.
#     
#     If you want to do a query, using a localized field, you have
#     to use the name this function returns, not the default name.
#     
#     >>> get_real_fieldname('name', 'en-us')
#     'name_en_us'
#     
#     Usage::
#     
#         def index(request):
#             published_in_language = get_real_fieldname('published', request.LANGUAGE_CODE)
#             qs = SomeModel.objects.filter(**{published_in_language:True})
#             return render_to_response('index.html', {'queryset':qs})
#     
#     
#     :param field: The name of a field in an internationalised model.
#     :param lang: The language for which you want to know the real name.
#     :rtype: The actual name of the ``field`` in the ``lang``.
#     """
#     return str('%s_%s' % (field, to_locale(lang).lower()))


from django.conf import settings
from django.utils import translation
from easymode.utils import first_match
from easymode.utils.languagecode import get_real_fieldname
from easymode.utils import first_match
    '''
    if language:
        return getattr(context, get_real_fieldname(field, language))
    
    if hasattr(settings, 'FALLBACK_LANGUAGES'):
        attrs = [translation.get_language()]
        attrs += get_fallback_languages()
    else:
        attrs = [
            translation.get_language(),
            translation.get_language()[:2],
            settings.LANGUAGE_CODE, 
        ]
    
    def predicate(x):
        value = getattr(context, get_real_fieldname(field, x), None)
        return value if valid_for_gettext(value) else None

    return first_match(predicate, attrs)


def get_localized_field_name(context, field):
    """Get the name of the localized field"""
    attrs = [
             translation.get_language(), 
             translation.get_language()[:2], 
             settings.LANGUAGE_CODE
            ]
            
    def predicate(x):

# Path: easymode/utils/languagecode.py
# def get_real_fieldname(field, lang):
#     """
#     Depending on the language a field can have a different name.
#     
#     If you want to do a query, using a localized field, you have
#     to use the name this function returns, not the default name.
#     
#     >>> get_real_fieldname('name', 'en-us')
#     'name_en_us'
#     
#     Usage::
#     
#         def index(request):
#             published_in_language = get_real_fieldname('published', request.LANGUAGE_CODE)
#             qs = SomeModel.objects.filter(**{published_in_language:True})
#             return render_to_response('index.html', {'queryset':qs})
#     
#     
#     :param field: The name of a field in an internationalised model.
#     :param lang: The language for which you want to know the real name.
#     :rtype: The actual name of the ``field`` in the ``lang``.
#     """
#     return str('%s_%s' % (field, to_locale(lang).lower()))


# Path: easymode/i18n/meta/utils.py
from django.conf import settings
from django.utils import translation
from easymode.utils import first_match
from easymode.utils.languagecode import get_real_fieldname
from easymode.utils import first_match

    '''
    if language:
        return getattr(context, get_real_fieldname(field, language))
    
    if hasattr(settings, 'FALLBACK_LANGUAGES'):
        attrs = [translation.get_language()]
        attrs += get_fallback_languages()
    else:
        attrs = [
            translation.get_language(),
            translation.get_language()[:2],
            settings.LANGUAGE_CODE, 
        ]
    
    def predicate(x):
        value = getattr(context, get_real_fieldname(field, x), None)
        return value if valid_for_gettext(value) else None

    return first_match(predicate, attrs)


def get_localized_field_name(context, field):
    """Get the name of the localized field"""
    attrs = [
             translation.get_language(), 
             translation.get_language()[:2], 
             settings.LANGUAGE_CODE
            ]
            
    def predicate(x):

        field_name = get_real_fieldname(field, x)