aigu 0.1.1 → 0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2399c45ee60052b0923ec680f270da427d9fbf13
4
- data.tar.gz: 25faad74c5700510c038818e99001a9f2106bdf1
3
+ metadata.gz: 6ac2a67491e84fbc1d670cedb00f2e37b656e8ba
4
+ data.tar.gz: ce9901efe5d99728af69b52d6632f7b04657c25a
5
5
  SHA512:
6
- metadata.gz: 675100dddff32390a6806e3036ff778f6566a8ac5d36c6fb2e82ed4ded2c6ef6b17994769bb5c4cdae58af9a3757224b7404b4cd33fbc9422a2451729785780d
7
- data.tar.gz: e61bd39dca2aa76a4c5c479c083f7bd997351555563f8f92823d7054e930e6b9fa7d5f4cf212ca7bc2a3f798cbadd9d8be2de5cc4818cdb389f40096f8407361
6
+ metadata.gz: 57f233c1aadd127fe41c0f320dff136ebb3bc3f0928d7526160dcf5bd2baa038815054a40115bf47f45157bd19aa162366ebdcd42133254f3ead6d8119712e2e
7
+ data.tar.gz: 72b57913979746214ad05df58dc7091a99c18ade41ace5a9408dcd96f3a913a6b942b32dbff140f510892e1614724d26c669c31296163110b8bb9f93885a7f17
data/README.md CHANGED
@@ -31,7 +31,7 @@ $ aigu export --locale=fr --input-directory=config/locales --output-file=my-proj
31
31
 
32
32
  | Option | Description |
33
33
  |-------------------|---------------------------------------------------------------------------------------------------------------------------|
34
- | `locale` | The locale used to find localization files. Files that match `*.<locale>.yml` into the input directory will be processed. |
34
+ | `locale` | The locale used to find localization files. Files that match `*.<locale>.yml` in the input directory will be processed. |
35
35
  | `input-directory` | The directory used to find localization files |
36
36
  | `output-file` | The path to the JSON file that will be written by `aigu` |
37
37
 
@@ -41,15 +41,16 @@ The `import` command takes a generated JSON file from Accent and generates
41
41
  the original YAML file structure.
42
42
 
43
43
  ```bash
44
- $ aigu import --input-file=file-from-accent.json --output-directory=config/locales
44
+ $ aigu import --locale=fr --input-file=file-from-accent.json --output-directory=config/locales
45
45
  ```
46
46
 
47
47
  ### Options
48
48
 
49
49
  | Option | Description |
50
- |--------------------|-------------------------------------------------------------------|
51
- | `input-file` | The path to the Accent-generated JSON file |
52
- | `output-directory` | The directory where the localization YAML files will be generated |
50
+ |--------------------|---------------------------------------------------------------------------------------------------|
51
+ | `locale` | The locale used to generate localization files. Files will be generated as `<file>.<locale>.yml` |
52
+ | `input-file` | The path to the Accent-generated JSON file |
53
+ | `output-directory` | The directory where the localization YAML files will be generated |
53
54
 
54
55
  ## License
55
56
 
data/SPEC.md CHANGED
@@ -54,12 +54,14 @@ fr:
54
54
 
55
55
  ### Output
56
56
 
57
+ With `--locale=fr` option.
58
+
57
59
  ```json
58
60
  {
59
- "app/users.fr|fr.app.users.index.new": "Nouvel utilisateur",
60
- "app/users.fr|fr.app.users.index.edit": "Modifier l’utilisateur %{user}",
61
- "app/shared/comments.fr|fr.app.shared.comments.title": "Tous les commentaires",
62
- "admin/shared.fr|fr.admin.shared.footer.copyright": "Copyright © %{year}",
63
- "layouts.fr|fr.layouts.application.title": "Mon Application"
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"
64
66
  }
65
67
  ```
data/lib/aigu/cli.rb CHANGED
@@ -2,7 +2,7 @@ module Aigu
2
2
  class CLI
3
3
  def initialize(env, argv)
4
4
  @env = env
5
- @command = argv.first =~ /[^-]/ ? argv.shift : nil
5
+ @command = argv.first =~ /^[^-]/ ? argv.shift : nil
6
6
  @argv = argv
7
7
  parse_options
8
8
  end
@@ -43,6 +43,10 @@ module Aigu
43
43
  @options[:output_file] = file
44
44
  end
45
45
 
46
+ opts.on('--locale=', 'The locale to use. Files will be processed/generated using the "<file>.<locale>.yml" pattern.') do |locale|
47
+ @options[:locale] = locale
48
+ end
49
+
46
50
  opts.on_tail('-h', '--help', 'Show this message') do
47
51
  puts opts
48
52
  exit
data/lib/aigu/exporter.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  module Aigu
2
2
  class Exporter
3
- def initialize(output_file: nil, input_directory: nil)
3
+ def initialize(output_file: nil, input_directory: nil, locale: nil)
4
4
  @output_file = output_file
5
5
  @input_directory = input_directory
6
+ @locale = locale
6
7
  end
7
8
 
8
9
  def process!
@@ -21,13 +22,14 @@ module Aigu
21
22
  def build_output
22
23
  @output = {}
23
24
 
24
- Dir[File.join(@input_directory, '**', '*.yml')].each do |file|
25
+ Dir[File.join(@input_directory, '**', "*.#{@locale}.yml")].each do |file|
25
26
  content = YAML.load_file(file)
26
27
  base_key = file.gsub(@input_directory, '').gsub(/^\/*/, '').gsub(/\.yml$/, '|')
27
28
 
28
- content = flattenize_hash(content)
29
+ content = flattenize_hash(content, base_key)
29
30
  content = flattenize_content_values(content)
30
- @output.merge! flattenize_hash(content, base_key)
31
+ content = globalize_content_keys(content)
32
+ @output.merge! content
31
33
  end
32
34
  end
33
35
 
@@ -41,6 +43,13 @@ module Aigu
41
43
  end
42
44
  end
43
45
 
46
+ def globalize_content_keys(content)
47
+ content.reduce({}) do |memo, (key, value)|
48
+ globalized_key = key.gsub(/\.#{@locale}\|#{@locale}\./, '|')
49
+ memo.merge globalized_key => value
50
+ end
51
+ end
52
+
44
53
  def flattenize_content_values(hash)
45
54
  result = {}
46
55
 
data/lib/aigu/importer.rb CHANGED
@@ -2,9 +2,10 @@ module Aigu
2
2
  class Importer
3
3
  ARRAY_REGEX = /___KEY___(?<index>\d+)$/
4
4
 
5
- def initialize(input_file: nil, output_directory: nil)
5
+ def initialize(input_file: nil, output_directory: nil, locale: nil)
6
6
  @input_file = input_file
7
7
  @output_directory = output_directory
8
+ @locale = locale
8
9
  end
9
10
 
10
11
  def process!
@@ -25,11 +26,12 @@ module Aigu
25
26
  json = File.read(@input_file)
26
27
  @object = JSON.parse(json)
27
28
  @object = expand_content_values(@object)
29
+ @object = localize_content_keys(@object)
28
30
  end
29
31
 
30
32
  def write_yaml_files
31
33
  @blob.each_pair do |file_name, hash|
32
- file_path = File.join(@output_directory, "#{file_name}.yml")
34
+ file_path = File.join(@output_directory, "#{file_name}.#{@locale}yml")
33
35
  puts "Generating #{file_path}"
34
36
  FileUtils.mkdir_p(File.dirname(file_path))
35
37
 
@@ -58,6 +60,13 @@ module Aigu
58
60
  end
59
61
  end
60
62
 
63
+ def localized_content_keys(content)
64
+ content.reduce({}) do |memo, (key, value)|
65
+ localized_key = key.gsub(/^([^|]+)\|/, "\\1.#{@locale}|#{@locale}.")
66
+ memo.merge localized_key => value
67
+ end
68
+ end
69
+
61
70
  def expand_content_values(content)
62
71
  content.reduce({}) do |memo, (key, value)|
63
72
  match_data = key.match(ARRAY_REGEX)
data/lib/aigu/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Aigu
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2'
3
3
  end
@@ -35,4 +35,32 @@ describe Aigu::Exporter do
35
35
 
36
36
  it { expect(flattenized_content).to eql expected_content }
37
37
  end
38
+
39
+ describe :globalize_content_keys do
40
+ let(:exporter) { described_class.new }
41
+ let(:globalized_keys) { exporter.send(:globalize_content_keys, content).keys }
42
+ before { exporter.instance_variable_set(:@locale, 'fr') }
43
+
44
+ let(:content) do
45
+ {
46
+ 'users.fr|fr.users.index.title' => 'Foo',
47
+ 'users.fr|fr.users.index.footer' => 'Bla',
48
+ 'users.fr|fr.users.index.fr.shown' => false,
49
+ 'users.fr|fr.users.index.hidden' => true,
50
+ 'users.fr|fr.users.index.what' => nil
51
+ }
52
+ end
53
+
54
+ let(:expected_keys) do
55
+ [
56
+ 'users|users.index.title',
57
+ 'users|users.index.footer',
58
+ 'users|users.index.fr.shown',
59
+ 'users|users.index.hidden',
60
+ 'users|users.index.what'
61
+ ]
62
+ end
63
+
64
+ it { expect(globalized_keys).to eql expected_keys }
65
+ end
38
66
  end
@@ -35,4 +35,32 @@ describe Aigu::Importer do
35
35
 
36
36
  it { expect(expanded_content).to eql expected_content }
37
37
  end
38
+
39
+ describe :localize_content_keys do
40
+ let(:exporter) { described_class.new }
41
+ let(:localized_keys) { exporter.send(:localized_content_keys, content).keys }
42
+ before { exporter.instance_variable_set(:@locale, 'fr') }
43
+
44
+ let(:content) do
45
+ {
46
+ 'users|users.index.title' => 'Foo',
47
+ 'users|users.index.footer' => 'Bla',
48
+ 'users|users.index.fr.shown' => false,
49
+ 'users|users.index.hidden' => true,
50
+ 'foo/users|users.index.what' => nil
51
+ }
52
+ end
53
+
54
+ let(:expected_keys) do
55
+ [
56
+ 'users.fr|fr.users.index.title',
57
+ 'users.fr|fr.users.index.footer',
58
+ 'users.fr|fr.users.index.fr.shown',
59
+ 'users.fr|fr.users.index.hidden',
60
+ 'foo/users.fr|fr.users.index.what'
61
+ ]
62
+ end
63
+
64
+ it { expect(localized_keys).to eql expected_keys }
65
+ end
38
66
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aigu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rémi Prévost
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-07 00:00:00.000000000 Z
11
+ date: 2014-05-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: 3.0.0.beta2
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
54
  version: 3.0.0.beta2
55
55
  description: Aigu converts a directory of Rails localization files into a single JSON
@@ -61,8 +61,8 @@ executables:
61
61
  extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
- - .gitignore
65
- - .rspec
64
+ - ".gitignore"
65
+ - ".rspec"
66
66
  - Gemfile
67
67
  - LICENSE.md
68
68
  - README.md
@@ -89,17 +89,17 @@ require_paths:
89
89
  - lib
90
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  requirements:
97
- - - '>='
97
+ - - ">="
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
101
  rubyforge_project:
102
- rubygems_version: 2.1.0
102
+ rubygems_version: 2.2.2
103
103
  signing_key:
104
104
  specification_version: 4
105
105
  summary: Aigu converts a directory of Rails localization files into a single JSON