Merge pull request #136 from sebastianludwig/android_langauges

Fixed Android language determination. Closes #134.
This commit is contained in:
Sebastian Celis 2016-02-22 16:32:59 -06:00
commit c863485b1d
2 changed files with 20 additions and 1 deletions

View file

@ -39,7 +39,9 @@ module Twine
if segment == 'values'
return @strings.language_codes[0]
else
match = /^values-(.*)$/.match(segment)
# The language is defined by a two-letter ISO 639-1 language code, optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r").
# see http://developer.android.com/guide/topics/resources/providing-resources.html#AlternativeResources
match = /^values-([a-z]{2}(-r[a-z]{2})?)$/i.match(segment)
if match
lang = match[1]
lang = LANG_CODES.fetch(lang, lang)

View file

@ -100,6 +100,23 @@ class TestAndroidFormatter < FormatterTest
identifier = '@android:string/cancel'
assert_equal identifier, @formatter.format_value(identifier)
end
def test_deducts_language_from_resource_folder
language = %w(en de fr).sample
assert_equal language, @formatter.determine_language_given_path("res/values-#{language}")
end
def test_deducts_language_and_region_from_resource_folder
assert_equal 'de-AT', @formatter.determine_language_given_path("res/values-de-rAT")
end
def test_maps_laguage_deducted_from_resource_folder
assert_equal 'zh-Hans', @formatter.determine_language_given_path("res/values-zh-rCN")
end
def test_does_not_deduct_language_from_device_capability_resource_folder
assert_nil @formatter.determine_language_given_path('res/values-w820p')
end
end
class TestAppleFormatter < FormatterTest