aigu 0.7 → 1.0

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: 616ab0c8f167d1882b848067e0f431300ae11e8b
4
- data.tar.gz: eabdfe2a5a75e12e6aab5c86e4da964f09609d56
3
+ metadata.gz: f139727dc870d7af72ca5a7158f82b862ab845d0
4
+ data.tar.gz: e08a5d627d246fc8a683e10bca1b0d92c6c3255d
5
5
  SHA512:
6
- metadata.gz: 1deffeb18fa97f7e6351e106d8271da63aa67c19a65254e69757d7605fa445ba1e4bb501b4f04d67ddb561f96fc964be5db5ff5c964187a933713bfa47a688d0
7
- data.tar.gz: 8efe81cf8c5ce9d153d098681117f98eb010d264619c84d0ac7fae9d34aa45e78cf50b5a3ad52cea4eec0d5eda2c23c73c637b76c6b6dac2abd6a9c1072e27c8
6
+ metadata.gz: 408822e9bbe23a275efa973102e9ee0dbbeface4f27c9483b80632b7f367cef9a9cd1acb249de36c905bd6499fc0e5e6b9b2491d8dbbc3b96efcaf30fdaa9ac3
7
+ data.tar.gz: 93567c83ec12858ab34e243887f8b711f03d597f596d83531bcc5c8bb17b7f5d5a5e6944ad400552ed2cdcefe2f972649641167cf7a76e041c9e3c9933729cf8
@@ -1,6 +1,8 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 2.4.0
5
+ - 2.3.3
4
6
  - 2.2
5
7
 
6
8
  sudo: false
data/README.md CHANGED
@@ -1,16 +1,8 @@
1
1
  ## Introduction
2
2
 
3
- Aigu is a set of utility to process localization files to genarate JSON files
4
- to push to Accent service. Pulling from Accent to update localization files
5
- is also supported.
6
-
7
- The following localization file formats are supported: Rails YAML, Android XML,
8
- Java Enum Core, iOS strings and stringsdict and Ember JavaScript.
9
-
10
- Merge and unmerge commands allows to merge different source files into a
11
- single JSON file to send as a single Accent project.
12
-
13
- Push and pull can be used to interact directly with Accent.
3
+ Aigu is a set of utility to process localization files to generate JSON files
4
+ to send to Accent as well as taking JSON files from Accent and convert them
5
+ back to localization files.
14
6
 
15
7
  ## Installation
16
8
 
@@ -34,24 +26,25 @@ This file will then be compatible with Accent.
34
26
  ```bash
35
27
  $ aigu <export-command> --locale=fr --input-directory=config/locales --output-file=my-project.json
36
28
  ```
29
+ #### Commands
30
+
31
+ | Command | File format |
32
+ |--------------------|---------------------------|
33
+ | `rails-export` | Rails YAML |
34
+ | `android-export` | Android XML |
35
+ | `core-export` | Java Enum Core |
36
+ | `ios-export` | iOS strings & stringsdict |
37
+ | `ember-export` | Ember.js JavaScript |
38
+ | `ember-pod-export` | Ember.js pods JSON |
37
39
 
38
40
  #### Options
39
41
 
40
- | Option | Description |
41
- |-------------------|------------------------------------------------------------------------|
42
- | `locale` | The locale used to find localization files. |
43
- | `input-directory` | The directory used to find localization files |
44
- | `output-file` | The path to the JSON file that will be written by `aigu` |
45
- | `ignore` | The patterns `aigu` will use to skip ignored files (eg. `routes.yml`) |
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 |
54
- | `ember-pod-export` | Ember.js pods JSON |
42
+ | Option | Description |
43
+ |-------------------|-----------------------------------------------------------------------|
44
+ | `locale` | The locale used to find localization files. |
45
+ | `input-directory` | The directory used to find localization files |
46
+ | `output-file` | The path to the JSON file that will be written by `aigu` |
47
+ | `ignore` | The patterns `aigu` will use to skip ignored files (eg. `routes.yml`) |
55
48
 
56
49
  ### Importing the JSON file from Accent
57
50
 
@@ -62,72 +55,24 @@ localization files in the output directory.
62
55
  $ aigu <import-command> --locale=fr --input-file=file-from-accent.json --output-directory=config/locales
63
56
  ```
64
57
 
65
- #### Options
66
-
67
- | Option | Description |
68
- |--------------------|---------------------------------------------------------------------------------------------------|
69
- | `locale` | The locale used to generate localization files. Files will be generated as `<file>.<locale>.yml` |
70
- | `input-file` | The path to the Accent-generated JSON file |
71
- | `output-directory` | The directory where the localization YAML files will be generated |
72
-
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 |
81
-
82
- ### Merge
83
-
84
- The `merge` command will combine several JSON file into a single one to send into a single Accent project. It will prefix keys with
85
- a pattern embedding the filename to allow later unmerging. It works from an input directory, mergin all json files in it.
86
- A file can be named `default.json` to avoid prefixes in the resulting json.
87
-
88
- #### Options
89
-
90
- | Option | Description |
91
- |--------------------|---------------------------------------------------------------------------------------------------|
92
- | `input-directory` | The directory containing json files to merge |
93
- | `output-file` | The path to the JSON file that will be written to |
94
-
95
-
96
- ### Unmerge
97
-
98
- The `unmerge` will split the Accent JSON file into several json files, for further processing. It will look for the prefix pattern
99
- of the merge command and will extract the filename or use default.json if pattern is not found.
100
-
101
- #### Options
102
-
103
- | Option | Description |
104
- |--------------------|---------------------------------------------------------------------------------------------------|
105
- | `input-file` | The path to the Accent-generated JSON file |
106
- | `output-directory` | The directory where the unmerged files will be written |
107
-
108
- ### Sending to Accent
109
-
110
- The `push` command takes a JSON file exported by Aigu and send it to Accent
111
-
112
- #### Options
113
-
114
- | Option | Description |
115
- |--------------------|-------------------------------------------------------------------|
116
- | `input-file` | The path to the Aigu-generated JSON file |
117
- | `accent-api-key` | The API key of the Accent project. (See project config in Accent) |
118
- | `accent-url` | The URL to the instance of Accent to use |
119
-
120
- ### Pulling from Accent
58
+ #### Commands
121
59
 
122
- The `pull` command GET the Accent generated JSON file
60
+ | Command | File format |
61
+ |--------------------|---------------------------|
62
+ | `rails-import` | Rails YAML |
63
+ | `android-import` | Android XML |
64
+ | `core-import` | Java Enum Core |
65
+ | `ios-import` | iOS strings & stringsdict |
66
+ | `ember-import` | Ember.js JavaScript |
67
+ | `ember-pod-import` | Ember.js pods JSON |
123
68
 
124
69
  #### Options
125
70
 
126
- | Option | Description |
127
- |--------------------|-------------------------------------------------------------------|
128
- | `output-file` | The path to write the Accent JSON file to |
129
- | `accent-api-key` | The API key of the Accent project. (See project config in Accent) |
130
- | `accent-url` | The URL to the instance of Accent to use |
71
+ | Option | Description |
72
+ |--------------------|--------------------------------------------------------------------------------------------------|
73
+ | `locale` | The locale used to generate localization files. Files will be generated as `<file>.<locale>.yml` |
74
+ | `input-file` | The path to the Accent-generated JSON file |
75
+ | `output-directory` | The directory where the localization YAML files will be generated |
131
76
 
132
77
  ### Using `.aigu.yml`
133
78
 
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Aigu::VERSION
9
9
  spec.authors = ['Rémi Prévost', 'William Jobin']
10
10
  spec.email = ['rprevost@mirego.com', 'wjobin@mirego.com']
11
- spec.description = 'Aigu converts a directory of Rails localization files into a single JSON file to import in Accent.'
11
+ spec.description = 'Aigu is a set of utility to process localization files to generate JSON files to send to Accent as well as taking JSON files from Accent and convert them back to localization files.'
12
12
  spec.summary = spec.description
13
13
  spec.homepage = 'https://github.com/mirego/aigu'
14
14
  spec.license = 'BSD 3-Clause'
@@ -27,10 +27,5 @@ require 'aigu/ember_importer'
27
27
  require 'aigu/ember_pod_exporter'
28
28
  require 'aigu/ember_pod_importer'
29
29
 
30
- require 'aigu/unmerger'
31
- require 'aigu/merger'
32
- require 'aigu/puller'
33
- require 'aigu/pusher'
34
-
35
30
  module Aigu
36
31
  end
@@ -12,11 +12,7 @@ module Aigu
12
12
  'ember-import' => 'EmberImporter',
13
13
  'ember-export' => 'EmberExporter',
14
14
  'ember-pod-import' => 'EmberPodImporter',
15
- 'ember-pod-export' => 'EmberPodExporter',
16
- 'merge' => 'Merger',
17
- 'unmerge' => 'Unmerger',
18
- 'pull' => 'Puller',
19
- 'push' => 'Pusher'
15
+ 'ember-pod-export' => 'EmberPodExporter'
20
16
  }.freeze
21
17
 
22
18
  def initialize(env, argv)
@@ -69,23 +65,23 @@ Commands:
69
65
  Options:
70
66
  DOC
71
67
 
72
- opts.on('--input-directory=', 'The directory in which the Rails YAML localization files are stored.') do |directory|
68
+ opts.on('--input-directory=', 'The directory in which the Rails YAML localization files are stored') do |directory|
73
69
  options[:'input-directory'] = directory
74
70
  end
75
71
 
76
- opts.on('--output-directory=', 'The directory in which the Rails YAML localization files will be generated.') do |directory|
72
+ opts.on('--output-directory=', 'The directory in which the Rails YAML localization files will be generated') do |directory|
77
73
  options[:'output-directory'] = directory
78
74
  end
79
75
 
80
- opts.on('--input-file=', 'The JSON file generated by Accent.') do |file|
76
+ opts.on('--input-file=', 'The JSON file generated by Accent') do |file|
81
77
  options[:'input-file'] = file
82
78
  end
83
79
 
84
- opts.on('--output-file=', 'The JSON file that will be generated for Accent.') do |file|
80
+ opts.on('--output-file=', 'The JSON file that will be generated for Accent') do |file|
85
81
  options[:'output-file'] = file
86
82
  end
87
83
 
88
- opts.on('--locale=', 'The locale to use. Files will be processed/generated using the "<file>.<locale>.yml" pattern.') do |locale|
84
+ opts.on('--locale=', 'The locale to use. Importers and exporters may need it to process files') do |locale|
89
85
  options[:locale] = locale
90
86
  end
91
87
 
@@ -93,12 +89,9 @@ DOC
93
89
  options[:ignore] = ignore.split(',')
94
90
  end
95
91
 
96
- opts.on('--accent-api-key=', 'Accent API key') do |key|
97
- options[:'accent-api-key'] = key
98
- end
99
-
100
- opts.on('--accent-url=', 'Accent URL (ex: http://accent.mirego.com)') do |url|
101
- options[:'accent-url'] = url
92
+ opts.on_tail('-v', '--version', 'Output Aigu’s version') do
93
+ puts "aigu-v#{Aigu::VERSION}"
94
+ exit
102
95
  end
103
96
 
104
97
  opts.on_tail('-h', '--help', 'Show this message') do
@@ -1,3 +1,3 @@
1
1
  module Aigu
2
- VERSION = '0.7'
2
+ VERSION = '1.0'
3
3
  end
@@ -3,7 +3,15 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
3
  require 'rspec'
4
4
  require 'aigu'
5
5
 
6
- RSpec.configure do |*|
6
+ RSpec.configure do |config|
7
+ config.before(:suite) do
8
+ module Kernel
9
+ def puts(*)
10
+ # Silence “puts” calls — we don’t want to write anything to STDOUT when
11
+ # running the test suite.
12
+ end
13
+ end
14
+ end
7
15
  end
8
16
 
9
17
  class String
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.7'
4
+ version: '1.0'
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: 2017-04-18 00:00:00.000000000 Z
12
+ date: 2017-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -95,8 +95,9 @@ dependencies:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '1.6'
98
- description: Aigu converts a directory of Rails localization files into a single JSON
99
- file to import in Accent.
98
+ description: Aigu is a set of utility to process localization files to generate JSON
99
+ files to send to Accent as well as taking JSON files from Accent and convert them
100
+ back to localization files.
100
101
  email:
101
102
  - rprevost@mirego.com
102
103
  - wjobin@mirego.com
@@ -113,7 +114,6 @@ files:
113
114
  - LICENSE.md
114
115
  - README.md
115
116
  - Rakefile
116
- - SPEC.md
117
117
  - aigu.gemspec
118
118
  - bin/aigu
119
119
  - bin/phare
@@ -132,12 +132,8 @@ files:
132
132
  - lib/aigu/importer.rb
133
133
  - lib/aigu/ios_exporter.rb
134
134
  - lib/aigu/ios_importer.rb
135
- - lib/aigu/merger.rb
136
- - lib/aigu/puller.rb
137
- - lib/aigu/pusher.rb
138
135
  - lib/aigu/rails_exporter.rb
139
136
  - lib/aigu/rails_importer.rb
140
- - lib/aigu/unmerger.rb
141
137
  - lib/aigu/version.rb
142
138
  - spec/aigu/android_exporter_spec.rb
143
139
  - spec/aigu/android_importer_spec.rb
@@ -183,8 +179,9 @@ rubyforge_project:
183
179
  rubygems_version: 2.6.8
184
180
  signing_key:
185
181
  specification_version: 4
186
- summary: Aigu converts a directory of Rails localization files into a single JSON
187
- file to import in Accent.
182
+ summary: Aigu is a set of utility to process localization files to generate JSON files
183
+ to send to Accent as well as taking JSON files from Accent and convert them back
184
+ to localization files.
188
185
  test_files:
189
186
  - spec/aigu/android_exporter_spec.rb
190
187
  - spec/aigu/android_importer_spec.rb
data/SPEC.md DELETED
@@ -1,67 +0,0 @@
1
- # Specification
2
-
3
- ## Keys
4
-
5
- Keys are generated based on the localization file path and the YAML key.
6
-
7
- ```json
8
- {
9
- "<path>|<key>": "<value>"
10
- }
11
- ```
12
-
13
- Where:
14
-
15
- | Item | Description |
16
- |-----------|-----------------------------------------------------------------------|
17
- | `<path>` | The path of the YAML localization file (with `/` used as a separator) |
18
- | `<key> ` | The full YAML key with `:` used as a separator between levels |
19
- | `<value>` | The localized string |
20
-
21
- ## Examples
22
-
23
- ### Input
24
-
25
- ```yaml
26
- # config/locales/app/users.fr.yml
27
- fr:
28
- app:
29
- users:
30
- index:
31
- new: 'Nouvel utilisateur'
32
- edit: 'Modifier l’utilisateur %{user}'
33
-
34
- # config/locales/app/shared/comments.fr.yml
35
- fr:
36
- app:
37
- shared:
38
- comments:
39
- title: 'Tous les commentaires'
40
-
41
- # config/locales/admin/shared.fr.yml
42
- fr:
43
- admin:
44
- shared:
45
- footer:
46
- copyright: 'Copyright © %{year}'
47
-
48
- # config/locales/layouts.fr.yml
49
- fr:
50
- layouts:
51
- application:
52
- title: 'Mon Application'
53
- ```
54
-
55
- ### Output
56
-
57
- With `--locale=fr` option.
58
-
59
- ```json
60
- {
61
- "app/users|app.users.index.new": "Nouvel utilisateur",
62
- "app/users|app.users.index.edit": "Modifier l’utilisateur %{user}",
63
- "app/shared/comments|app.shared.comments.title": "Tous les commentaires",
64
- "admin/shared|admin.shared.footer.copyright": "Copyright © %{year}",
65
- "layouts|layouts.application.title": "Mon Application"
66
- }
67
- ```
@@ -1,51 +0,0 @@
1
- module Aigu
2
- class Merger
3
- def initialize(opts = {})
4
- @output_file = opts[:'output-file']
5
- @input_directory = opts[:'input-directory']
6
- end
7
-
8
- def process!
9
- puts "Generating flat Accent JSON file `#{@output_file}` merging json files in `#{@input_directory}` directory"
10
-
11
- puts '---'
12
-
13
- build_output
14
- write_json_file
15
-
16
- puts '---'
17
- puts 'Done'
18
- end
19
-
20
- protected
21
-
22
- def build_output
23
- @output = {}
24
-
25
- pattern = File.join(@input_directory, '*.json')
26
- Dir[pattern].each do |filepath|
27
- puts "Processing #{filepath}"
28
-
29
- file_name = filepath.rpartition(File::SEPARATOR).last.split('.', 2).first
30
- prefix = file_name == 'default' ? '' : "@#{file_name.upcase}@__"
31
-
32
- json = JSON.parse(File.read(filepath))
33
- json.each_pair do |key, value|
34
- @output[prefix + key] = value
35
- end
36
- end
37
-
38
- @output
39
- end
40
-
41
- def write_json_file
42
- file_path = @output_file
43
- puts "Generating #{file_path}"
44
- FileUtils.mkdir_p(File.dirname(file_path))
45
-
46
- File.open(file_path, 'w+') do |file|
47
- file << JSON.pretty_generate(JSON.parse(@output.to_json))
48
- end
49
- end
50
- end
51
- end
@@ -1,49 +0,0 @@
1
- module Aigu
2
- class Puller
3
- PULL_PATH = '/public_api/latest_revision?language=%s&render_format=json&render_filename=aigu.json'
4
-
5
- def initialize(opts = {})
6
- @output_file = opts[:'output-file']
7
- @accent_api_key = opts[:'accent-api-key']
8
- @accent_url = opts[:'accent-url']
9
- @locale = opts[:'locale']
10
- end
11
-
12
- def process!
13
- puts "Pulling JSON file `#{@output_file}` from Accent"
14
-
15
- puts '---'
16
-
17
- pull
18
-
19
- puts '---'
20
- puts 'Done'
21
- end
22
-
23
- protected
24
-
25
- def pull
26
- uri = URI(@accent_url + format(PULL_PATH, @locale))
27
-
28
- http = Net::HTTP.new(uri.host, uri.port)
29
- uri.scheme == 'https' && http.use_ssl = true
30
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
31
- request = Net::HTTP::Get.new(uri)
32
- request.add_field('Authorization', @accent_api_key)
33
-
34
- response = http.request(request)
35
- puts 'Response code: ' + response.code
36
-
37
- if response.code != '200'
38
- puts 'Error pulling string revision from Accent'
39
- exit 1
40
- end
41
-
42
- puts "Generating #{@output_file}"
43
-
44
- File.open(@output_file, 'w+') do |file|
45
- file << response.body
46
- end
47
- end
48
- end
49
- end
@@ -1,53 +0,0 @@
1
- module Aigu
2
- class Pusher
3
- PUSH_PATH = '/public_api/revisions'
4
-
5
- HTTP_ALREADY_UP_TO_DATE = '200'.freeze
6
- HTTP_UPDATED = '201'.freeze
7
- HTTP_SUCCESS_CODES = [HTTP_ALREADY_UP_TO_DATE, HTTP_UPDATED].freeze
8
-
9
- def initialize(opts = {})
10
- @input_file = opts[:'input-file']
11
- @accent_api_key = opts[:'accent-api-key']
12
- @accent_url = opts[:'accent-url']
13
- end
14
-
15
- def process!
16
- puts "Sending JSON file `#{@input_file}` to Accent"
17
-
18
- puts '---'
19
-
20
- send
21
-
22
- puts '---'
23
- puts 'Done'
24
- end
25
-
26
- protected
27
-
28
- def send
29
- payload = File.read(@input_file)
30
- file_name = @input_file.rpartition(File::SEPARATOR).last
31
-
32
- uri = URI(@accent_url + PUSH_PATH)
33
-
34
- http = Net::HTTP.new(uri.host, uri.port)
35
- uri.scheme == 'https' && http.use_ssl = true
36
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
- request = Net::HTTP::Post.new(uri)
38
- request.add_field('Authorization', @accent_api_key)
39
- request.add_field('Content-Type', 'application/json')
40
-
41
- request.body = JSON.pretty_generate(JSON.parse({ revision: { file: payload, filename: file_name } }.to_json))
42
-
43
- response = http.request(request)
44
-
45
- puts 'Response: ' + response.code
46
-
47
- unless HTTP_SUCCESS_CODES.include? response.code
48
- puts 'Error pushing string update to Accent'
49
- exit 1
50
- end
51
- end
52
- end
53
- end
@@ -1,55 +0,0 @@
1
- module Aigu
2
- class Unmerger
3
- UNMERGE_REGEX = /^@(?<file_name>\w+)@__(?<key>.+)$/
4
-
5
- def initialize(opts = {})
6
- @output_directory = opts[:'output-directory']
7
- @input_file = opts[:'input-file']
8
- end
9
-
10
- def process!
11
- puts "Unmerging Accent json file `#{@input_file}` to `#{@output_directory}` directory"
12
-
13
- puts '---'
14
-
15
- parse_json
16
- write_json_files
17
-
18
- puts '---'
19
- puts 'Done'
20
- end
21
-
22
- protected
23
-
24
- def parse_json
25
- @object = {}
26
-
27
- json = JSON.parse(File.read(@input_file))
28
-
29
- json.each_pair do |key, value|
30
- match_data = key.match(UNMERGE_REGEX)
31
- if match_data
32
- @object[match_data[:file_name]] ||= {}
33
- @object[match_data[:file_name]][match_data[:key]] = value
34
- else
35
- @object['DEFAULT'] ||= {}
36
- @object['DEFAULT'][key] = value
37
- end
38
- end
39
-
40
- @object
41
- end
42
-
43
- def write_json_files
44
- @object.each_pair do |file_name, json|
45
- file_path = File.join(@output_directory, "#{file_name.downcase}.json")
46
- puts "Generating #{file_path}"
47
- FileUtils.mkdir_p(File.dirname(file_path))
48
-
49
- File.open(file_path, 'w+') do |file|
50
- file << JSON.pretty_generate(JSON.parse(json.to_json))
51
- end
52
- end
53
- end
54
- end
55
- end