[states] adding multiple state abbreviations for states that can have periods in the naem like D.C., D.F. in Mexico and Brasil, etc.
This commit is contained in:
@@ -1,20 +1,48 @@
|
|||||||
|
"A.A.T":
|
||||||
|
en: Australian Antarctic Territory
|
||||||
|
"A.A.T.":
|
||||||
|
en: Australian Antarctic Territory
|
||||||
AAT:
|
AAT:
|
||||||
en: Australian Antarctic Territory
|
en: Australian Antarctic Territory
|
||||||
|
"A.C.T":
|
||||||
|
en: Australian Capital Territory
|
||||||
|
"A.C.T.":
|
||||||
|
en: Australian Capital Territory
|
||||||
ACT:
|
ACT:
|
||||||
en: Australian Capital Territory
|
en: Australian Capital Territory
|
||||||
|
"J.B.T.":
|
||||||
|
en: Jervis Bay Territory
|
||||||
|
"J.B.T":
|
||||||
|
en: Jervis Bay Territory
|
||||||
JBT:
|
JBT:
|
||||||
en: Jervis Bay Territory
|
en: Jervis Bay Territory
|
||||||
|
"N.S.W":
|
||||||
|
en: New South Wales
|
||||||
|
"N.S.W.":
|
||||||
|
en: New South Wales
|
||||||
NSW:
|
NSW:
|
||||||
en: New South Wales
|
en: New South Wales
|
||||||
|
"N.T":
|
||||||
|
en: Northern Territory
|
||||||
|
"N.T.":
|
||||||
|
en: Northern Territory
|
||||||
NT:
|
NT:
|
||||||
en: Northern Territory
|
en: Northern Territory
|
||||||
QLD:
|
QLD:
|
||||||
en: Queensland
|
en: Queensland
|
||||||
|
"S.A":
|
||||||
|
en: South Australia
|
||||||
|
"S.A.":
|
||||||
|
en: South Australia
|
||||||
SA:
|
SA:
|
||||||
en: South Australia
|
en: South Australia
|
||||||
TAS:
|
TAS:
|
||||||
en: Tasmania
|
en: Tasmania
|
||||||
VIC:
|
VIC:
|
||||||
en: Victoria
|
en: Victoria
|
||||||
|
"W.A":
|
||||||
|
en: Western Australia
|
||||||
|
"W.A.":
|
||||||
|
en: Western Australia
|
||||||
WA:
|
WA:
|
||||||
en: Western Australia
|
en: Western Australia
|
||||||
@@ -10,6 +10,10 @@ BA:
|
|||||||
pt: Bahia
|
pt: Bahia
|
||||||
CE:
|
CE:
|
||||||
pt: Ceará
|
pt: Ceará
|
||||||
|
"D.F":
|
||||||
|
pt: Distrito Federal
|
||||||
|
"D.F.":
|
||||||
|
pt: Distrito Federal
|
||||||
DF:
|
DF:
|
||||||
pt: Distrito Federal
|
pt: Distrito Federal
|
||||||
ES:
|
ES:
|
||||||
|
|||||||
@@ -14,6 +14,10 @@ CA:
|
|||||||
es: Coahuila
|
es: Coahuila
|
||||||
CL:
|
CL:
|
||||||
es: Colima
|
es: Colima
|
||||||
|
"D.F.":
|
||||||
|
es: Distrito Federal
|
||||||
|
"D.F":
|
||||||
|
es: Distrito Federal
|
||||||
DF:
|
DF:
|
||||||
es: Distrito Federal
|
es: Distrito Federal
|
||||||
DU:
|
DU:
|
||||||
|
|||||||
@@ -12,6 +12,10 @@ CO:
|
|||||||
en: Colorado
|
en: Colorado
|
||||||
CT:
|
CT:
|
||||||
en: Connecticut
|
en: Connecticut
|
||||||
|
"D.C":
|
||||||
|
en: District of Columbia
|
||||||
|
"D.C.":
|
||||||
|
en: District of Columbia
|
||||||
DC:
|
DC:
|
||||||
en: District of Columbia
|
en: District of Columbia
|
||||||
DE:
|
DE:
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
|
import random
|
||||||
import six
|
import six
|
||||||
import sys
|
import sys
|
||||||
import yaml
|
import yaml
|
||||||
@@ -24,30 +25,34 @@ class StateAbbreviations(object):
|
|||||||
country = filename.split('.yaml')[0]
|
country = filename.split('.yaml')[0]
|
||||||
country_config = yaml.load(open(os.path.join(base_dir, filename)))
|
country_config = yaml.load(open(os.path.join(base_dir, filename)))
|
||||||
|
|
||||||
country_abbreviations = defaultdict(dict)
|
country_abbreviations = defaultdict(list)
|
||||||
country_full_names = defaultdict(dict)
|
country_full_names = defaultdict(list)
|
||||||
|
|
||||||
for abbreviation, vals in six.iteritems(country_config):
|
for abbreviation, vals in six.iteritems(country_config):
|
||||||
for language, full_name in six.iteritems(vals):
|
for language, full_name in six.iteritems(vals):
|
||||||
full_name = safe_decode(full_name)
|
full_name = safe_decode(full_name)
|
||||||
abbreviation = safe_decode(abbreviation)
|
abbreviation = safe_decode(abbreviation)
|
||||||
country_abbreviations[full_name.lower()][language] = abbreviation
|
country_abbreviations[(full_name.lower(), language)].append(abbreviation)
|
||||||
country_full_names[abbreviation.lower()][language] = full_name
|
country_full_names[(abbreviation.lower(), language)].append(full_name)
|
||||||
|
|
||||||
self.abbreviations[country] = dict(country_abbreviations)
|
self.abbreviations[country] = dict(country_abbreviations)
|
||||||
self.full_names[country] = dict(country_full_names)
|
self.full_names[country] = dict(country_full_names)
|
||||||
|
|
||||||
def get_abbreviation(self, country, language, state, default=None):
|
def get_abbreviation(self, country, language, state, default=None):
|
||||||
value = nested_get(self.abbreviations, (country.lower(), state.lower(), language.lower()))
|
values = nested_get(self.abbreviations, (country.lower(), (state.lower(), language.lower())))
|
||||||
if value is DoesNotExist:
|
if values is DoesNotExist:
|
||||||
return default
|
return default
|
||||||
return value
|
if len(values) == 1:
|
||||||
|
return values[0]
|
||||||
|
return random.choice(values)
|
||||||
|
|
||||||
def get_full_name(self, country, language, state, default=None):
|
def get_full_name(self, country, language, state, default=None):
|
||||||
value = nested_get(self.full_names, (country.lower(), state.lower(), language.lower()))
|
values = nested_get(self.full_names, (country.lower(), (state.lower(), language.lower())))
|
||||||
if value is DoesNotExist:
|
if values is DoesNotExist:
|
||||||
return default
|
return default
|
||||||
return value
|
if len(values) == 1:
|
||||||
|
return values[0]
|
||||||
|
return random.choice(values)
|
||||||
|
|
||||||
|
|
||||||
state_abbreviations = StateAbbreviations()
|
state_abbreviations = StateAbbreviations()
|
||||||
|
|||||||
Reference in New Issue
Block a user