Added regional dialect fallback to generic language (#3)

* Added regional dialect fallback to generic language

Signed-off-by: David Martinez <47610359+dvdmrtnz@users.noreply.github.com>

* Reorder generic_language to mantain fallback_mapping priority

Signed-off-by: David Martinez <47610359+dvdmrtnz@users.noreply.github.com>

* Update lib/twine/output_processor.rb

Signed-off-by: David Martinez <47610359+dvdmrtnz@users.noreply.github.com>

Co-authored-by: Alexander Borsuk <170263+biodranik@users.noreply.github.com>

Co-authored-by: Alexander Borsuk <170263+biodranik@users.noreply.github.com>
This commit is contained in:
David Martinez 2022-03-23 13:00:10 +01:00 committed by GitHub
parent 96e0e2c3cd
commit 6cd569fa49
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,7 +17,12 @@ module Twine
'zh-TW' => 'zh-Hant' # if we don't have a zh-TW translation, try zh-Hant before en
}
[fallback_mapping[language], default_language].flatten.compact
# Regional dialect fallbacks to generic language (for example: 'es-MX' to 'es' instead of default 'en').
if language.match(/([a-zA-Z])-[a-zA-Z]+/)
generic_language = language.gsub(/([a-zA-Z])-[a-zA-Z]+/, '\1')
end
[fallback_mapping[language], generic_language, default_language].flatten.compact
end
def process(language)