[formatting] Moving language country overrides to formatter config so actual language is retained

This commit is contained in:
Al
2016-05-24 16:52:08 -04:00
parent e59e3a173c
commit 308080f6ee
3 changed files with 8 additions and 5 deletions

View File

@@ -3,6 +3,11 @@ global:
place_direction: right
direction_probability: 0.9
language_code_replacements:
ja_rm: en
ko_rm: en
zh_pinyin: en
insertions:
# For each component, insertions are mutually exclusive
# They don't have to sum to 1 (especially for components

View File

@@ -7,11 +7,6 @@ languages:
# Replace user-tagged admin components with the non-local language version
replace_non_local_probability: 0.4
language_code_replacements:
ja_rm: en
ko_rm: en
zh_pinyin: en
# Dependencies for including each component in an "address"
# Two-way dependencies are not an issue
component_dependencies:

View File

@@ -180,6 +180,8 @@ class AddressFormatter(object):
self.load_config()
self.load_country_formats()
self.language_code_replacements = nested_get(self.config, ('global', 'languages', 'language_code_replacements'))
self.setup_insertion_probabilities()
self.setup_no_name_templates()
self.setup_place_only_templates()
@@ -681,6 +683,7 @@ class AddressFormatter(object):
def get_template_from_config(self, config, country, language=None):
template = None
if language:
language = self.language_code_replacements.get(language, language)
# For countries like China and Japan where the country format varies
# based on which language is being used
template = config.get('{}_{}'.format(country.upper(), language.lower()), None)