<commit_before>from django.conf import settings
from django.utils.deconstruct import deconstructible
from django.utils.translation import get_language as django_get_language


LANGUAGES = [lang for lang, name in settings.LANGUAGES]


def localized_field_names(field):
    return ['%s_%s' % (field, lang) for lang in LANGUAGES]


def get_language():
    language = django_get_language()
    # no sublanguages
    if '-' in language:
        language = language.split('-')[0]

    # return str not unicode so we can use it in a kwargs dictionary
    return str(language)
<commit_msg>Be safer when determining current language<commit_after>from django.conf import settings
from django.utils.deconstruct import deconstructible
from django.utils.translation import get_language as django_get_language


LANGUAGES = [lang for lang, name in settings.LANGUAGES]


def localized_field_names(field):
    return ['%s_%s' % (field, lang) for lang in LANGUAGES]


def get_language():
    language = django_get_language()
    # no sublanguages
    if language and '-' in language:
        language = language.split('-')[0]

    # return str not unicode so we can use it in a kwargs dictionary
    return str(language)

{'fraction_non_alphanumeric': 0.08139534883720931, 'fraction_numerical': 0.0016611295681063123, 'mean_word_length': 4.193965517241379, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '888708', 'n_tokens_mistral': 358, 'n_tokens_neox': 339, 'n_words': 121}