twine 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -0
  3. data/lib/twine.rb +21 -0
  4. data/lib/twine/cli.rb +68 -91
  5. data/lib/twine/formatters/abstract.rb +133 -82
  6. data/lib/twine/formatters/android.rb +49 -67
  7. data/lib/twine/formatters/apple.rb +33 -47
  8. data/lib/twine/formatters/django.rb +38 -48
  9. data/lib/twine/formatters/flash.rb +25 -40
  10. data/lib/twine/formatters/gettext.rb +37 -44
  11. data/lib/twine/formatters/jquery.rb +31 -33
  12. data/lib/twine/formatters/tizen.rb +38 -55
  13. data/lib/twine/output_processor.rb +57 -0
  14. data/lib/twine/placeholders.rb +54 -0
  15. data/lib/twine/runner.rb +78 -115
  16. data/lib/twine/stringsfile.rb +83 -60
  17. data/lib/twine/version.rb +1 -1
  18. data/test/command_test_case.rb +12 -0
  19. data/test/fixtures/consume_loc_drop.zip +0 -0
  20. data/test/fixtures/formatter_android.xml +15 -0
  21. data/test/fixtures/formatter_apple.strings +20 -0
  22. data/test/fixtures/formatter_django.po +28 -0
  23. data/test/fixtures/formatter_flash.properties +15 -0
  24. data/test/fixtures/formatter_gettext.po +26 -0
  25. data/test/fixtures/formatter_jquery.json +7 -0
  26. data/test/fixtures/formatter_tizen.xml +15 -0
  27. data/test/fixtures/gettext_multiline.po +10 -0
  28. data/test/fixtures/twine_accent_values.txt +13 -0
  29. data/test/test_abstract_formatter.rb +152 -0
  30. data/test/test_cli.rb +288 -0
  31. data/test/test_consume_loc_drop.rb +27 -0
  32. data/test/test_consume_string_file.rb +53 -0
  33. data/test/test_formatters.rb +236 -0
  34. data/test/test_generate_all_string_files.rb +44 -0
  35. data/test/test_generate_loc_drop.rb +44 -0
  36. data/test/test_generate_string_file.rb +51 -0
  37. data/test/test_output_processor.rb +85 -0
  38. data/test/test_placeholders.rb +86 -0
  39. data/test/test_strings_file.rb +58 -0
  40. data/test/test_strings_row.rb +47 -0
  41. data/test/test_validate_strings_file.rb +55 -0
  42. data/test/twine_file_dsl.rb +46 -0
  43. data/test/twine_test_case.rb +44 -0
  44. metadata +80 -37
  45. data/test/fixtures/en-1.json +0 -5
  46. data/test/fixtures/en-1.po +0 -16
  47. data/test/fixtures/en-1.strings +0 -10
  48. data/test/fixtures/en-2.po +0 -23
  49. data/test/fixtures/en-3.xml +0 -8
  50. data/test/fixtures/fr-1.xml +0 -10
  51. data/test/fixtures/strings-1.txt +0 -17
  52. data/test/fixtures/strings-2.txt +0 -5
  53. data/test/fixtures/strings-3.txt +0 -5
  54. data/test/fixtures/test-json-line-breaks/consumed.txt +0 -5
  55. data/test/fixtures/test-json-line-breaks/generated.json +0 -3
  56. data/test/fixtures/test-json-line-breaks/line-breaks.json +0 -3
  57. data/test/fixtures/test-json-line-breaks/line-breaks.txt +0 -4
  58. data/test/fixtures/test-output-1.txt +0 -12
  59. data/test/fixtures/test-output-10.txt +0 -9
  60. data/test/fixtures/test-output-11.txt +0 -9
  61. data/test/fixtures/test-output-12.txt +0 -12
  62. data/test/fixtures/test-output-2.txt +0 -12
  63. data/test/fixtures/test-output-3.txt +0 -18
  64. data/test/fixtures/test-output-4.txt +0 -21
  65. data/test/fixtures/test-output-5.txt +0 -4
  66. data/test/fixtures/test-output-6.txt +0 -10
  67. data/test/fixtures/test-output-7.txt +0 -16
  68. data/test/fixtures/test-output-8.txt +0 -9
  69. data/test/fixtures/test-output-9.txt +0 -21
  70. data/test/twine_test.rb +0 -134
@@ -0,0 +1,46 @@
1
+ module TwineFileDSL
2
+ def build_twine_file(*languages)
3
+ @currently_built_twine_file = Twine::StringsFile.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::StringsSection.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_row(parameters)
20
+ return unless @currently_built_twine_file
21
+ return unless @currently_built_twine_file_section
22
+
23
+ # this relies on Ruby 1.9 preserving the order of hash elements
24
+ key, value = parameters.first
25
+ row = Twine::StringsRow.new(key.to_s)
26
+ if value.is_a? Hash
27
+ value.each do |language, translation|
28
+ row.translations[language.to_s] = translation
29
+ end
30
+ elsif !value.is_a? Symbol
31
+ language = @currently_built_twine_file.language_codes.first
32
+ row.translations[language] = value
33
+ end
34
+
35
+ row.comment = parameters[:comment] if parameters[:comment]
36
+ row.tags = parameters[:tags] if parameters[:tags]
37
+ if parameters[:ref] || value.is_a?(Symbol)
38
+ reference_key = (parameters[:ref] || value).to_s
39
+ row.reference_key = reference_key
40
+ row.reference = @currently_built_twine_file.strings_map[reference_key]
41
+ end
42
+
43
+ @currently_built_twine_file_section.rows << row
44
+ @currently_built_twine_file.strings_map[row.key] = row
45
+ end
46
+ end
@@ -0,0 +1,44 @@
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 TwineTestCase < 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
+ @output_dir = Dir.mktmpdir
19
+ @output_path = File.join @output_dir, SecureRandom.uuid
20
+ end
21
+
22
+ def teardown
23
+ FileUtils.remove_entry_secure @output_dir if File.exists? @output_dir
24
+ super
25
+ end
26
+
27
+ def output_content
28
+ File.read @output_path
29
+ end
30
+
31
+ def execute(command)
32
+ command += " -o #{@output_path}"
33
+ Twine::Runner.run(command.split(" "))
34
+ end
35
+
36
+ def fixture(filename)
37
+ File.join File.dirname(__FILE__), 'fixtures', filename
38
+ end
39
+ alias :f :fixture
40
+
41
+ def content(filename)
42
+ ERB.new(File.read fixture(filename)).result
43
+ end
44
+ 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.7.0
4
+ version: 0.8.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: 2015-08-08 00:00:00.000000000 Z
11
+ date: 2016-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -16,42 +16,70 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.5
19
+ version: '1.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.5
26
+ version: '1.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: safe_yaml
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.0.3
33
+ version: '1.0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.0.3
40
+ version: '1.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.9.2
47
+ version: '10.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.9.2
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'
55
83
  description: |2
56
84
  Twine is a command line tool for managing your strings and their translations.
57
85
 
@@ -78,38 +106,41 @@ files:
78
106
  - lib/twine/formatters/gettext.rb
79
107
  - lib/twine/formatters/jquery.rb
80
108
  - lib/twine/formatters/tizen.rb
109
+ - lib/twine/output_processor.rb
110
+ - lib/twine/placeholders.rb
81
111
  - lib/twine/plugin.rb
82
112
  - lib/twine/runner.rb
83
113
  - lib/twine/stringsfile.rb
84
114
  - lib/twine/version.rb
85
- - test/fixtures/en-1.json
86
- - test/fixtures/en-1.po
87
- - test/fixtures/en-1.strings
88
- - test/fixtures/en-2.po
89
- - test/fixtures/en-3.xml
90
- - test/fixtures/fr-1.xml
91
- - test/fixtures/strings-1.txt
92
- - test/fixtures/strings-2.txt
93
- - test/fixtures/strings-3.txt
94
- - test/fixtures/test-json-line-breaks/consumed.txt
95
- - test/fixtures/test-json-line-breaks/generated.json
96
- - test/fixtures/test-json-line-breaks/line-breaks.json
97
- - test/fixtures/test-json-line-breaks/line-breaks.txt
98
- - test/fixtures/test-output-1.txt
99
- - test/fixtures/test-output-10.txt
100
- - test/fixtures/test-output-11.txt
101
- - test/fixtures/test-output-12.txt
102
- - test/fixtures/test-output-2.txt
103
- - test/fixtures/test-output-3.txt
104
- - test/fixtures/test-output-4.txt
105
- - test/fixtures/test-output-5.txt
106
- - test/fixtures/test-output-6.txt
107
- - test/fixtures/test-output-7.txt
108
- - test/fixtures/test-output-8.txt
109
- - test/fixtures/test-output-9.txt
110
- - test/twine_test.rb
115
+ - test/command_test_case.rb
116
+ - test/fixtures/consume_loc_drop.zip
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_string_file.rb
130
+ - test/test_formatters.rb
131
+ - test/test_generate_all_string_files.rb
132
+ - test/test_generate_loc_drop.rb
133
+ - test/test_generate_string_file.rb
134
+ - test/test_output_processor.rb
135
+ - test/test_placeholders.rb
136
+ - test/test_strings_file.rb
137
+ - test/test_strings_row.rb
138
+ - test/test_validate_strings_file.rb
139
+ - test/twine_file_dsl.rb
140
+ - test/twine_test_case.rb
111
141
  homepage: https://github.com/mobiata/twine
112
- licenses: []
142
+ licenses:
143
+ - BSD-3-Clause
113
144
  metadata: {}
114
145
  post_install_message:
115
146
  rdoc_options: []
@@ -127,9 +158,21 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
158
  version: '0'
128
159
  requirements: []
129
160
  rubyforge_project:
130
- rubygems_version: 2.2.2
161
+ rubygems_version: 2.4.5.1
131
162
  signing_key:
132
163
  specification_version: 4
133
164
  summary: Manage strings and their translations for your iOS and Android projects.
134
165
  test_files:
135
- - test/twine_test.rb
166
+ - test/test_abstract_formatter.rb
167
+ - test/test_cli.rb
168
+ - test/test_consume_loc_drop.rb
169
+ - test/test_consume_string_file.rb
170
+ - test/test_formatters.rb
171
+ - test/test_generate_all_string_files.rb
172
+ - test/test_generate_loc_drop.rb
173
+ - test/test_generate_string_file.rb
174
+ - test/test_output_processor.rb
175
+ - test/test_placeholders.rb
176
+ - test/test_strings_file.rb
177
+ - test/test_strings_row.rb
178
+ - test/test_validate_strings_file.rb
@@ -1,5 +0,0 @@
1
- {
2
- "key1":"key1-english",
3
- "key3":"key3-english",
4
- "key5":"A new string"
5
- }
@@ -1,16 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Language: en\n"
4
- "X-Generator: Twine\n"
5
-
6
- msgctxt "key1"
7
- msgid "key1-english"
8
- msgstr "key1-english"
9
-
10
- msgctxt "key3"
11
- msgid "key3-english"
12
- msgstr ""
13
-
14
- msgctxt "key5"
15
- msgid "A new string"
16
- msgstr "A new string"
@@ -1,10 +0,0 @@
1
- /**
2
- * iOS Strings File
3
- * Generated by Twine
4
- * Language: en
5
- */
6
-
7
- /* My Strings */
8
- "key1" = "key1-english";
9
- "key3" = "key3-english";
10
- "key5" = "A new string";
@@ -1,23 +0,0 @@
1
- msgid ""
2
- msgstr ""
3
- "Language: en\n"
4
- "X-Generator: Twine\n"
5
-
6
- msgctxt "key1"
7
- msgid "key1-english"
8
- msgstr "key1-english"
9
-
10
- msgctxt "key3"
11
- msgid "key3-english"
12
- msgstr ""
13
-
14
- msgctxt "key4"
15
- msgid "key4"
16
- "multiline"
17
- msgstr "A multi"
18
- "line string\n"
19
- "can occur"
20
-
21
- msgctxt "key5"
22
- msgid "A new string"
23
- msgstr "A new string"
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Android Strings File -->
3
- <!-- Generated by Twine 0.5.0 -->
4
- <!-- Language: en -->
5
- <resources>
6
- <!-- SECTION: My Strings -->
7
- <string name="string_with_spaces">\u0020string with spaces\u0020\u0020</string>
8
- </resources>
@@ -1,10 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Android Strings File -->
3
- <!-- Generated by Twine -->
4
- <!-- Language: fr -->
5
- <resources>
6
- <!-- This is a comment -->
7
- <string name="key1">key1-french</string>
8
- <string name="key2">key2-french</string>
9
- <string name="key3">key3-french</string>
10
- </resources>
@@ -1,17 +0,0 @@
1
- [[My Strings]]
2
- [key1]
3
- en = key1-english
4
- tags = tag1
5
- comment = This is a comment
6
- es = key1-spanish
7
- fr = key1-french
8
- [key2]
9
- en = key2-english
10
- tags = tag2
11
- fr = key2-french
12
- [key3]
13
- en = key3-english
14
- tags = tag1,tag2
15
- es = key3-spanish
16
- [key4]
17
- en = key4-english
@@ -1,5 +0,0 @@
1
- [[My Strings]]
2
- [key with space ]
3
- en = `string with space `
4
- tags = tag1
5
- comment = String ends with space
@@ -1,5 +0,0 @@
1
- [[My Strings]]
2
- [parameterized_string]
3
- en = The %@ brown fox jumps over the %@ dog %d times.
4
- [percentage_string]
5
- en = This product is %d%% off.
@@ -1,5 +0,0 @@
1
- [[Line Break Strings]]
2
- [line_breaking]
3
- en = This\nstring\ncontains\nline\nbreaks
4
- tags = tag1
5
- fr = This\nstring\nalso\ncontains\nline\nbreaks
@@ -1,3 +0,0 @@
1
- {
2
- "line_breaking":"This\nstring\ncontains\nline\nbreaks"
3
- }
@@ -1,3 +0,0 @@
1
- {
2
- "line_breaking":"This\nstring\nalso\ncontains\nline\nbreaks"
3
- }
@@ -1,4 +0,0 @@
1
- [[Line Break Strings]]
2
- [line_breaking]
3
- en = This\nstring\ncontains\nline\nbreaks
4
- tags = tag1
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Android Strings File -->
3
- <!-- Generated by Twine <%= Twine::VERSION %> -->
4
- <!-- Language: fr -->
5
- <resources>
6
- <!-- SECTION: My Strings -->
7
- <!-- This is a comment -->
8
- <string name="key1">key1-french</string>
9
- <string name="key2">key2-french</string>
10
- <string name="key3">key3-english</string>
11
- <string name="key4">key4-english</string>
12
- </resources>
@@ -1,9 +0,0 @@
1
- <?xml version="1.0" encoding="utf-8"?>
2
- <!-- Android Strings File -->
3
- <!-- Generated by Twine <%= Twine::VERSION %> -->
4
- <!-- Language: en -->
5
- <resources>
6
- <!-- SECTION: My Strings -->
7
- <!-- String ends with space -->
8
- <string name="key with space ">string with space\u0020</string>
9
- </resources>
@@ -1,9 +0,0 @@
1
- [[Uncategorized]]
2
- [string_with_spaces]
3
- en = ` string with spaces `
4
-
5
- [[My Strings]]
6
- [key with space ]
7
- en = `string with space `
8
- tags = tag1
9
- comment = String ends with space