<commit_before># -*- coding: utf-8 -*-

from babel import Locale
from django.forms import Select, TextInput
from django.forms.widgets import MultiWidget
from django.utils import translation
from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE

from phonenumber_field.phonenumber import PhoneNumber


class PhonePrefixSelect(Select):
    initial = None

    def __init__(self, initial=None):
        choices = [('', '---------')]
        locale = Locale(translation.to_locale(translation.get_language()))
        for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items():
            prefix = '+%d' % prefix
            if initial and initial in values:
                self.initial = prefix
            for country_code in values:
                country_name = locale.territories.get(country_code)
                if country_name:
                    choices.append((prefix, u'%s %s' % (country_name, prefix)))
        super(PhonePrefixSelect, self).__init__(
            choices=sorted(choices, key=lambda item: item[1]))
<commit_msg>checked if locale is null related #113<commit_after># -*- coding: utf-8 -*-

from babel import Locale
from django.forms import Select, TextInput
from django.forms.widgets import MultiWidget
from django.utils import translation
from phonenumbers.data import _COUNTRY_CODE_TO_REGION_CODE

from phonenumber_field.phonenumber import PhoneNumber


class PhonePrefixSelect(Select):
    initial = None

    def __init__(self, initial=None):
        choices = [('', '---------')]
        language = translation.get_language()
        if language:
            locale = Locale(translation.to_locale(language))
            for prefix, values in _COUNTRY_CODE_TO_REGION_CODE.items():
                prefix = '+%d' % prefix
                if initial and initial in values:
                    self.initial = prefix
                for country_code in values:
                    country_name = locale.territories.get(country_code)
                    if country_name:
                        choices.append((prefix, u'%s %s' % (country_name, prefix)))
        super(PhonePrefixSelect, self).__init__(
            choices=sorted(choices, key=lambda item: item[1]))

{'fraction_non_alphanumeric': 0.09699453551912568, 'fraction_numerical': 0.0031876138433515485, 'mean_word_length': 2.5898692810457518, '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': '2985543', 'n_tokens_mistral': 602, 'n_tokens_neox': 586, 'n_words': 156}