i18n_flow 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +7 -0
  3. data/.rspec +3 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +13 -0
  6. data/Gemfile +6 -0
  7. data/Gemfile.lock +45 -0
  8. data/LICENSE +22 -0
  9. data/README.md +103 -0
  10. data/Rakefile +2 -0
  11. data/bin/console +14 -0
  12. data/bin/setup +8 -0
  13. data/doc/rules.md +316 -0
  14. data/doc/tags.md +488 -0
  15. data/example/example.en.yml +14 -0
  16. data/example/example.ja.yml +9 -0
  17. data/exe/i18n_flow +11 -0
  18. data/i18n_flow.gemspec +28 -0
  19. data/i18n_flow.yml +8 -0
  20. data/lib/i18n_flow/cli/color.rb +18 -0
  21. data/lib/i18n_flow/cli/command_base.rb +33 -0
  22. data/lib/i18n_flow/cli/copy_command.rb +69 -0
  23. data/lib/i18n_flow/cli/help_command.rb +29 -0
  24. data/lib/i18n_flow/cli/lint_command/ascii.erb +45 -0
  25. data/lib/i18n_flow/cli/lint_command/ascii_renderer.rb +58 -0
  26. data/lib/i18n_flow/cli/lint_command/markdown.erb +49 -0
  27. data/lib/i18n_flow/cli/lint_command/markdown_renderer.rb +55 -0
  28. data/lib/i18n_flow/cli/lint_command.rb +55 -0
  29. data/lib/i18n_flow/cli/read_config_command.rb +20 -0
  30. data/lib/i18n_flow/cli/search_command/default.erb +11 -0
  31. data/lib/i18n_flow/cli/search_command/default_renderer.rb +67 -0
  32. data/lib/i18n_flow/cli/search_command/oneline.erb +5 -0
  33. data/lib/i18n_flow/cli/search_command/oneline_renderer.rb +39 -0
  34. data/lib/i18n_flow/cli/search_command.rb +59 -0
  35. data/lib/i18n_flow/cli/split_command.rb +20 -0
  36. data/lib/i18n_flow/cli/version_command.rb +9 -0
  37. data/lib/i18n_flow/cli.rb +42 -0
  38. data/lib/i18n_flow/configuration.rb +205 -0
  39. data/lib/i18n_flow/parser.rb +34 -0
  40. data/lib/i18n_flow/repository.rb +39 -0
  41. data/lib/i18n_flow/search.rb +176 -0
  42. data/lib/i18n_flow/splitter/merger.rb +60 -0
  43. data/lib/i18n_flow/splitter/strategy.rb +66 -0
  44. data/lib/i18n_flow/splitter.rb +5 -0
  45. data/lib/i18n_flow/util.rb +57 -0
  46. data/lib/i18n_flow/validator/errors.rb +99 -0
  47. data/lib/i18n_flow/validator/file_scope.rb +58 -0
  48. data/lib/i18n_flow/validator/multiplexer.rb +58 -0
  49. data/lib/i18n_flow/validator/symmetry.rb +154 -0
  50. data/lib/i18n_flow/validator.rb +4 -0
  51. data/lib/i18n_flow/version.rb +7 -0
  52. data/lib/i18n_flow/yaml_ast_proxy/mapping.rb +72 -0
  53. data/lib/i18n_flow/yaml_ast_proxy/node.rb +128 -0
  54. data/lib/i18n_flow/yaml_ast_proxy/node_meta_data.rb +86 -0
  55. data/lib/i18n_flow/yaml_ast_proxy/sequence.rb +29 -0
  56. data/lib/i18n_flow/yaml_ast_proxy.rb +57 -0
  57. data/lib/i18n_flow.rb +15 -0
  58. data/spec/lib/i18n_flow/cli/command_base_spec.rb +46 -0
  59. data/spec/lib/i18n_flow/cli/help_command_spec.rb +13 -0
  60. data/spec/lib/i18n_flow/cli/version_command_spec.rb +13 -0
  61. data/spec/lib/i18n_flow/configuration_spec.rb +334 -0
  62. data/spec/lib/i18n_flow/repository_spec.rb +40 -0
  63. data/spec/lib/i18n_flow/splitter/merger_spec.rb +149 -0
  64. data/spec/lib/i18n_flow/util_spec.rb +194 -0
  65. data/spec/lib/i18n_flow/validator/file_scope_spec.rb +74 -0
  66. data/spec/lib/i18n_flow/validator/multiplexer_spec.rb +68 -0
  67. data/spec/lib/i18n_flow/validator/symmetry_spec.rb +511 -0
  68. data/spec/lib/i18n_flow/yaml_ast_proxy/node_spec.rb +151 -0
  69. data/spec/lib/i18n_flow_spec.rb +21 -0
  70. data/spec/spec_helper.rb +16 -0
  71. data/spec/support/repository_examples.rb +60 -0
  72. data/spec/support/util_macro.rb +14 -0
  73. metadata +214 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4537799b78a2246ecd36a0cf9be738dc928e2422
4
+ data.tar.gz: 1fc6adc2ef94f46a13714829dfbc677cb42778f9
5
+ SHA512:
6
+ metadata.gz: 923ce8ee56eb52fbe275a1c07657c163b8a319c7dc67aec80e9b0f45f6991e44ff43b4c4c04bcce70909c26eac6959fb5f22555a347feb3aaca09223f4eae92a
7
+ data.tar.gz: 9d84ac662df036e5c2bbd56e3f4d9dda06ceb8e57e60b1b8670f8f01b2c37e6cfb0ce51001970a274722a3507fc4fd6a7ec243a06dcb4401e191d9ce7abf1f12
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /pkg/
6
+ /spec/reports/
7
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format doc
3
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.4.2
data/.travis.yml ADDED
@@ -0,0 +1,13 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm: 2.4.2
4
+
5
+ branches:
6
+ only:
7
+ - master # Affects only branch builds; pull requests will still be built on any branch
8
+
9
+ install:
10
+ - bundle install
11
+
12
+ script:
13
+ - bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in i18n_flow.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,45 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ i18n_flow (0.1.0)
5
+ psych (>= 3.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ coderay (1.1.2)
11
+ diff-lcs (1.3)
12
+ fakefs (0.13.1)
13
+ method_source (0.9.0)
14
+ pry (0.11.3)
15
+ coderay (~> 1.1.0)
16
+ method_source (~> 0.9.0)
17
+ psych (3.0.2)
18
+ rake (10.5.0)
19
+ rspec (3.7.0)
20
+ rspec-core (~> 3.7.0)
21
+ rspec-expectations (~> 3.7.0)
22
+ rspec-mocks (~> 3.7.0)
23
+ rspec-core (3.7.1)
24
+ rspec-support (~> 3.7.0)
25
+ rspec-expectations (3.7.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.7.0)
28
+ rspec-mocks (3.7.0)
29
+ diff-lcs (>= 1.2.0, < 2.0)
30
+ rspec-support (~> 3.7.0)
31
+ rspec-support (3.7.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.16)
38
+ fakefs
39
+ i18n_flow!
40
+ pry
41
+ rake (~> 10.0)
42
+ rspec (~> 3.7)
43
+
44
+ BUNDLED WITH
45
+ 1.16.0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018- Yuki Iwanaga
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ ![](https://user-images.githubusercontent.com/1695538/36350808-d0cf8afe-14e1-11e8-8afb-34a316f98f80.png)
2
+
3
+ i18n_flow (beta)
4
+ ================
5
+
6
+ [![Build Status](https://travis-ci.org/creasty/i18n_flow.svg?branch=master)](https://travis-ci.org/creasty/i18n_flow)
7
+ [![License](https://img.shields.io/github/license/creasty/i18n_flow.svg)](./LICENSE)
8
+
9
+ **Manage translation status in YAML file.**
10
+ With an official [tag](http://www.yaml.org/spec/1.2/spec.html#id2784064) feature, `i18n_flow` enables you to annotate status information directly in YAML file.
11
+
12
+ ![](https://user-images.githubusercontent.com/1695538/36359417-6a976054-155e-11e8-914b-d6a10a8287fc.png)
13
+
14
+ - [Lint rules](./doc/rules.md)
15
+ - [Tags](./doc/tags.md)
16
+
17
+
18
+ Setup
19
+ -----
20
+
21
+ ### Installation
22
+
23
+ Add this line to your Gemfile:
24
+
25
+ ```ruby
26
+ gem 'i18n_flow', github: 'creasty/i18n_flow'
27
+ ```
28
+
29
+ ### Configuration
30
+
31
+ Create a configuration file at your project's root directory.
32
+
33
+ ```sh-session
34
+ $ cat > i18n_flow.yml
35
+ base_path: config/locales
36
+ glob_patterns:
37
+ - '**/*.yml'
38
+ valid_locales:
39
+ - en
40
+ - ja
41
+ locale_pairs:
42
+ - ['en', 'ja']
43
+ ^D
44
+ ```
45
+
46
+
47
+ CLI
48
+ ---
49
+
50
+ ```sh-session
51
+ $ i18n_flow
52
+ Manage translation status in yaml file
53
+
54
+ Usage:
55
+ i18n_flow COMMAND [args...]
56
+ i18n_flow [options]
57
+
58
+ Options:
59
+ -v, --version Show version
60
+ -h Show help
61
+
62
+ Commands:
63
+ lint Validate files
64
+ search Search contents and keys
65
+ copy Copy translations and mark as todo
66
+ split Split a file into proper-sized files
67
+ version Show version
68
+ help Show help
69
+ ```
70
+
71
+
72
+ Configuration file
73
+ ------------------
74
+
75
+ ```yaml
76
+ # Base directory
77
+ # Default: pwd
78
+ base_path: config/locales
79
+
80
+ # Patterns for locale YAML files
81
+ # Default: ['*.en.yml']
82
+ glob_patterns:
83
+ - '**/*.yml'
84
+
85
+ # List of all supporting locales
86
+ # May want to sync with `I18n.available_locales`
87
+ # Default: ['en']
88
+ valid_locales:
89
+ - en
90
+ - ja
91
+
92
+ # List of master-foreign pairs
93
+ # Used by the linter to check symmetry
94
+ # Default: []
95
+ locale_pairs:
96
+ - ['en', 'ja']
97
+
98
+ # Enabled linters
99
+ # Default
100
+ linters:
101
+ - file_scope
102
+ - symmetry
103
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "i18n_flow"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/doc/rules.md ADDED
@@ -0,0 +1,316 @@
1
+ Lint rules
2
+ ==========
3
+
4
+ File-scope linter
5
+ -----------------
6
+
7
+ File-scope linter checks consistency between file content and a file path of each file, without comparing with others.
8
+
9
+ 'File-scope' is a sort of namespace that derives from a file path.
10
+ For example a file-scope of `models/user.en.yml` is `en.models.user`.
11
+
12
+
13
+ ### A file must start with scopes that derive from its file path
14
+
15
+ <table><thead><tr>
16
+ <th></th>
17
+ <th>models/user.en.yml</th>
18
+ </tr></thead><tbody><tr><th>โœ…</th><td>
19
+
20
+ ```yaml
21
+ en:
22
+ models:
23
+ user:
24
+ ...
25
+ ```
26
+
27
+ </td></tr><tr><td colspan=2>
28
+
29
+ Starts with `en.models.user`
30
+
31
+ </td></tr></tbody></table>
32
+
33
+ <table><thead><tr>
34
+ <th></th>
35
+ <th>models/user.en.yml</th>
36
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
37
+
38
+ ```yaml
39
+ ja:
40
+ models:
41
+ user:
42
+ ...
43
+ ```
44
+
45
+ </td></tr><tr><td colspan=2>
46
+
47
+ Starts with `ja`
48
+
49
+ </td></tr></tbody></table>
50
+
51
+ <table><thead><tr>
52
+ <th></th>
53
+ <th>controllers/admin/accounts_controller.en.yml</th>
54
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
55
+
56
+ ```yaml
57
+ en:
58
+ controllers:
59
+ nimda:
60
+ accounts_controller:
61
+ ...
62
+ ```
63
+
64
+ </td></tr><tr><td colspan=2>
65
+
66
+ Starts with `en.controllers.nimda`
67
+
68
+ </td></tr></tbody></table>
69
+
70
+
71
+ ### Having extra key at anywhere upper-or-equal level than a file-scope
72
+
73
+ <table><thead><tr>
74
+ <th></th>
75
+ <th>models/user.en.yml</th>
76
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
77
+
78
+ ```yaml
79
+ en:
80
+ models:
81
+ user:
82
+ ...
83
+
84
+ foo: ...
85
+ ```
86
+
87
+ </td></tr><tr><td colspan=2>
88
+
89
+ `en.foo` and `en.models` coexist
90
+
91
+ </td></tr></tbody></table>
92
+
93
+
94
+ ### A file-scope itself must not have a scalar value
95
+
96
+ <table><thead><tr>
97
+ <th></th>
98
+ <th>models/user.en.yml</th>
99
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
100
+
101
+ ```yaml
102
+ en:
103
+ models:
104
+ user: 'User'
105
+ ```
106
+
107
+ </td></tr><tr><td colspan=2>
108
+
109
+ `user` must be either a mapping or a sequence
110
+
111
+ </td></tr></tbody></table>
112
+
113
+
114
+ Symmetry linter
115
+ ---------------
116
+
117
+ Symmetry linter compares a pair of files and checks their symmetry.
118
+ As a pair, one is 'master' and another is 'foreign'.
119
+
120
+ If your primary language is English and going to support Japanese as secondary, you may want to lint Japanese (foreign) locale file based on English locale file (master).
121
+
122
+ ### Keys in a foreign file must be exhaustive and exclusive
123
+
124
+ [โ†’ Justify violations with `!only` or ignore with `!ignore:key`](./tags.md)
125
+
126
+ <table><thead><tr>
127
+ <th></th>
128
+ <th>master</th>
129
+ <th>foreign</th>
130
+ </tr></thead><tbody><tr><th>โœ…</th><td>
131
+
132
+ ```yaml
133
+ en:
134
+ title: 'Non zero sum'
135
+ desc: 'A situation in...'
136
+ ```
137
+
138
+ </td><td>
139
+
140
+ ```yaml
141
+ ja:
142
+ title: '้žใ‚ผใƒญๅ’Œ'
143
+ desc: '่ค‡ๆ•ฐใฎไบบใŒ็›ธไบ’...'
144
+ ```
145
+
146
+ </td></tr><tr><td colspan=3>
147
+
148
+ Every keys exist on both files. No asymmetric keys
149
+
150
+ </td></tr></tbody></table>
151
+
152
+
153
+ <table><thead><tr>
154
+ <th></th>
155
+ <th>master</th>
156
+ <th>foreign</th>
157
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
158
+
159
+ ```yaml
160
+ en:
161
+ title: 'Non zero sum'
162
+ desc: 'A situation in...'
163
+ ```
164
+
165
+ </td><td>
166
+
167
+ ```yaml
168
+ ja:
169
+ title: '้žใ‚ผใƒญๅ’Œ'
170
+
171
+ ```
172
+
173
+ </td></tr><tr><td colspan=3>
174
+
175
+ Missing `ja.desc`
176
+
177
+ </td></tr></tbody></table>
178
+
179
+
180
+ <table><thead><tr>
181
+ <th></th>
182
+ <th>master</th>
183
+ <th>foreign</th>
184
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
185
+
186
+ ```yaml
187
+ en:
188
+ title: 'Non zero sum'
189
+
190
+ ```
191
+
192
+ </td><td>
193
+
194
+ ```yaml
195
+ ja:
196
+ title: '้žใ‚ผใƒญๅ’Œ'
197
+ desc: '่ค‡ๆ•ฐใฎไบบใŒ็›ธไบ’...'
198
+ ```
199
+
200
+ </td></tr><tr><td colspan=3>
201
+
202
+ Having the extra `ja.desc`
203
+
204
+ </td></tr></tbody></table>
205
+
206
+
207
+ ### Structure must match exactly
208
+
209
+ [โ†’ Ignore violations with `!ignore:key`](./tags.md)
210
+
211
+ <table><thead><tr>
212
+ <th></th>
213
+ <th>master</th>
214
+ <th>foreign</th>
215
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
216
+
217
+ ```yaml
218
+ en:
219
+ follower_count:
220
+ one: '1 follower'
221
+ other: '%{count} followers'
222
+ ```
223
+
224
+ </td><td>
225
+
226
+ ```yaml
227
+ ja:
228
+ follower_count: '%{count} ใƒ•ใ‚ฉใƒญใƒฏ'
229
+
230
+
231
+ ```
232
+
233
+ </td></tr><tr><td colspan=3>
234
+
235
+ `en.follower_count` is a mapping, whereas `ja.follower_count` is a scalar
236
+
237
+ </td></tr></tbody></table>
238
+
239
+
240
+ ### Interpolation arguments must be exhaustive and exclusive
241
+
242
+ [โ†’ Ignore violations with `!ignore:args`](./tags.md)
243
+
244
+ <table><thead><tr>
245
+ <th></th>
246
+ <th>master</th>
247
+ <th>foreign</th>
248
+ </tr></thead><tbody><tr><th>โœ…</th><td>
249
+
250
+ ```yaml
251
+ en:
252
+ key: '%{alpha} %{beta} %{beta}'
253
+ ```
254
+
255
+ </td><td>
256
+
257
+ ```yaml
258
+ ja:
259
+ key: '%{beta} %{alpha}'
260
+ ```
261
+
262
+ </td></tr><tr><td colspan=3>
263
+
264
+ It's insensitive of arguments order and repetition
265
+
266
+ </td></tr></tbody></table>
267
+
268
+
269
+ <table><thead><tr>
270
+ <th></th>
271
+ <th>master</th>
272
+ <th>foreign</th>
273
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
274
+
275
+ ```yaml
276
+ en:
277
+ key: '%{alpha}'
278
+ ```
279
+
280
+ </td><td>
281
+
282
+ ```yaml
283
+ ja:
284
+ key: 'alpha'
285
+ ```
286
+
287
+ </td></tr><tr><td colspan=3>
288
+
289
+ No arguments exists in `ja.key`
290
+
291
+ </td></tr></tbody></table>
292
+
293
+
294
+ <table><thead><tr>
295
+ <th></th>
296
+ <th>master</th>
297
+ <th>foreign</th>
298
+ </tr></thead><tbody><tr><th>๐Ÿ‘Ž</th><td>
299
+
300
+ ```yaml
301
+ en:
302
+ key: '%{alpha}'
303
+ ```
304
+
305
+ </td><td>
306
+
307
+ ```yaml
308
+ ja:
309
+ key: '%{gamma}'
310
+ ```
311
+
312
+ </td></tr><tr><td colspan=3>
313
+
314
+ A set of arguments is different from master
315
+
316
+ </td></tr></tbody></table>