Properly prefixing Android output path with values-.

This commit is contained in:
Sebastian Ludwig 2016-02-28 11:58:33 -06:00
parent c863485b1d
commit f29d73c6fa
2 changed files with 15 additions and 3 deletions

View file

@ -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!('\\\'', '\'')

View file

@ -117,6 +117,14 @@ class TestAndroidFormatter < FormatterTest
def test_does_not_deduct_language_from_device_capability_resource_folder
assert_nil @formatter.determine_language_given_path('res/values-w820p')
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