yury-twine 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +2 -0
- data/LICENSE +30 -0
- data/README.md +230 -0
- data/bin/twine +7 -0
- data/lib/twine.rb +36 -0
- data/lib/twine/cli.rb +200 -0
- data/lib/twine/encoding.rb +22 -0
- data/lib/twine/formatters.rb +20 -0
- data/lib/twine/formatters/abstract.rb +187 -0
- data/lib/twine/formatters/android.rb +254 -0
- data/lib/twine/formatters/apple.rb +328 -0
- data/lib/twine/output_processor.rb +57 -0
- data/lib/twine/placeholders.rb +54 -0
- data/lib/twine/plugin.rb +62 -0
- data/lib/twine/runner.rb +332 -0
- data/lib/twine/twine_file.rb +266 -0
- data/lib/twine/version.rb +3 -0
- data/test/command_test.rb +14 -0
- data/test/fixtures/consume_loc_drop.zip +0 -0
- data/test/fixtures/enc_utf16be.dummy +0 -0
- data/test/fixtures/enc_utf16be_bom.dummy +0 -0
- data/test/fixtures/enc_utf16le.dummy +0 -0
- data/test/fixtures/enc_utf16le_bom.dummy +0 -0
- data/test/fixtures/enc_utf8.dummy +2 -0
- data/test/fixtures/formatter_android.xml +15 -0
- data/test/fixtures/formatter_apple.strings +20 -0
- data/test/fixtures/formatter_django.po +30 -0
- data/test/fixtures/formatter_flash.properties +15 -0
- data/test/fixtures/formatter_gettext.po +26 -0
- data/test/fixtures/formatter_jquery.json +7 -0
- data/test/fixtures/formatter_tizen.xml +15 -0
- data/test/fixtures/gettext_multiline.po +10 -0
- data/test/fixtures/twine_accent_values.txt +13 -0
- data/test/test_abstract_formatter.rb +165 -0
- data/test/test_cli.rb +304 -0
- data/test/test_consume_loc_drop.rb +27 -0
- data/test/test_consume_localization_file.rb +119 -0
- data/test/test_formatters.rb +363 -0
- data/test/test_generate_all_localization_files.rb +102 -0
- data/test/test_generate_loc_drop.rb +80 -0
- data/test/test_generate_localization_file.rb +91 -0
- data/test/test_output_processor.rb +85 -0
- data/test/test_placeholders.rb +84 -0
- 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 +46 -0
- data/test/twine_test.rb +48 -0
- metadata +179 -0
@@ -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
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module TwineFileDSL
|
2
|
+
def build_twine_file(*languages)
|
3
|
+
@currently_built_twine_file = Twine::TwineFile.new
|
4
|
+
@currently_built_twine_file.language_codes.concat languages
|
5
|
+
yield
|
6
|
+
result = @currently_built_twine_file
|
7
|
+
@currently_built_twine_file = nil
|
8
|
+
return result
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_section(name)
|
12
|
+
return unless @currently_built_twine_file
|
13
|
+
@currently_built_twine_file_section = Twine::TwineSection.new name
|
14
|
+
@currently_built_twine_file.sections << @currently_built_twine_file_section
|
15
|
+
yield
|
16
|
+
@currently_built_twine_file_section = nil
|
17
|
+
end
|
18
|
+
|
19
|
+
def add_definition(parameters)
|
20
|
+
return unless @currently_built_twine_file
|
21
|
+
return unless @currently_built_twine_file_section
|
22
|
+
|
23
|
+
# this relies on Ruby preserving the order of hash elements
|
24
|
+
key, value = parameters.first
|
25
|
+
definition = Twine::TwineDefinition.new(key.to_s)
|
26
|
+
if value.is_a? Hash
|
27
|
+
value.each do |language, translation|
|
28
|
+
definition.translations[language.to_s] = translation
|
29
|
+
end
|
30
|
+
elsif !value.is_a? Symbol
|
31
|
+
language = @currently_built_twine_file.language_codes.first
|
32
|
+
definition.translations[language] = value
|
33
|
+
end
|
34
|
+
|
35
|
+
definition.comment = parameters[:comment] if parameters[:comment]
|
36
|
+
definition.tags = parameters[:tags] if parameters[:tags]
|
37
|
+
if parameters[:ref] || value.is_a?(Symbol)
|
38
|
+
reference_key = (parameters[:ref] || value).to_s
|
39
|
+
definition.reference_key = reference_key
|
40
|
+
definition.reference = @currently_built_twine_file.definitions_by_key[reference_key]
|
41
|
+
end
|
42
|
+
|
43
|
+
@currently_built_twine_file_section.definitions << definition
|
44
|
+
@currently_built_twine_file.definitions_by_key[definition.key] = definition
|
45
|
+
end
|
46
|
+
end
|
data/test/twine_test.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require "mocha/mini_test"
|
4
|
+
require 'securerandom'
|
5
|
+
require 'stringio'
|
6
|
+
require 'twine'
|
7
|
+
require 'twine_file_dsl'
|
8
|
+
|
9
|
+
class TwineTest < Minitest::Test
|
10
|
+
include TwineFileDSL
|
11
|
+
|
12
|
+
KNOWN_LANGUAGES = %w(en fr de es)
|
13
|
+
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
Twine::stdout = StringIO.new
|
17
|
+
Twine::stderr = StringIO.new
|
18
|
+
|
19
|
+
@formatters = Twine::Formatters.formatters.dup
|
20
|
+
|
21
|
+
@output_dir = Dir.mktmpdir
|
22
|
+
@output_path = File.join @output_dir, SecureRandom.uuid
|
23
|
+
end
|
24
|
+
|
25
|
+
def teardown
|
26
|
+
FileUtils.remove_entry_secure @output_dir if File.exists? @output_dir
|
27
|
+
Twine::Formatters.formatters.clear
|
28
|
+
Twine::Formatters.formatters.concat @formatters
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def execute(command)
|
33
|
+
command += " -o #{@output_path}"
|
34
|
+
Twine::Runner.run(command.split(" "))
|
35
|
+
end
|
36
|
+
|
37
|
+
def fixture_path(filename)
|
38
|
+
File.join File.dirname(__FILE__), 'fixtures', filename
|
39
|
+
end
|
40
|
+
|
41
|
+
def content(filename)
|
42
|
+
ERB.new(File.read fixture_path(filename)).result
|
43
|
+
end
|
44
|
+
|
45
|
+
def content_io(filename)
|
46
|
+
StringIO.new ERB.new(File.read fixture_path(filename)).result
|
47
|
+
end
|
48
|
+
end
|
metadata
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yury-twine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sebastian Celis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubyzip
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: safe_yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.4'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.4'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.1'
|
83
|
+
description: |2
|
84
|
+
Twine is a command line tool for managing your strings and their translations.
|
85
|
+
|
86
|
+
It is geared toward Mac OS X, iOS, and Android developers.
|
87
|
+
email: twine@mobiata.com
|
88
|
+
executables:
|
89
|
+
- twine
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.md
|
96
|
+
- bin/twine
|
97
|
+
- lib/twine.rb
|
98
|
+
- lib/twine/cli.rb
|
99
|
+
- lib/twine/encoding.rb
|
100
|
+
- lib/twine/formatters.rb
|
101
|
+
- lib/twine/formatters/abstract.rb
|
102
|
+
- lib/twine/formatters/android.rb
|
103
|
+
- lib/twine/formatters/apple.rb
|
104
|
+
- lib/twine/output_processor.rb
|
105
|
+
- lib/twine/placeholders.rb
|
106
|
+
- lib/twine/plugin.rb
|
107
|
+
- lib/twine/runner.rb
|
108
|
+
- lib/twine/twine_file.rb
|
109
|
+
- lib/twine/version.rb
|
110
|
+
- test/command_test.rb
|
111
|
+
- test/fixtures/consume_loc_drop.zip
|
112
|
+
- test/fixtures/enc_utf16be.dummy
|
113
|
+
- test/fixtures/enc_utf16be_bom.dummy
|
114
|
+
- test/fixtures/enc_utf16le.dummy
|
115
|
+
- test/fixtures/enc_utf16le_bom.dummy
|
116
|
+
- test/fixtures/enc_utf8.dummy
|
117
|
+
- test/fixtures/formatter_android.xml
|
118
|
+
- test/fixtures/formatter_apple.strings
|
119
|
+
- test/fixtures/formatter_django.po
|
120
|
+
- test/fixtures/formatter_flash.properties
|
121
|
+
- test/fixtures/formatter_gettext.po
|
122
|
+
- test/fixtures/formatter_jquery.json
|
123
|
+
- test/fixtures/formatter_tizen.xml
|
124
|
+
- test/fixtures/gettext_multiline.po
|
125
|
+
- test/fixtures/twine_accent_values.txt
|
126
|
+
- test/test_abstract_formatter.rb
|
127
|
+
- test/test_cli.rb
|
128
|
+
- test/test_consume_loc_drop.rb
|
129
|
+
- test/test_consume_localization_file.rb
|
130
|
+
- test/test_formatters.rb
|
131
|
+
- test/test_generate_all_localization_files.rb
|
132
|
+
- test/test_generate_loc_drop.rb
|
133
|
+
- test/test_generate_localization_file.rb
|
134
|
+
- test/test_output_processor.rb
|
135
|
+
- test/test_placeholders.rb
|
136
|
+
- test/test_twine_definition.rb
|
137
|
+
- test/test_twine_file.rb
|
138
|
+
- test/test_validate_twine_file.rb
|
139
|
+
- test/twine_file_dsl.rb
|
140
|
+
- test/twine_test.rb
|
141
|
+
homepage: https://github.com/mobiata/twine
|
142
|
+
licenses:
|
143
|
+
- BSD-3-Clause
|
144
|
+
metadata: {}
|
145
|
+
post_install_message: Twine command names have changed! Please check the documentation
|
146
|
+
for their new names.
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '2.0'
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubyforge_project:
|
162
|
+
rubygems_version: 2.5.1
|
163
|
+
signing_key:
|
164
|
+
specification_version: 4
|
165
|
+
summary: Manage strings and their translations for your iOS, Android and other projects.
|
166
|
+
test_files:
|
167
|
+
- test/test_abstract_formatter.rb
|
168
|
+
- test/test_cli.rb
|
169
|
+
- test/test_consume_loc_drop.rb
|
170
|
+
- test/test_consume_localization_file.rb
|
171
|
+
- test/test_formatters.rb
|
172
|
+
- test/test_generate_all_localization_files.rb
|
173
|
+
- test/test_generate_loc_drop.rb
|
174
|
+
- test/test_generate_localization_file.rb
|
175
|
+
- test/test_output_processor.rb
|
176
|
+
- test/test_placeholders.rb
|
177
|
+
- test/test_twine_definition.rb
|
178
|
+
- test/test_twine_file.rb
|
179
|
+
- test/test_validate_twine_file.rb
|