-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use 2 letter language codes #975
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -346,10 +346,10 @@ def _convert_wof_l10n_name(x): | |
if len(lang_str_iso_639_3) != 3: | ||
return None | ||
try: | ||
pycountry.languages.get(iso639_3_code=lang_str_iso_639_3) | ||
lang = pycountry.languages.get(iso639_3_code=lang_str_iso_639_3) | ||
except KeyError: | ||
return None | ||
return lang_str_iso_639_3 | ||
return lang.iso639_1_code | ||
|
||
|
||
def _normalize_osm_lang_code(x): | ||
|
@@ -366,8 +366,11 @@ def _normalize_osm_lang_code(x): | |
lang = pycountry.languages.get(iso639_3_code=x) | ||
except KeyError: | ||
return None | ||
iso639_3_code = lang.iso639_3_code.encode('utf-8') | ||
return iso639_3_code | ||
try: | ||
iso639_1_code = lang.iso639_1_code.encode('utf-8') | ||
except AttributeError: | ||
return None | ||
return iso639_1_code | ||
|
||
|
||
def _normalize_country_code(x): | ||
|
@@ -386,38 +389,38 @@ def _normalize_country_code(x): | |
return alpha2_code | ||
|
||
|
||
osm_l10n_lookup = { | ||
'zh-min-nan': 'nan', | ||
'zh-yue': 'yue', | ||
} | ||
|
||
|
||
def osm_l10n_name_lookup(x): | ||
lookup = osm_l10n_lookup.get(x) | ||
if lookup is not None: | ||
return lookup | ||
else: | ||
return x | ||
osm_l10n_lookup = set([ | ||
'zh-min-nan', | ||
'zh-yue' | ||
]) | ||
|
||
|
||
def _convert_osm_l10n_name(x): | ||
x = osm_l10n_name_lookup(x) | ||
if x in osm_l10n_lookup: | ||
return x | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to preserve these variations, or normalize them? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assumed that if we handled them specially before, we'd want to keep them now? @nvkelso what do you think? |
||
|
||
if '_' not in x: | ||
return _normalize_osm_lang_code(x) | ||
lang_code_candidate = x | ||
country_candidate = None | ||
|
||
fields_by_underscore = x.split('_', 1) | ||
lang_code_candidate, country_candidate = fields_by_underscore | ||
else: | ||
fields_by_underscore = x.split('_', 1) | ||
lang_code_candidate, country_candidate = fields_by_underscore | ||
|
||
lang_code_result = _normalize_osm_lang_code(lang_code_candidate) | ||
if lang_code_result is None: | ||
return None | ||
|
||
country_result = _normalize_country_code(country_candidate) | ||
if country_result is None: | ||
return None | ||
if country_candidate: | ||
country_result = _normalize_country_code(country_candidate) | ||
if country_result is None: | ||
return None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This matches the previous behavior, but I'm now wondering if it's better to keep the language code rather than dropping it on an invalid country code. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm wondering if we have something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. We can set it up so that we'll only set the language code if one doesn't already exist in this scenario, but the added complexity might not be worth it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've changed the behaviour in 4df4863 to keep the most specific language code. At the moment, that just means that any with an omitted country are less specific and won't overwrite a code without a country, e.g: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great idea with priorities! ⚡ My first thoughts were also to just return a more complex value object, but just whether the country code was invalid or not. The priority notion is a better generalization of that. |
||
|
||
result = '%s_%s' % (lang_code_result, country_result) | ||
|
||
else: | ||
result = lang_code_result | ||
|
||
result = '%s_%s' % (lang_code_result, country_result) | ||
return result | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be
ja
instead of jp.