From 1cec0570d6c4a64ce68614ed842b37d95f20bb11 Mon Sep 17 00:00:00 2001 From: Al Date: Thu, 15 Sep 2016 11:45:46 -0400 Subject: [PATCH] [formatting] only using alias country insertions if the given country has not defined its own (e.g. look at Puerto Rico first, then use the US if there's nothing defined) --- scripts/geodata/address_formatting/formatter.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/geodata/address_formatting/formatter.py b/scripts/geodata/address_formatting/formatter.py index 89981424..be54d0c7 100644 --- a/scripts/geodata/address_formatting/formatter.py +++ b/scripts/geodata/address_formatting/formatter.py @@ -562,7 +562,16 @@ class AddressFormatter(object): if not template: return None - country = self.country_aliases.get(country.upper(), country).lower() + country_language = None + if language: + country_language = '{}_{}'.format(country, language) + + alias_country = self.country_aliases.get(country.upper(), country).lower() + for term in (country, country_language): + if term in self.country_insertions or term in self.country_conditionals: + break + else: + country = alias_country cache_keys = [] @@ -571,9 +580,6 @@ class AddressFormatter(object): insertions = nested_get(self.country_insertions, (country, component), default=None) conditionals = nested_get(self.country_conditionals, (country, component), default=None) - if language: - country_language = '{}_{}'.format(country, language) - if insertions is None and language: insertions = nested_get(self.country_insertions, (country_language, component), default=None) scope = country_language