# 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
"""
utility functions used by easymode's i18n.meta package to get localized attributes
from a class.
"""



def valid_for_gettext(value):
    """Gettext acts weird when empty string is passes, and passing none would be even weirder"""
    return value not in (None, "")
    
def get_fallback_languages():
    """Retrieve the fallback languages from the settings.py"""
    lang = translation.get_language()
    fallback_list = settings.FALLBACK_LANGUAGES.get(lang, None)
    if fallback_list:
        return fallback_list

    return settings.FALLBACK_LANGUAGES.get(lang[:2], [])


def get_localized_property(context, field=None, language=None):
    '''
    When accessing to the name of the field itself, the value
    in the current language will be returned. Unless it's set,
    the value in the default language will be returned.
    '''
    if language:

# 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

"""
utility functions used by easymode's i18n.meta package to get localized attributes
from a class.
"""



def valid_for_gettext(value):
    """Gettext acts weird when empty string is passes, and passing none would be even weirder"""
    return value not in (None, "")
    
def get_fallback_languages():
    """Retrieve the fallback languages from the settings.py"""
    lang = translation.get_language()
    fallback_list = settings.FALLBACK_LANGUAGES.get(lang, None)
    if fallback_list:
        return fallback_list

    return settings.FALLBACK_LANGUAGES.get(lang[:2], [])


def get_localized_property(context, field=None, language=None):
    '''
    When accessing to the name of the field itself, the value
    in the current language will be returned. Unless it's set,
    the value in the default language will be returned.
    '''
    if language:

        return getattr(context, get_real_fieldname(field, language))