bisu 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +5 -0
- data/bisu.gemspec +1 -1
- data/lib/bisu/translator.rb +24 -6
- data/test/test_bisu_translator.rb +27 -10
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3653a0a2945c287e0d77426b0701596ecbc626e7
|
4
|
+
data.tar.gz: c1c4ea04cedda5020ffd836589e885a482ddeef5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e3bf46581c3d02f52e1ba3820680be3dfb07190c1171ecd29d66e4ec4f3725d8b39caca86f4379e8427e8801d622577d1ec4a98a2d69a8862bcb2691820f9f
|
7
|
+
data.tar.gz: ecb9703fd7ef9c39b9fbaf537824554fee0acb9ada737ae0bcc3002fd76fff61cc420e29641cbbb5b40fd55d6b24512f213c033b4f1e27b5f5cefdf043ac3584
|
data/README.md
CHANGED
@@ -60,6 +60,8 @@ Configuration
|
|
60
60
|
"klGeneral_Delete" = "$kDelete$";
|
61
61
|
"klGeneral_Cancel" = "$kCancel$";
|
62
62
|
"klGeneral_Close" = "$kClose$";
|
63
|
+
|
64
|
+
"klRequestName" = "$kRequestName%{user_name: %@}$";
|
63
65
|
```
|
64
66
|
|
65
67
|
1. Create a \*.translatable version for your **Android** localization files:
|
@@ -75,6 +77,7 @@ Configuration
|
|
75
77
|
<string name="delete">$kDelete$</string>
|
76
78
|
<string name="cancel">$kCancel$</string>
|
77
79
|
<string name="close">$kClose$</string>
|
80
|
+
<string name="request_name">$kRequestName%{user_name: %s}$</string>
|
78
81
|
</resources>
|
79
82
|
```
|
80
83
|
|
@@ -86,4 +89,6 @@ Configuration
|
|
86
89
|
delete: $kDelete$
|
87
90
|
cancel: $kCancel$
|
88
91
|
close: $kClose$
|
92
|
+
messages:
|
93
|
+
request_name: $kRequestName$
|
89
94
|
```
|
data/bisu.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'bisu'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.2.0'
|
4
4
|
s.date = '2015-07-01'
|
5
5
|
s.summary = 'A localization automation service'
|
6
6
|
s.description = 'Bisu manages your app iOS and Android localization files for you. No more copy+paste induced errors!'
|
data/lib/bisu/translator.rb
CHANGED
@@ -56,11 +56,12 @@ module Bisu
|
|
56
56
|
t = t.gsub("$specialKComment1$", "This file was automatically generated based on a translation template.")
|
57
57
|
t = t.gsub("$specialKComment2$", "Remember to CHANGE THE TEMPLATE and not this file!")
|
58
58
|
|
59
|
-
|
60
|
-
if localized = @kb.localize(
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
if l = localization_params(t)
|
60
|
+
if localized = @kb.localize(l[:loc_key], language)
|
61
|
+
l[:loc_vars].each do |param, value|
|
62
|
+
localized = localized.gsub("%{#{param}}", value)
|
63
|
+
end
|
64
|
+
t = t.gsub(l[:match], process(localized))
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
@@ -69,9 +70,26 @@ module Bisu
|
|
69
70
|
t
|
70
71
|
end
|
71
72
|
|
73
|
+
def localization_params(text)
|
74
|
+
return nil unless matches = text.match(/\$(k[^\$\{]+)(?:\{(.+)\})?\$/)
|
75
|
+
|
76
|
+
loc_vars = if matches[2]
|
77
|
+
vars = matches[2].split(",").map(&:strip)
|
78
|
+
vars = vars.map do |var|
|
79
|
+
key, value = var.split(":", 2).map(&:strip)
|
80
|
+
[key.to_sym, value]
|
81
|
+
end
|
82
|
+
Hash[vars]
|
83
|
+
end
|
84
|
+
|
85
|
+
{ match: matches[0],
|
86
|
+
loc_key: matches[1],
|
87
|
+
loc_vars: loc_vars || {} }
|
88
|
+
end
|
89
|
+
|
72
90
|
def process(text)
|
73
91
|
if @type.eql?(:android)
|
74
|
-
text = text.gsub(/[']/, "
|
92
|
+
text = text.gsub(/[']/, "\\\\\\\\'")
|
75
93
|
text = text.gsub("...", "…")
|
76
94
|
text = text.gsub("& ", "& ")
|
77
95
|
|
@@ -10,11 +10,13 @@ class BisuTranslatorTest < Minitest::Test
|
|
10
10
|
kb = Bisu::KnowledgeBase.new({
|
11
11
|
languages: [@lang],
|
12
12
|
keys: {
|
13
|
-
"kRegularKey"
|
14
|
-
"kIOSKey"
|
15
|
-
"kAndroidKey1"
|
16
|
-
"kAndroidKey2"
|
17
|
-
"kAndroidKey3"
|
13
|
+
"kRegularKey" => { @lang => "Não sabes nada João das Neves" },
|
14
|
+
"kIOSKey" => { @lang => "Não sabes nada \"João das Neves\"" },
|
15
|
+
"kAndroidKey1" => { @lang => "Não sabes nada 'João das Neves'" },
|
16
|
+
"kAndroidKey2" => { @lang => "Não sabes nada João das Neves..." },
|
17
|
+
"kAndroidKey3" => { @lang => "Não sabes nada João das Neves & Pícaros" },
|
18
|
+
"k1ParameterKey" => { @lang => "Não sabes nada %{name}" },
|
19
|
+
"k2ParametersKey" => { @lang => "Sabes %{percentage} por cento %{name}." },
|
18
20
|
}
|
19
21
|
})
|
20
22
|
|
@@ -29,19 +31,34 @@ class BisuTranslatorTest < Minitest::Test
|
|
29
31
|
orig3 = "3: $specialKLanguage$"
|
30
32
|
orig4 = "4: $specialKLocale$"
|
31
33
|
orig5 = "5: $kRegularKey$"
|
34
|
+
orig6_1 = "6.1: $k1ParameterKey$"
|
35
|
+
orig6_2 = "6.2: $k1ParameterKey{name:%1$s}$"
|
36
|
+
orig7_1 = "7.1: $k2ParametersKey$"
|
37
|
+
orig7_2 = "7.2: $k2ParametersKey{percentage:%2$d, name:%1$s}$"
|
38
|
+
orig7_3 = "7.3: $k2ParametersKey{name:%1$s, percentage:%2$d}$"
|
32
39
|
|
33
40
|
loc1 = "1: This file was automatically generated based on a translation template."
|
34
41
|
loc2 = "2: Remember to CHANGE THE TEMPLATE and not this file!"
|
35
42
|
loc3 = "3: #{@lang}"
|
36
43
|
loc4 = "4: #{@locale}"
|
37
44
|
loc5 = "5: Não sabes nada João das Neves"
|
45
|
+
loc6_1 = "6.1: Não sabes nada %{name}"
|
46
|
+
loc6_2 = "6.2: Não sabes nada %1$s"
|
47
|
+
loc7_1 = "7.1: Sabes %{percentage} por cento %{name}."
|
48
|
+
loc7_2 = "7.2: Sabes %2$d por cento %1$s."
|
49
|
+
loc7_3 = "7.3: Sabes %2$d por cento %1$s."
|
38
50
|
|
39
51
|
[@tios, @tand, @tror].each do |translator|
|
40
|
-
assert_equal translator.send(:localize, orig1,
|
41
|
-
assert_equal translator.send(:localize, orig2,
|
42
|
-
assert_equal translator.send(:localize, orig3,
|
43
|
-
assert_equal translator.send(:localize, orig4,
|
44
|
-
assert_equal translator.send(:localize, orig5,
|
52
|
+
assert_equal translator.send(:localize, orig1, @lang, @locale), loc1
|
53
|
+
assert_equal translator.send(:localize, orig2, @lang, @locale), loc2
|
54
|
+
assert_equal translator.send(:localize, orig3, @lang, @locale), loc3
|
55
|
+
assert_equal translator.send(:localize, orig4, @lang, @locale), loc4
|
56
|
+
assert_equal translator.send(:localize, orig5, @lang, @locale), loc5
|
57
|
+
assert_equal translator.send(:localize, orig6_1, @lang, @locale), loc6_1
|
58
|
+
assert_equal translator.send(:localize, orig6_2, @lang, @locale), loc6_2
|
59
|
+
assert_equal translator.send(:localize, orig7_1, @lang, @locale), loc7_1
|
60
|
+
assert_equal translator.send(:localize, orig7_2, @lang, @locale), loc7_2
|
61
|
+
assert_equal translator.send(:localize, orig7_3, @lang, @locale), loc7_3
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|