aigu 0.6.1 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6fd41e4a3b35261dae66ad6e7a8559e0c9481589
4
- data.tar.gz: 80d3f8950a1d643f67613dca3a392a1a1ac3d324
3
+ metadata.gz: 616ab0c8f167d1882b848067e0f431300ae11e8b
4
+ data.tar.gz: eabdfe2a5a75e12e6aab5c86e4da964f09609d56
5
5
  SHA512:
6
- metadata.gz: af1cefce92cf401d729749554e61f06a50323d6dca5c80b68abce6853d762ef20b322476610a014d030d73bb5873a807c8d67a010ed50b968e4a9814fa80a4e8
7
- data.tar.gz: 3fa916fd2a79476fd73313d1ccebacd827f37777ec48b0c52f4a4958fd94c7b4a40dcfb650630b8dfd0bd120a76b97d62df5d9128a1dc546eac68353f7d6ff2d
6
+ metadata.gz: 1deffeb18fa97f7e6351e106d8271da63aa67c19a65254e69757d7605fa445ba1e4bb501b4f04d67ddb561f96fc964be5db5ff5c964187a933713bfa47a688d0
7
+ data.tar.gz: 8efe81cf8c5ce9d153d098681117f98eb010d264619c84d0ac7fae9d34aa45e78cf50b5a3ad52cea4eec0d5eda2c23c73c637b76c6b6dac2abd6a9c1072e27c8
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014, Mirego
1
+ Copyright (c) 2014-2017, Mirego
2
2
  All rights reserved.
3
3
 
4
4
  Redistribution and use in source and binary forms, with or without
data/README.md CHANGED
@@ -44,13 +44,14 @@ $ aigu <export-command> --locale=fr --input-directory=config/locales --output-fi
44
44
  | `output-file` | The path to the JSON file that will be written by `aigu` |
45
45
  | `ignore` | The patterns `aigu` will use to skip ignored files (eg. `routes.yml`) |
46
46
 
47
- | Command | File format |
48
- |-------------------|----------------------------|
49
- | `rails-export` | Rails YAML |
50
- | `android-export` | Android XML |
51
- | `core-export` | Java Enum Core |
52
- | `ios-export` | iOS strings & stringsdict |
53
- | `ember-export` | Ember.js JavaScript |
47
+ | Command | File format |
48
+ |--------------------|----------------------------|
49
+ | `rails-export` | Rails YAML |
50
+ | `android-export` | Android XML |
51
+ | `core-export` | Java Enum Core |
52
+ | `ios-export` | iOS strings & stringsdict |
53
+ | `ember-export` | Ember.js JavaScript |
54
+ | `ember-pod-export` | Ember.js pods JSON |
54
55
 
55
56
  ### Importing the JSON file from Accent
56
57
 
@@ -69,12 +70,14 @@ $ aigu <import-command> --locale=fr --input-file=file-from-accent.json --output-
69
70
  | `input-file` | The path to the Accent-generated JSON file |
70
71
  | `output-directory` | The directory where the localization YAML files will be generated |
71
72
 
72
- | Command | File format |
73
- |-------------------|----------------------------|
74
- | `rails-import` | Rails YAML |
75
- | `android-import` | Android XML |
76
- | `core-import` | Java Enum Core |
77
- | `ios-import` | iOS strings & stringsdict |
73
+ | Command | File format |
74
+ |--------------------|----------------------------|
75
+ | `rails-import` | Rails YAML |
76
+ | `android-import` | Android XML |
77
+ | `core-import` | Java Enum Core |
78
+ | `ios-import` | iOS strings & stringsdict |
79
+ | `ember-import` | Ember.js JavaScript |
80
+ | `ember-pod-import` | Ember.js pods JSON |
78
81
 
79
82
  ### Merge
80
83
 
@@ -154,7 +157,7 @@ the commit if there are errors.
154
157
 
155
158
  ## License
156
159
 
157
- `Aigu` is © 2014-2015 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/aigu/blob/master/LICENSE.md) file.
160
+ `Aigu` is © 2014-2017 [Mirego](http://www.mirego.com) and may be freely distributed under the [New BSD license](http://opensource.org/licenses/BSD-3-Clause). See the [`LICENSE.md`](https://github.com/mirego/aigu/blob/master/LICENSE.md) file.
158
161
 
159
162
  ## About Mirego
160
163
 
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
+ spec.required_ruby_version = '~> 2.1'
22
+
21
23
  spec.add_development_dependency 'bundler', '~> 1.3'
22
24
  spec.add_development_dependency 'rake'
23
25
  spec.add_development_dependency 'rspec', '~> 3.0'
@@ -24,6 +24,8 @@ require 'aigu/ios_exporter'
24
24
  require 'aigu/ios_importer'
25
25
  require 'aigu/ember_exporter'
26
26
  require 'aigu/ember_importer'
27
+ require 'aigu/ember_pod_exporter'
28
+ require 'aigu/ember_pod_importer'
27
29
 
28
30
  require 'aigu/unmerger'
29
31
  require 'aigu/merger'
@@ -11,16 +11,18 @@ module Aigu
11
11
  'ios-export' => 'IOSExporter',
12
12
  'ember-import' => 'EmberImporter',
13
13
  'ember-export' => 'EmberExporter',
14
+ 'ember-pod-import' => 'EmberPodImporter',
15
+ 'ember-pod-export' => 'EmberPodExporter',
14
16
  'merge' => 'Merger',
15
17
  'unmerge' => 'Unmerger',
16
18
  'pull' => 'Puller',
17
19
  'push' => 'Pusher'
18
- }
20
+ }.freeze
19
21
 
20
22
  def initialize(env, argv)
21
23
  @env = env
22
24
  @command = argv.first =~ /^[^-]/ ? argv.shift : nil
23
- @command = @command.gsub('_', '-') if @command
25
+ @command = @command.tr('_', '-') if @command
24
26
  @argv = argv
25
27
  @options = {}
26
28
  @options = parse_options_from_yaml(@options)
@@ -103,7 +105,6 @@ DOC
103
105
  puts opts
104
106
  exit
105
107
  end
106
-
107
108
  end.parse! @argv
108
109
 
109
110
  options
@@ -0,0 +1,86 @@
1
+ module Aigu
2
+ class EmberPodExporter < Exporter
3
+ protected
4
+
5
+ def build_output
6
+ @output = build_output_from_global_translations(@input_directory, @locale)
7
+ @output.merge! build_output_from_pods(@input_directory, @locale)
8
+
9
+ @output
10
+ end
11
+
12
+ def build_output_from_global_translations(input_directory, locale)
13
+ pattern = File.join(input_directory, '**', 'locales', locale, 'translations.*.json')
14
+
15
+ Dir[pattern].reduce({}) do |memo, file|
16
+ content = read_or_ignore(file, input_directory)
17
+
18
+ return nil unless content
19
+
20
+ root_key = file.match(/translations\.([a-z]+)\.json/)[1]
21
+
22
+ base_key = file.gsub(input_directory, '').gsub(/^\//, '').gsub(/[a-z]+\/translations\.[a-z]+\.json$/, "__LOCALE__/translations.#{root_key}.json|")
23
+
24
+ content = flattenize_hash(content, base_key)
25
+
26
+ memo.merge! content
27
+ end
28
+ end
29
+
30
+ def build_output_from_pods(input_directory, locale)
31
+ pattern = File.join(input_directory, '**', "translations.#{locale}.json")
32
+
33
+ Dir[pattern].reduce({}) do |memo, file|
34
+ content = read_or_ignore(file, input_directory)
35
+
36
+ return nil unless content
37
+
38
+ base_key = file.gsub(input_directory, '').gsub(/^\//, '').gsub(/\/translations.#{locale}.json$/, '/translations.__LOCALE__.json|')
39
+
40
+ content = flattenize_hash(content, base_key)
41
+
42
+ memo.merge! content
43
+ end
44
+ end
45
+
46
+ def write_json_file
47
+ file_path = @output_file
48
+ puts "Generating #{file_path}"
49
+ FileUtils.mkdir_p(File.dirname(file_path))
50
+
51
+ File.open(file_path, 'w+') do |file|
52
+ file << @output.to_json
53
+ end
54
+ end
55
+
56
+ def read_or_ignore(file, input_directory)
57
+ filepath = file.gsub(/\A#{input_directory}\//, '')
58
+
59
+ if ignored_filepath?(filepath)
60
+ puts "Ignoring #{filepath}"
61
+ false
62
+ else
63
+ puts "Processing #{filepath}"
64
+ content = File.read(file)
65
+ JSON.parse(content)
66
+ end
67
+ end
68
+
69
+ def flattenize_hash(hash, base_key = '')
70
+ if hash.is_a?(Hash)
71
+ hash.reduce({}) do |memo, (key, value)|
72
+ new_base_key = [base_key, key].join('.').gsub(/\|\.+/, '|')
73
+ memo.merge! flattenize_hash(value, new_base_key)
74
+ end
75
+ else
76
+ { base_key.gsub(/^\./, '') => hash }
77
+ end
78
+ end
79
+
80
+ def ignored_filepath?(filepath)
81
+ @ignore && @ignore.any? do |pattern|
82
+ File.fnmatch(pattern, filepath, File::FNM_PATHNAME | File::FNM_DOTMATCH)
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,57 @@
1
+ module Aigu
2
+ class EmberPodImporter < Importer
3
+ def process!
4
+ puts "Generating JSON files in `#{@output_directory}` based on Accent-generated `#{@input_file}` file"
5
+ puts '---'
6
+
7
+ object = sorted_object_from_json(@input_file)
8
+ blob = build_blob(object)
9
+ write_json_files(blob, @output_directory)
10
+
11
+ puts '---'
12
+ puts 'Done'
13
+ end
14
+
15
+ protected
16
+
17
+ def sorted_object_from_json(input_file)
18
+ json = File.read(input_file)
19
+ JSON.parse(json).sort_with_keys
20
+ end
21
+
22
+ def write_json_files(blob, output_directory)
23
+ blob.each_pair do |file_name, translations|
24
+ file_path = File.join(output_directory, file_name.gsub('__LOCALE__', @locale))
25
+ puts "Generating #{file_path}"
26
+ FileUtils.mkdir_p(File.dirname(file_path))
27
+
28
+ content = JSON.pretty_generate(translations)
29
+
30
+ File.open(file_path, 'w+') do |file|
31
+ file << content
32
+ end
33
+ end
34
+ end
35
+
36
+ def build_blob(object)
37
+ blob = Hash.recursive
38
+
39
+ object.each_pair do |key, value|
40
+ filename, flat_key = key.split('|')
41
+
42
+ parts = flat_key.split('.')
43
+ hash = blob[filename]
44
+
45
+ parts.each_with_index do |part, index|
46
+ if index + 1 < parts.length
47
+ hash = hash[part]
48
+ else
49
+ hash[part] = value
50
+ end
51
+ end
52
+ end
53
+
54
+ blob
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module Aigu
2
- VERSION = '0.6.1'
2
+ VERSION = '0.7'
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aigu::EmberPodExporter do
4
+ describe :build_output do
5
+ let(:input_directory) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'ember_pod_files') }
6
+ let(:exporter) { Aigu::EmberPodExporter.new(:'input-directory' => input_directory, locale: 'en') }
7
+ let(:output) { exporter.send(:build_output) }
8
+
9
+ let(:expected_output) do
10
+ {
11
+ 'app/locales/__LOCALE__/translations.general.json|hello' => 'Hello from general.hello',
12
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|errors.general' => 'Nested A) An error occured.',
13
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|errors.network' => 'Nested A) A network error occured.',
14
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|labels.first_name' => 'Nested A) First Name',
15
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|labels.last_name' => 'Nested A) Last Name',
16
+ 'app/pods/component-a/translations.__LOCALE__.json|errors.general' => 'A) An error occured.',
17
+ 'app/pods/component-a/translations.__LOCALE__.json|errors.network' => 'A) A network error occured.',
18
+ 'app/pods/component-a/translations.__LOCALE__.json|labels.first_name' => 'A) First Name',
19
+ 'app/pods/component-a/translations.__LOCALE__.json|labels.last_name' => 'A) Last Name',
20
+ 'app/pods/component-b/translations.__LOCALE__.json|errors.general' => 'B) An error occured.',
21
+ 'app/pods/component-b/translations.__LOCALE__.json|errors.network' => 'B) A network error occured.',
22
+ 'app/pods/component-b/translations.__LOCALE__.json|labels.first_name' => 'B) First Name',
23
+ 'app/pods/component-b/translations.__LOCALE__.json|labels.last_name' => 'B) Last Name'
24
+ }
25
+ end
26
+
27
+ it { expect(output).to eql expected_output }
28
+ end
29
+ end
@@ -0,0 +1,66 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aigu::EmberPodImporter do
4
+ describe :build_blob do
5
+ let(:importer) { Aigu::EmberPodImporter.new }
6
+ let(:blob) { importer.send(:build_blob, content) }
7
+
8
+ let(:content) do
9
+ {
10
+ 'app/locales/__LOCALE__/translations.general.json|hello' => 'Hello from general.hello',
11
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|labels.first_name' => 'Nested A) First Name',
12
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|labels.last_name' => 'Nested A) Last Name',
13
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|errors.general' => 'Nested A) An error occured.',
14
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json|errors.network' => 'Nested A) A network error occured.',
15
+ 'app/pods/component-a/translations.__LOCALE__.json|labels.first_name' => 'A) First Name',
16
+ 'app/pods/component-a/translations.__LOCALE__.json|labels.last_name' => 'A) Last Name',
17
+ 'app/pods/component-a/translations.__LOCALE__.json|errors.general' => 'A) An error occured.',
18
+ 'app/pods/component-a/translations.__LOCALE__.json|errors.network' => 'A) A network error occured.',
19
+ 'app/pods/component-b/translations.__LOCALE__.json|labels.first_name' => 'B) First Name',
20
+ 'app/pods/component-b/translations.__LOCALE__.json|labels.last_name' => 'B) Last Name',
21
+ 'app/pods/component-b/translations.__LOCALE__.json|errors.general' => 'B) An error occured.',
22
+ 'app/pods/component-b/translations.__LOCALE__.json|errors.network' => 'B) A network error occured.'
23
+ }
24
+ end
25
+
26
+ let(:expected_blob) do
27
+ {
28
+ 'app/locales/__LOCALE__/translations.general.json' => {
29
+ 'hello' => 'Hello from general.hello'
30
+ },
31
+ 'app/pods/component-a/nested-component-a/translations.__LOCALE__.json' => {
32
+ 'errors' => {
33
+ 'general' => 'Nested A) An error occured.',
34
+ 'network' => 'Nested A) A network error occured.'
35
+ },
36
+ 'labels' => {
37
+ 'first_name' => 'Nested A) First Name',
38
+ 'last_name' => 'Nested A) Last Name'
39
+ }
40
+ },
41
+ 'app/pods/component-a/translations.__LOCALE__.json' => {
42
+ 'errors' => {
43
+ 'general' => 'A) An error occured.',
44
+ 'network' => 'A) A network error occured.'
45
+ },
46
+ 'labels' => {
47
+ 'first_name' => 'A) First Name',
48
+ 'last_name' => 'A) Last Name'
49
+ }
50
+ },
51
+ 'app/pods/component-b/translations.__LOCALE__.json' => {
52
+ 'errors' => {
53
+ 'general' => 'B) An error occured.',
54
+ 'network' => 'B) A network error occured.'
55
+ },
56
+ 'labels' => {
57
+ 'first_name' => 'B) First Name',
58
+ 'last_name' => 'B) Last Name'
59
+ }
60
+ }
61
+ }
62
+ end
63
+
64
+ it { expect(blob).to eql expected_blob }
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ {
2
+ "hello": "Hello from general.hello"
3
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "hello": "Bonjour de general.hello"
3
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "Nested A) First Name",
4
+ "last_name": "Nested A) Last Name"
5
+ },
6
+ "errors": {
7
+ "general": "Nested A) An error occured.",
8
+ "network": "Nested A) A network error occured."
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "Nested A) Prénom",
4
+ "last_name": "Nested A) Nom"
5
+ },
6
+ "errors": {
7
+ "general": "Nested A) Une erreur est survenue.",
8
+ "network": "Nested A) Une erreur réseau est survenue."
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "A) First Name",
4
+ "last_name": "A) Last Name"
5
+ },
6
+ "errors": {
7
+ "general": "A) An error occured.",
8
+ "network": "A) A network error occured."
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "A) Prénom",
4
+ "last_name": "A) Nom"
5
+ },
6
+ "errors": {
7
+ "general": "A) Une erreur est survenue.",
8
+ "network": "A) Une erreur réseau est survenue."
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "B) First Name",
4
+ "last_name": "B) Last Name"
5
+ },
6
+ "errors": {
7
+ "general": "B) An error occured.",
8
+ "network": "B) A network error occured."
9
+ }
10
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "labels": {
3
+ "first_name": "B) Prénom",
4
+ "last_name": "B) Nom"
5
+ },
6
+ "errors": {
7
+ "general": "B) Une erreur est survenue.",
8
+ "network": "B) Une erreur réseau est survenue."
9
+ }
10
+ }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aigu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: '0.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-07 00:00:00.000000000 Z
12
+ date: 2017-04-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -125,6 +125,8 @@ files:
125
125
  - lib/aigu/core_importer.rb
126
126
  - lib/aigu/ember_exporter.rb
127
127
  - lib/aigu/ember_importer.rb
128
+ - lib/aigu/ember_pod_exporter.rb
129
+ - lib/aigu/ember_pod_importer.rb
128
130
  - lib/aigu/exporter.rb
129
131
  - lib/aigu/extensions/hash.rb
130
132
  - lib/aigu/importer.rb
@@ -143,10 +145,20 @@ files:
143
145
  - spec/aigu/core_importer_spec.rb
144
146
  - spec/aigu/ember_exporter_spec.rb
145
147
  - spec/aigu/ember_importer_spec.rb
148
+ - spec/aigu/ember_pod_exporter_spec.rb
149
+ - spec/aigu/ember_pod_importer_spec.rb
146
150
  - spec/aigu/ios_exporter_spec.rb
147
151
  - spec/aigu/ios_importer_spec.rb
148
152
  - spec/aigu/rails_exporter_spec.rb
149
153
  - spec/aigu/rails_importer_spec.rb
154
+ - spec/fixtures/ember_pod_files/app/locales/en/translations.general.json
155
+ - spec/fixtures/ember_pod_files/app/locales/fr/translations.general.json
156
+ - spec/fixtures/ember_pod_files/app/pods/component-a/nested-component-a/translations.en.json
157
+ - spec/fixtures/ember_pod_files/app/pods/component-a/nested-component-a/translations.fr.json
158
+ - spec/fixtures/ember_pod_files/app/pods/component-a/translations.en.json
159
+ - spec/fixtures/ember_pod_files/app/pods/component-a/translations.fr.json
160
+ - spec/fixtures/ember_pod_files/app/pods/component-b/translations.en.json
161
+ - spec/fixtures/ember_pod_files/app/pods/component-b/translations.fr.json
150
162
  - spec/spec_helper.rb
151
163
  homepage: https://github.com/mirego/aigu
152
164
  licenses:
@@ -158,9 +170,9 @@ require_paths:
158
170
  - lib
159
171
  required_ruby_version: !ruby/object:Gem::Requirement
160
172
  requirements:
161
- - - ">="
173
+ - - "~>"
162
174
  - !ruby/object:Gem::Version
163
- version: '0'
175
+ version: '2.1'
164
176
  required_rubygems_version: !ruby/object:Gem::Requirement
165
177
  requirements:
166
178
  - - ">="
@@ -168,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
180
  version: '0'
169
181
  requirements: []
170
182
  rubyforge_project:
171
- rubygems_version: 2.4.5
183
+ rubygems_version: 2.6.8
172
184
  signing_key:
173
185
  specification_version: 4
174
186
  summary: Aigu converts a directory of Rails localization files into a single JSON
@@ -180,8 +192,18 @@ test_files:
180
192
  - spec/aigu/core_importer_spec.rb
181
193
  - spec/aigu/ember_exporter_spec.rb
182
194
  - spec/aigu/ember_importer_spec.rb
195
+ - spec/aigu/ember_pod_exporter_spec.rb
196
+ - spec/aigu/ember_pod_importer_spec.rb
183
197
  - spec/aigu/ios_exporter_spec.rb
184
198
  - spec/aigu/ios_importer_spec.rb
185
199
  - spec/aigu/rails_exporter_spec.rb
186
200
  - spec/aigu/rails_importer_spec.rb
201
+ - spec/fixtures/ember_pod_files/app/locales/en/translations.general.json
202
+ - spec/fixtures/ember_pod_files/app/locales/fr/translations.general.json
203
+ - spec/fixtures/ember_pod_files/app/pods/component-a/nested-component-a/translations.en.json
204
+ - spec/fixtures/ember_pod_files/app/pods/component-a/nested-component-a/translations.fr.json
205
+ - spec/fixtures/ember_pod_files/app/pods/component-a/translations.en.json
206
+ - spec/fixtures/ember_pod_files/app/pods/component-a/translations.fr.json
207
+ - spec/fixtures/ember_pod_files/app/pods/component-b/translations.en.json
208
+ - spec/fixtures/ember_pod_files/app/pods/component-b/translations.fr.json
187
209
  - spec/spec_helper.rb