<s> from __future__ import unicode_literals <EOL> from django . conf import settings <EOL> from django . forms . widgets import Select <EOL> from django . utils . encoding import force_text <EOL> from django . utils . encoding import python_2_unicode_compatible <EOL> from django . utils . six import text_type <EOL> from django . utils . translation import get_language <EOL> import gettext as gettext_module <EOL> import pycountry <EOL> import unicodedata <EOL> _translations = { } <EOL> def gettext ( value ) : <EOL> global _translations <EOL> if not settings . USE_I18N : <EOL> return value <EOL> language = get_language ( ) <EOL> if language not in _translations : <EOL> _translations [ language ] = gettext_module . translation ( <EOL> domain = '<STR_LIT>' , <EOL> localedir = pycountry . LOCALES_DIR , <EOL> languages = [ language ] , <EOL> codeset = '<STR_LIT:utf-8>' , <EOL> fallback = True , <EOL> ) <EOL> return _translations [ language ] . gettext ( value ) <EOL> @ python_2_unicode_compatible <EOL> class CountryContainer ( object ) : <EOL> """<STR_LIT:U+0020>""" <EOL> def __init__ ( self , value ) : <EOL> self . obj = pycountry . countries . get ( alpha3 = value ) <EOL> @ property <EOL> def name ( self ) : <EOL> return gettext ( self . obj . name ) <EOL> @ property <EOL> def official_name ( self ) : <EOL> return gettext ( self . obj . official_name ) <EOL> @ property <EOL> def int_name ( self ) : <EOL> return self . obj . name <EOL> @ property <EOL> def int_official_name ( self ) : <EOL> return self . obj . official_name <EOL> @ property <EOL> def key ( self ) : <EOL> return self . obj . alpha3 <EOL> @ property <EOL> def alpha2 ( self ) : <EOL> return self . obj . alpha2 <EOL> @ property <EOL> def alpha3 ( self ) : <EOL> return self . obj . alpha3 <EOL> def __str__ ( self ) : <EOL> return text_type ( self . obj . alpha3 ) <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:3> <EOL> class CountrySelect ( Select ) : <EOL> def __init__ ( self , attrs = None , choices = ( ) ) : <EOL> super ( Select , self ) . __init__ ( attrs ) <EOL> data = [ ] <EOL> if choices : <EOL> for name in choices : <EOL> data . append ( ( name , gettext ( pycountry . countries . get ( alpha3 = name ) . name ) ) ) <EOL> else : <EOL> for country in pycountry . countries : <EOL> data . append ( ( country . alpha3 , gettext ( country . name ) ) ) <EOL> self . choices = list ( sorted ( <EOL> data , <EOL> key = lambda x : unicodedata . normalize ( '<STR_LIT>' , force_text ( x [ <NUM_LIT:1> ] ) ) <EOL> ) ) </s>
