twine 0.9.1 → 0.10.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 +56 -69
- data/lib/twine.rb +11 -3
- data/lib/twine/cli.rb +375 -155
- data/lib/twine/formatters.rb +0 -5
- data/lib/twine/formatters/abstract.rb +43 -43
- data/lib/twine/formatters/android.rb +58 -59
- data/lib/twine/formatters/apple.rb +3 -3
- data/lib/twine/formatters/django.rb +15 -21
- data/lib/twine/formatters/flash.rb +17 -20
- data/lib/twine/formatters/gettext.rb +11 -15
- data/lib/twine/formatters/jquery.rb +8 -11
- data/lib/twine/formatters/tizen.rb +4 -4
- data/lib/twine/output_processor.rb +15 -15
- data/lib/twine/placeholders.rb +26 -6
- data/lib/twine/runner.rb +95 -95
- data/lib/twine/{stringsfile.rb → twine_file.rb} +53 -48
- data/lib/twine/version.rb +1 -1
- data/test/{command_test_case.rb → command_test.rb} +5 -5
- data/test/fixtures/{consume_loc_drop.zip → consume_localization_archive.zip} +0 -0
- data/test/fixtures/formatter_django.po +3 -1
- data/test/test_abstract_formatter.rb +40 -40
- data/test/test_cli.rb +313 -211
- data/test/test_consume_localization_archive.rb +27 -0
- data/test/{test_consume_string_file.rb → test_consume_localization_file.rb} +19 -19
- data/test/test_formatters.rb +108 -43
- data/test/{test_generate_all_string_files.rb → test_generate_all_localization_files.rb} +18 -18
- data/test/{test_generate_loc_drop.rb → test_generate_localization_archive.rb} +14 -14
- data/test/{test_generate_string_file.rb → test_generate_localization_file.rb} +18 -18
- data/test/test_output_processor.rb +26 -26
- data/test/test_placeholders.rb +44 -9
- data/test/test_twine_definition.rb +111 -0
- data/test/test_twine_file.rb +58 -0
- data/test/test_validate_twine_file.rb +61 -0
- data/test/twine_file_dsl.rb +12 -12
- data/test/{twine_test_case.rb → twine_test.rb} +1 -1
- metadata +23 -23
- data/test/test_consume_loc_drop.rb +0 -27
- data/test/test_strings_file.rb +0 -58
- data/test/test_strings_row.rb +0 -47
- data/test/test_validate_strings_file.rb +0 -61
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'twine_test'
|
2
|
+
|
3
|
+
class TestTwineDefinition < TwineTest
|
4
|
+
class TestTags < TwineTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
@definition = Twine::TwineDefinition.new 'key'
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_include_untagged
|
11
|
+
assert @definition.matches_tags?([[rand(100000).to_s]], true)
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_matches_no_given_tags
|
15
|
+
assert @definition.matches_tags?([], false)
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_matches_tag
|
19
|
+
@definition.tags = ['tag1']
|
20
|
+
|
21
|
+
assert @definition.matches_tags?([['tag1']], false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_matches_any_tag
|
25
|
+
@definition.tags = ['tag1']
|
26
|
+
|
27
|
+
assert @definition.matches_tags?([['tag0', 'tag1', 'tag2']], false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_matches_all_tags
|
31
|
+
@definition.tags = ['tag1', 'tag2']
|
32
|
+
|
33
|
+
assert @definition.matches_tags?([['tag1'], ['tag2']], false)
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_does_not_match_all_tags
|
37
|
+
@definition.tags = ['tag1']
|
38
|
+
|
39
|
+
refute @definition.matches_tags?([['tag1'], ['tag2']], false)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_does_not_match_excluded_tag
|
43
|
+
@definition.tags = ['tag1']
|
44
|
+
|
45
|
+
refute @definition.matches_tags?([['~tag1']], false)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_matches_excluded_tag
|
49
|
+
@definition.tags = ['tag2']
|
50
|
+
|
51
|
+
assert @definition.matches_tags?([['~tag1']], false)
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_complex_rules
|
55
|
+
@definition.tags = ['tag1', 'tag2', 'tag3']
|
56
|
+
|
57
|
+
assert @definition.matches_tags?([['tag1']], false)
|
58
|
+
assert @definition.matches_tags?([['tag1', 'tag4']], false)
|
59
|
+
assert @definition.matches_tags?([['tag1'], ['tag2'], ['tag3']], false)
|
60
|
+
refute @definition.matches_tags?([['tag1'], ['tag4']], false)
|
61
|
+
|
62
|
+
assert @definition.matches_tags?([['tag4', '~tag5']], false)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
class TestReferences < TwineTest
|
67
|
+
def setup
|
68
|
+
super
|
69
|
+
|
70
|
+
@reference = Twine::TwineDefinition.new 'reference-key'
|
71
|
+
@reference.comment = 'reference comment'
|
72
|
+
@reference.tags = ['ref1']
|
73
|
+
@reference.translations['en'] = 'ref-value'
|
74
|
+
|
75
|
+
@definition = Twine::TwineDefinition.new 'key'
|
76
|
+
@definition.reference_key = @reference.key
|
77
|
+
@definition.reference = @reference
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_reference_comment_used
|
81
|
+
assert_equal 'reference comment', @definition.comment
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_reference_comment_override
|
85
|
+
@definition.comment = 'definition comment'
|
86
|
+
|
87
|
+
assert_equal 'definition comment', @definition.comment
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_reference_tags_used
|
91
|
+
assert @definition.matches_tags?([['ref1']], false)
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_reference_tags_override
|
95
|
+
@definition.tags = ['tag1']
|
96
|
+
|
97
|
+
refute @definition.matches_tags?([['ref1']], false)
|
98
|
+
assert @definition.matches_tags?([['tag1']], false)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_reference_translation_used
|
102
|
+
assert_equal 'ref-value', @definition.translation_for_lang('en')
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_reference_translation_override
|
106
|
+
@definition.translations['en'] = 'value'
|
107
|
+
|
108
|
+
assert_equal 'value', @definition.translation_for_lang('en')
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'twine_test'
|
2
|
+
|
3
|
+
class TestTwineFile < TwineTest
|
4
|
+
class Reading < TwineTest
|
5
|
+
def setup
|
6
|
+
super
|
7
|
+
|
8
|
+
@twine_file = Twine::TwineFile.new
|
9
|
+
@twine_file.read fixture_path('twine_accent_values.txt')
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_reading_keeps_leading_accent
|
13
|
+
assert_equal '`value', @twine_file.definitions_by_key['value_with_leading_accent'].translations['en']
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_reading_keeps_trailing_accent
|
17
|
+
assert_equal 'value`', @twine_file.definitions_by_key['value_with_trailing_accent'].translations['en']
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_reading_keeps_leading_space
|
21
|
+
assert_equal ' value', @twine_file.definitions_by_key['value_with_leading_space'].translations['en']
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_reading_keeps_trailing_space
|
25
|
+
assert_equal 'value ', @twine_file.definitions_by_key['value_with_trailing_space'].translations['en']
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_reading_keeps_wrapping_spaces
|
29
|
+
assert_equal ' value ', @twine_file.definitions_by_key['value_wrapped_by_spaces'].translations['en']
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_reading_keeps_wrapping_accents
|
33
|
+
assert_equal '`value`', @twine_file.definitions_by_key['value_wrapped_by_accents'].translations['en']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class Writing < TwineTest
|
38
|
+
|
39
|
+
def test_accent_wrapping
|
40
|
+
@twine_file = build_twine_file 'en' do
|
41
|
+
add_section 'Section' do
|
42
|
+
add_definition value_with_leading_accent: '`value'
|
43
|
+
add_definition value_with_trailing_accent: 'value`'
|
44
|
+
add_definition value_with_leading_space: ' value'
|
45
|
+
add_definition value_with_trailing_space: 'value '
|
46
|
+
add_definition value_wrapped_by_spaces: ' value '
|
47
|
+
add_definition value_wrapped_by_accents: '`value`'
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
@twine_file.write @output_path
|
52
|
+
|
53
|
+
assert_equal content('twine_accent_values.txt'), File.read(@output_path)
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'command_test'
|
4
|
+
|
5
|
+
class TestValidateTwineFile < CommandTest
|
6
|
+
def setup
|
7
|
+
super
|
8
|
+
@options = { twine_file: 'input.txt' }
|
9
|
+
|
10
|
+
@twine_file = build_twine_file 'en' do
|
11
|
+
add_section 'Section 1' do
|
12
|
+
add_definition key1: 'value1', tags: ['tag1']
|
13
|
+
add_definition key2: 'value2', tags: ['tag1']
|
14
|
+
end
|
15
|
+
|
16
|
+
add_section 'Section 2' do
|
17
|
+
add_definition key3: 'value3', tags: ['tag1', 'tag2']
|
18
|
+
add_definition key4: 'value4', tags: ['tag2']
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def random_definition
|
24
|
+
@twine_file.definitions_by_key[@twine_file.definitions_by_key.keys.sample]
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_recognizes_valid_file
|
28
|
+
Twine::Runner.new(@options, @twine_file).validate_twine_file
|
29
|
+
assert_equal "input.txt is valid.\n", Twine::stdout.string
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_reports_duplicate_keys
|
33
|
+
@twine_file.sections[0].definitions << random_definition
|
34
|
+
|
35
|
+
assert_raises Twine::Error do
|
36
|
+
Twine::Runner.new(@options, @twine_file).validate_twine_file
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_reports_invalid_characters_in_keys
|
41
|
+
random_definition.key[0] = "!?;:,^`´'\"\\|/(){}[]~-+*=#$%".chars.to_a.sample
|
42
|
+
|
43
|
+
assert_raises Twine::Error do
|
44
|
+
Twine::Runner.new(@options, @twine_file).validate_twine_file
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_does_not_reports_missing_tags_by_default
|
49
|
+
random_definition.tags.clear
|
50
|
+
|
51
|
+
Twine::Runner.new(@options, @twine_file).validate_twine_file
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_reports_missing_tags
|
55
|
+
random_definition.tags.clear
|
56
|
+
|
57
|
+
assert_raises Twine::Error do
|
58
|
+
Twine::Runner.new(@options.merge(pedantic: true), @twine_file).validate_twine_file
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/test/twine_file_dsl.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module TwineFileDSL
|
2
2
|
def build_twine_file(*languages)
|
3
|
-
@currently_built_twine_file = Twine::
|
3
|
+
@currently_built_twine_file = Twine::TwineFile.new
|
4
4
|
@currently_built_twine_file.language_codes.concat languages
|
5
5
|
yield
|
6
6
|
result = @currently_built_twine_file
|
@@ -10,37 +10,37 @@ module TwineFileDSL
|
|
10
10
|
|
11
11
|
def add_section(name)
|
12
12
|
return unless @currently_built_twine_file
|
13
|
-
@currently_built_twine_file_section = Twine::
|
13
|
+
@currently_built_twine_file_section = Twine::TwineSection.new name
|
14
14
|
@currently_built_twine_file.sections << @currently_built_twine_file_section
|
15
15
|
yield
|
16
16
|
@currently_built_twine_file_section = nil
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
19
|
+
def add_definition(parameters)
|
20
20
|
return unless @currently_built_twine_file
|
21
21
|
return unless @currently_built_twine_file_section
|
22
22
|
|
23
23
|
# this relies on Ruby preserving the order of hash elements
|
24
24
|
key, value = parameters.first
|
25
|
-
|
25
|
+
definition = Twine::TwineDefinition.new(key.to_s)
|
26
26
|
if value.is_a? Hash
|
27
27
|
value.each do |language, translation|
|
28
|
-
|
28
|
+
definition.translations[language.to_s] = translation
|
29
29
|
end
|
30
30
|
elsif !value.is_a? Symbol
|
31
31
|
language = @currently_built_twine_file.language_codes.first
|
32
|
-
|
32
|
+
definition.translations[language] = value
|
33
33
|
end
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
definition.comment = parameters[:comment] if parameters[:comment]
|
36
|
+
definition.tags = parameters[:tags] if parameters[:tags]
|
37
37
|
if parameters[:ref] || value.is_a?(Symbol)
|
38
38
|
reference_key = (parameters[:ref] || value).to_s
|
39
|
-
|
40
|
-
|
39
|
+
definition.reference_key = reference_key
|
40
|
+
definition.reference = @currently_built_twine_file.definitions_by_key[reference_key]
|
41
41
|
end
|
42
42
|
|
43
|
-
@currently_built_twine_file_section.
|
44
|
-
@currently_built_twine_file.
|
43
|
+
@currently_built_twine_file_section.definitions << definition
|
44
|
+
@currently_built_twine_file.definitions_by_key[definition.key] = definition
|
45
45
|
end
|
46
46
|
end
|
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: 0.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sebastian Celis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -110,10 +110,10 @@ files:
|
|
110
110
|
- lib/twine/placeholders.rb
|
111
111
|
- lib/twine/plugin.rb
|
112
112
|
- lib/twine/runner.rb
|
113
|
-
- lib/twine/
|
113
|
+
- lib/twine/twine_file.rb
|
114
114
|
- lib/twine/version.rb
|
115
|
-
- test/
|
116
|
-
- test/fixtures/
|
115
|
+
- test/command_test.rb
|
116
|
+
- test/fixtures/consume_localization_archive.zip
|
117
117
|
- test/fixtures/enc_utf16be.dummy
|
118
118
|
- test/fixtures/enc_utf16be_bom.dummy
|
119
119
|
- test/fixtures/enc_utf16le.dummy
|
@@ -130,19 +130,19 @@ files:
|
|
130
130
|
- test/fixtures/twine_accent_values.txt
|
131
131
|
- test/test_abstract_formatter.rb
|
132
132
|
- test/test_cli.rb
|
133
|
-
- test/
|
134
|
-
- test/
|
133
|
+
- test/test_consume_localization_archive.rb
|
134
|
+
- test/test_consume_localization_file.rb
|
135
135
|
- test/test_formatters.rb
|
136
|
-
- test/
|
137
|
-
- test/
|
138
|
-
- test/
|
136
|
+
- test/test_generate_all_localization_files.rb
|
137
|
+
- test/test_generate_localization_archive.rb
|
138
|
+
- test/test_generate_localization_file.rb
|
139
139
|
- test/test_output_processor.rb
|
140
140
|
- test/test_placeholders.rb
|
141
|
-
- test/
|
142
|
-
- test/
|
143
|
-
- test/
|
141
|
+
- test/test_twine_definition.rb
|
142
|
+
- test/test_twine_file.rb
|
143
|
+
- test/test_validate_twine_file.rb
|
144
144
|
- test/twine_file_dsl.rb
|
145
|
-
- test/
|
145
|
+
- test/twine_test.rb
|
146
146
|
homepage: https://github.com/mobiata/twine
|
147
147
|
licenses:
|
148
148
|
- BSD-3-Clause
|
@@ -166,18 +166,18 @@ rubyforge_project:
|
|
166
166
|
rubygems_version: 2.4.5.1
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
|
-
summary: Manage strings and their translations for your iOS and
|
169
|
+
summary: Manage strings and their translations for your iOS, Android and other projects.
|
170
170
|
test_files:
|
171
171
|
- test/test_abstract_formatter.rb
|
172
172
|
- test/test_cli.rb
|
173
|
-
- test/
|
174
|
-
- test/
|
173
|
+
- test/test_consume_localization_archive.rb
|
174
|
+
- test/test_consume_localization_file.rb
|
175
175
|
- test/test_formatters.rb
|
176
|
-
- test/
|
177
|
-
- test/
|
178
|
-
- test/
|
176
|
+
- test/test_generate_all_localization_files.rb
|
177
|
+
- test/test_generate_localization_archive.rb
|
178
|
+
- test/test_generate_localization_file.rb
|
179
179
|
- test/test_output_processor.rb
|
180
180
|
- test/test_placeholders.rb
|
181
|
-
- test/
|
182
|
-
- test/
|
183
|
-
- test/
|
181
|
+
- test/test_twine_definition.rb
|
182
|
+
- test/test_twine_file.rb
|
183
|
+
- test/test_validate_twine_file.rb
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require 'command_test_case'
|
2
|
-
|
3
|
-
class TestConsumeLocDrop < CommandTestCase
|
4
|
-
def setup
|
5
|
-
super
|
6
|
-
|
7
|
-
options = {}
|
8
|
-
options[:input_path] = fixture_path 'consume_loc_drop.zip'
|
9
|
-
options[:output_path] = @output_path
|
10
|
-
options[:format] = 'apple'
|
11
|
-
|
12
|
-
@twine_file = build_twine_file 'en', 'es' do
|
13
|
-
add_section 'Section' do
|
14
|
-
add_row key1: 'value1'
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
@runner = Twine::Runner.new(options, @twine_file)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_consumes_zip_file
|
22
|
-
@runner.consume_loc_drop
|
23
|
-
|
24
|
-
assert @twine_file.strings_map['key1'].translations['en'], 'value1-english'
|
25
|
-
assert @twine_file.strings_map['key1'].translations['es'], 'value1-spanish'
|
26
|
-
end
|
27
|
-
end
|
data/test/test_strings_file.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'twine_test_case'
|
2
|
-
|
3
|
-
class TestStringsFile < TwineTestCase
|
4
|
-
class Reading < TwineTestCase
|
5
|
-
def setup
|
6
|
-
super
|
7
|
-
|
8
|
-
@strings = Twine::StringsFile.new
|
9
|
-
@strings.read fixture_path('twine_accent_values.txt')
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_reading_keeps_leading_accent
|
13
|
-
assert_equal '`value', @strings.strings_map['value_with_leading_accent'].translations['en']
|
14
|
-
end
|
15
|
-
|
16
|
-
def test_reading_keeps_trailing_accent
|
17
|
-
assert_equal 'value`', @strings.strings_map['value_with_trailing_accent'].translations['en']
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_reading_keeps_leading_space
|
21
|
-
assert_equal ' value', @strings.strings_map['value_with_leading_space'].translations['en']
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_reading_keeps_trailing_space
|
25
|
-
assert_equal 'value ', @strings.strings_map['value_with_trailing_space'].translations['en']
|
26
|
-
end
|
27
|
-
|
28
|
-
def test_reading_keeps_wrapping_spaces
|
29
|
-
assert_equal ' value ', @strings.strings_map['value_wrapped_by_spaces'].translations['en']
|
30
|
-
end
|
31
|
-
|
32
|
-
def test_reading_keeps_wrapping_accents
|
33
|
-
assert_equal '`value`', @strings.strings_map['value_wrapped_by_accents'].translations['en']
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
class Writing < TwineTestCase
|
38
|
-
|
39
|
-
def test_accent_wrapping
|
40
|
-
@strings = build_twine_file 'en' do
|
41
|
-
add_section 'Section' do
|
42
|
-
add_row value_with_leading_accent: '`value'
|
43
|
-
add_row value_with_trailing_accent: 'value`'
|
44
|
-
add_row value_with_leading_space: ' value'
|
45
|
-
add_row value_with_trailing_space: 'value '
|
46
|
-
add_row value_wrapped_by_spaces: ' value '
|
47
|
-
add_row value_wrapped_by_accents: '`value`'
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
@strings.write @output_path
|
52
|
-
|
53
|
-
assert_equal content('twine_accent_values.txt'), File.read(@output_path)
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|