twine 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/twine/formatters/android.rb +16 -8
- data/lib/twine/version.rb +1 -1
- data/test/test_formatters.rb +75 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6d46a283d86aa50c84b7b229f2e3159edd72816
|
4
|
+
data.tar.gz: c412942ce007dbd236cc32b4b9ceadf99734cbe4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b44a73df4eb789f78cbec2a37cbe496f7cda95ea62b7e56c2eb189d5f26b5c0a5ef497b7c185a78961ba263df64e386a7efc2b58a58dab540eb0ea9a81b68922
|
7
|
+
data.tar.gz: c9814e961ac0c8eb36c61122c89b3d9bd321133dd8b0441e2cfdd352a65e71d74cf8cae31d0da9903988e80c524fef332dd5fc56c2d4dc622e3f581364770636
|
data/README.md
CHANGED
@@ -80,7 +80,7 @@ Twine currently supports the following output formats:
|
|
80
80
|
* [Android String Resources][androidstrings] (format: android)
|
81
81
|
* HTML tags will be escaped by replacing `<` with `<`
|
82
82
|
* Tags inside `<![CDATA[` won't be escaped.
|
83
|
-
* Supports [basic styling][androidstyling]
|
83
|
+
* Supports [basic styling][androidstyling] according to [Android documentation](https://developer.android.com/guide/topics/resources/string-resource.html#StylingWithHTML). All of the documented tags are supported, in addition to `<a>` links.
|
84
84
|
* These tags will *not* be escaped if the string doesn't contain placeholders. You can reference them directly in your layouts or by using [`getText()`](https://developer.android.com/reference/android/content/res/Resources.html#getText(int)) to read them programatically.
|
85
85
|
* These tags *will* be escaped if the string contains placeholders. You can use [`getString()`](https://developer.android.com/reference/android/content/res/Resources.html#getString(int,%20java.lang.Object...)) combined with [`fromHtml`](https://developer.android.com/reference/android/text/Html.html#fromHtml(java.lang.String)) as shown in the [documentation][androidstyling] to display them.
|
86
86
|
* See [\#212](https://github.com/scelis/twine/issues/212) for details.
|
@@ -41,7 +41,11 @@ module Twine
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def output_path_for_language(lang)
|
44
|
-
|
44
|
+
if lang == @twine_file.language_codes[0]
|
45
|
+
"values"
|
46
|
+
else
|
47
|
+
"values-#{lang}".gsub(/-(\p{Lu})/, '-r\1')
|
48
|
+
end
|
45
49
|
end
|
46
50
|
|
47
51
|
def set_translation_for_key(key, lang, value)
|
@@ -109,22 +113,26 @@ module Twine
|
|
109
113
|
|
110
114
|
# http://developer.android.com/guide/topics/resources/string-resource.html#FormattingAndStyling
|
111
115
|
def escape_value(value)
|
112
|
-
inside_cdata = /<\!\[CDATA\[((?!\]\]>).)*$/
|
113
|
-
|
116
|
+
inside_cdata = /<\!\[CDATA\[((?!\]\]>).)*$/ # opening CDATA tag ('<![CDATA[') not followed by a closing tag (']]>')
|
117
|
+
inside_opening_tag = /<(a|font|span|p)\s?((?!>).)*$/ # tag start ('<a ', '<font ', '<span ' or '<p ') not followed by a '>'
|
114
118
|
|
115
119
|
# escape double and single quotes and & signs
|
116
|
-
value = gsub_unless(value, '"', '\\"') { |substring| substring =~ inside_cdata || substring =~
|
120
|
+
value = gsub_unless(value, '"', '\\"') { |substring| substring =~ inside_cdata || substring =~ inside_opening_tag }
|
117
121
|
value = gsub_unless(value, "'", "\\'") { |substring| substring =~ inside_cdata }
|
118
|
-
value = gsub_unless(value, /&/, '&') { |substring| substring =~ inside_cdata || substring =~
|
122
|
+
value = gsub_unless(value, /&/, '&') { |substring| substring =~ inside_cdata || substring =~ inside_opening_tag }
|
119
123
|
|
120
124
|
# if `value` contains a placeholder, escape all angle brackets
|
121
125
|
# if not, escape opening angle brackes unless it's a supported styling tag
|
122
126
|
# https://github.com/scelis/twine/issues/212
|
123
127
|
# https://stackoverflow.com/questions/3235131/#18199543
|
124
128
|
if number_of_twine_placeholders(value) > 0
|
125
|
-
|
126
|
-
|
127
|
-
|
129
|
+
# matches all `<` but <![CDATA
|
130
|
+
angle_bracket = /<(?!(\/?(\!\[CDATA)))/
|
131
|
+
else
|
132
|
+
# matches all '<' but <b>, <em>, <i>, <cite>, <dfn>, <big>, <small>, <font>, <tt>, <s>,
|
133
|
+
# <strike>, <del>, <u>, <super>, <sub>, <ul>, <li>, <br>, <div>, <span>, <p>, <a>
|
134
|
+
# and <![CDATA
|
135
|
+
angle_bracket = /<(?!(\/?(b|em|i|cite|dfn|big|small|font|tt|s|strike|del|u|super|sub|ul|li|br|div|span|p|a|\!\[CDATA)))/
|
128
136
|
end
|
129
137
|
value = gsub_unless(value, angle_bracket, '<') { |substring| substring =~ inside_cdata }
|
130
138
|
|
data/lib/twine/version.rb
CHANGED
data/test/test_formatters.rb
CHANGED
@@ -47,26 +47,87 @@ class TestAndroidFormatter < FormatterTest
|
|
47
47
|
'a "good" way' => 'a \"good\" way',
|
48
48
|
|
49
49
|
'<b>bold</b>' => '<b>bold</b>',
|
50
|
+
'<em>bold</em>' => '<em>bold</em>',
|
51
|
+
|
50
52
|
'<i>italic</i>' => '<i>italic</i>',
|
53
|
+
'<cite>italic</cite>' => '<cite>italic</cite>',
|
54
|
+
'<dfn>italic</dfn>' => '<dfn>italic</dfn>',
|
55
|
+
|
56
|
+
'<big>larger</big>' => '<big>larger</big>',
|
57
|
+
'<small>smaller</small>' => '<small>smaller</small>',
|
58
|
+
|
59
|
+
'<font color="#45C1D0">F</font>' => '<font color="#45C1D0">F</font>',
|
60
|
+
|
61
|
+
'<tt>monospaced</tt>' => '<tt>monospaced</tt>',
|
62
|
+
|
63
|
+
'<s>strike</s>' => '<s>strike</s>',
|
64
|
+
'<strike>strike</strike>' => '<strike>strike</strike>',
|
65
|
+
'<del>strike</del>' => '<del>strike</del>',
|
66
|
+
|
51
67
|
'<u>underline</u>' => '<u>underline</u>',
|
52
68
|
|
69
|
+
'<super>superscript</super>'=> '<super>superscript</super>',
|
70
|
+
|
71
|
+
'<sub>subscript</sub>' => '<sub>subscript</sub>',
|
72
|
+
|
73
|
+
'<ul>bullet point</ul>' => '<ul>bullet point</ul>',
|
74
|
+
'<li>bullet point</li>' => '<li>bullet point</li>',
|
75
|
+
|
76
|
+
'<br>line break' => '<br>line break',
|
77
|
+
|
78
|
+
'<div>division</div>' => '<div>division</div>',
|
79
|
+
|
80
|
+
'<span style="color:#45C1D0">inline</span>' => '<span style="color:#45C1D0">inline</span>',
|
81
|
+
|
82
|
+
'<p>para</p>' => '<p>para</p>',
|
83
|
+
'<p dir="ltr">para</p>' => '<p dir="ltr">para</p>',
|
84
|
+
|
53
85
|
'<b>%@</b>' => '<b>%s</b>',
|
86
|
+
'<em>%@</em>' => '<em>%s</em>',
|
87
|
+
|
54
88
|
'<i>%@</i>' => '<i>%s</i>',
|
89
|
+
'<cite>%@</cite>' => '<cite>%s</cite>',
|
90
|
+
'<dfn>%@</dfn>' => '<dfn>%s</dfn>',
|
91
|
+
|
92
|
+
'<big>%@</big>' => '<big>%s</big>',
|
93
|
+
'<small>%@</small>' => '<small>%s</small>',
|
94
|
+
|
95
|
+
'<font color="#45C1D0>%@</font>' => '<font color="#45C1D0>%s</font>',
|
96
|
+
|
97
|
+
'<tt>%@</tt>' => '<tt>%s</tt>',
|
98
|
+
|
99
|
+
'<s>%@</s>' => '<s>%s</s>',
|
100
|
+
'<strike>%@</strike>' => '<strike>%s</strike>',
|
101
|
+
'<del>%@</del>' => '<del>%s</del>',
|
102
|
+
|
55
103
|
'<u>%@</u>' => '<u>%s</u>',
|
56
104
|
|
57
|
-
'<
|
58
|
-
|
105
|
+
'<super>%@</super>' => '<super>%s</super>',
|
106
|
+
|
107
|
+
'<sub>%@</sub>' => '<sub>%s</sub>',
|
108
|
+
|
109
|
+
'<ul>%@</ul>' => '<ul>%s</ul>',
|
110
|
+
'<li>%@</li>' => '<li>%s</li>',
|
111
|
+
|
112
|
+
'<br>%@' => '<br>%s',
|
113
|
+
|
114
|
+
'<div>%@</div>' => '<div>%s</div>',
|
115
|
+
|
116
|
+
'<span style="color:#45C1D0">%@</span>' => '<span style="color:#45C1D0">%s</span>',
|
117
|
+
|
118
|
+
'<p>%@</p>' => '<p>%s</p>',
|
119
|
+
'<p dir="ltr">%@</p>' => '<p dir="ltr">%s</p>',
|
59
120
|
|
60
121
|
'<a href="target">link</a>' => '<a href="target">link</a>',
|
61
122
|
'<a href="target">"link"</a>' => '<a href="target">\"link\"</a>',
|
62
123
|
'<a href="target"></a>"out"' => '<a href="target"></a>\"out\"',
|
63
124
|
'<a href="http://url.com?param=1¶m2=3¶m3=%20">link</a>' => '<a href="http://url.com?param=1¶m2=3¶m3=%20">link</a>',
|
64
125
|
|
65
|
-
'<
|
66
|
-
'<![CDATA[]]><
|
67
|
-
'<![CDATA[<
|
68
|
-
'<![CDATA[<
|
69
|
-
'<![CDATA[]]><![CDATA[<
|
126
|
+
'<q>escaped</q><![CDATA[]]>' => '<q>escaped</q><![CDATA[]]>',
|
127
|
+
'<![CDATA[]]><q>escaped</q>' => '<![CDATA[]]><q>escaped</q>',
|
128
|
+
'<![CDATA[<q>unescaped</q>]]>' => '<![CDATA[<q>unescaped</q>]]>',
|
129
|
+
'<![CDATA[<q>unescaped with %@</q>]]>' => '<![CDATA[<q>unescaped with %s</q>]]>',
|
130
|
+
'<![CDATA[]]><![CDATA[<q>unescaped</q>]]>' => '<![CDATA[]]><![CDATA[<q>unescaped</q>]]>',
|
70
131
|
|
71
132
|
'<![CDATA[&]]>' => '<![CDATA[&]]>',
|
72
133
|
'<![CDATA[\']]>' => '<![CDATA[\']]>',
|
@@ -231,6 +292,13 @@ class TestAndroidFormatter < FormatterTest
|
|
231
292
|
def test_output_path_with_region
|
232
293
|
assert_equal 'values-en-rGB', @formatter.output_path_for_language('en-GB')
|
233
294
|
end
|
295
|
+
|
296
|
+
def test_output_path_respects_default_lang
|
297
|
+
@formatter.twine_file.language_codes.concat KNOWN_LANGUAGES
|
298
|
+
non_default_language = KNOWN_LANGUAGES[1..-1].sample
|
299
|
+
assert_equal 'values', @formatter.output_path_for_language(KNOWN_LANGUAGES[0])
|
300
|
+
assert_equal "values-#{non_default_language}", @formatter.output_path_for_language(non_default_language)
|
301
|
+
end
|
234
302
|
end
|
235
303
|
|
236
304
|
class TestAppleFormatter < FormatterTest
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -177,7 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
- !ruby/object:Gem::Version
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
|
-
|
180
|
+
rubyforge_project:
|
181
|
+
rubygems_version: 2.5.2.3
|
181
182
|
signing_key:
|
182
183
|
specification_version: 4
|
183
184
|
summary: Manage strings and their translations for your iOS, Android and other projects.
|