[formatting] Moving language country overrides to formatter config so actual language is retained
This commit is contained in:
@@ -3,6 +3,11 @@ global:
|
|||||||
place_direction: right
|
place_direction: right
|
||||||
direction_probability: 0.9
|
direction_probability: 0.9
|
||||||
|
|
||||||
|
language_code_replacements:
|
||||||
|
ja_rm: en
|
||||||
|
ko_rm: en
|
||||||
|
zh_pinyin: en
|
||||||
|
|
||||||
insertions:
|
insertions:
|
||||||
# For each component, insertions are mutually exclusive
|
# For each component, insertions are mutually exclusive
|
||||||
# They don't have to sum to 1 (especially for components
|
# They don't have to sum to 1 (especially for components
|
||||||
|
|||||||
@@ -7,11 +7,6 @@ languages:
|
|||||||
# Replace user-tagged admin components with the non-local language version
|
# Replace user-tagged admin components with the non-local language version
|
||||||
replace_non_local_probability: 0.4
|
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"
|
# Dependencies for including each component in an "address"
|
||||||
# Two-way dependencies are not an issue
|
# Two-way dependencies are not an issue
|
||||||
component_dependencies:
|
component_dependencies:
|
||||||
|
|||||||
@@ -180,6 +180,8 @@ class AddressFormatter(object):
|
|||||||
self.load_config()
|
self.load_config()
|
||||||
self.load_country_formats()
|
self.load_country_formats()
|
||||||
|
|
||||||
|
self.language_code_replacements = nested_get(self.config, ('global', 'languages', 'language_code_replacements'))
|
||||||
|
|
||||||
self.setup_insertion_probabilities()
|
self.setup_insertion_probabilities()
|
||||||
self.setup_no_name_templates()
|
self.setup_no_name_templates()
|
||||||
self.setup_place_only_templates()
|
self.setup_place_only_templates()
|
||||||
@@ -681,6 +683,7 @@ class AddressFormatter(object):
|
|||||||
def get_template_from_config(self, config, country, language=None):
|
def get_template_from_config(self, config, country, language=None):
|
||||||
template = None
|
template = None
|
||||||
if language:
|
if language:
|
||||||
|
language = self.language_code_replacements.get(language, language)
|
||||||
# For countries like China and Japan where the country format varies
|
# For countries like China and Japan where the country format varies
|
||||||
# based on which language is being used
|
# based on which language is being used
|
||||||
template = config.get('{}_{}'.format(country.upper(), language.lower()), None)
|
template = config.get('{}_{}'.format(country.upper(), language.lower()), None)
|
||||||
|
|||||||
Reference in New Issue
Block a user