diff --git a/lib/twine/formatters/android.rb b/lib/twine/formatters/android.rb index 96de694..2a92ae4 100644 --- a/lib/twine/formatters/android.rb +++ b/lib/twine/formatters/android.rb @@ -7,11 +7,11 @@ module Twine class Android < Abstract include Twine::Placeholders - LANG_CODES = Hash[ - 'zh' => 'zh-Hans', + LANG_MAPPINGS = Hash[ 'zh-rCN' => 'zh-Hans', 'zh-rHK' => 'zh-Hant', 'en-rGB' => 'en-UK', + 'zh' => 'zh-Hans', 'in' => 'id', 'nb' => 'no' # TODO: spanish @@ -44,7 +44,7 @@ module Twine match = /^values-([a-z]{2}(-r[a-z]{2})?)$/i.match(segment) if match lang = match[1] - lang = LANG_CODES.fetch(lang, lang) + lang = LANG_MAPPINGS.fetch(lang, lang) lang.sub!('-r', '-') return lang end @@ -54,6 +54,10 @@ module Twine return end + def output_path_for_language(lang) + "values-" + (LANG_MAPPINGS.key(lang) || lang) + end + def set_translation_for_key(key, lang, value) value = CGI.unescapeHTML(value) value.gsub!('\\\'', '\'') diff --git a/test/test_formatters.rb b/test/test_formatters.rb index b9ebe28..5fbe584 100644 --- a/test/test_formatters.rb +++ b/test/test_formatters.rb @@ -116,6 +116,14 @@ class TestAndroidFormatter < FormatterTest def test_does_not_deduct_language_from_device_capability_resource_folder assert_nil @formatter.determine_language_given_path('res/values-w820dp') end + + def test_output_path_is_prefixed + assert_equal 'values-en', @formatter.output_path_for_language('en') + end + + def test_output_path_language_mappings + assert_equal 'values-zh-rCN', @formatter.output_path_for_language('zh-Hans') + end end class TestAppleFormatter < FormatterTest