i18n-cli 0.1.1 → 0.2.1

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
  SHA256:
3
- metadata.gz: 4bd556b60de6270065c861c645627b5e441614d80a9e591adf1bca5916a1ddb5
4
- data.tar.gz: d33fa5bd9ac4e58c881b1dd5784aae585ab72bd9603fd90dfb33b9ad503caa32
3
+ metadata.gz: 5f7eb38204d9dbac1f6a9dc389aa351a529d59a7daea429021fe65e623973b76
4
+ data.tar.gz: e15364b3faf8c70f367f3efbb5c74e736a9c4b6cfbe005dde83a0c249b340637
5
5
  SHA512:
6
- metadata.gz: 11472bd3992d9c1544d28a1330b8e177d1261eff247ca2a7bbd2db181a3b0558c1ce6d70629a8df28f5c13111f29f9f29e194f7b4a6c531dcca72b29ffdb2e78
7
- data.tar.gz: a9e31d22720fc60399c08164d65c7054485824c69bd15e6ebfc0f8cfc4954bfd70e7100c7c38f3413ce612f164da868f7405e579231a35c656fe7640442fadd4
6
+ metadata.gz: f55cfa08fb49a022a59b15405e7564d6ee544061a7bb444df227b1babcfc626f72696a0ff661d2605d0843a44c9f7f15a6767887da90db7b89744cbef2dc7efe
7
+ data.tar.gz: 58a9417706ae3bcd73f2d202e5a7196388b5c2d71b346ae1872c8eab0444924dbf6ada44785f9231f66642b01b940bfacc0570bf8d16fcf57ef916badca7d22f
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'fileutils'
2
3
  require 'i18n-cli/version'
3
4
 
4
5
  module I18n
@@ -18,6 +19,8 @@ module I18n
18
19
  apply
19
20
  when 'commit'
20
21
  commit
22
+ when 'build'
23
+ build
21
24
  else
22
25
  help
23
26
  end
@@ -32,7 +35,8 @@ module I18n
32
35
  metadata: {
33
36
  cliVersion: VERSION,
34
37
  projectName: project_name,
35
- version: "0.1"
38
+ buildFolder: './',
39
+ version: '0.1',
36
40
  }
37
41
  }
38
42
 
@@ -51,7 +55,7 @@ module I18n
51
55
 
52
56
  localization_hash = {
53
57
  strings: keys_hash,
54
- version: localization_lock_hash['metadata']['version']
58
+ version: localization_lock_hash['metadata']['version'],
55
59
  }
56
60
 
57
61
  file_content = JSON.pretty_generate(localization_hash)
@@ -81,7 +85,8 @@ module I18n
81
85
  metadata: {
82
86
  cliVersion: VERSION,
83
87
  projectName: localization_lock_hash['metadata']['projectName'],
84
- version: "#{version_split[0]}.#{version_split[1].to_i + 1}"
88
+ buildFolder: localization_lock_hash['metadata']['buildFolder'],
89
+ version: "#{version_split[0]}.#{version_split[1].to_i + 1}",
85
90
  }
86
91
  }
87
92
 
@@ -91,12 +96,40 @@ module I18n
91
96
  apply
92
97
  end
93
98
 
99
+ def build
100
+ localization_lock_hash = JSON.parse(File.open(LOCALIZATION_LOCK_FILE, &:read))
101
+
102
+ build_folder = localization_lock_hash['metadata']['buildFolder']
103
+
104
+ if !File.directory?(build_folder)
105
+ puts "Build folder '#{build_folder}' doesn't exists"
106
+ return
107
+ end
108
+
109
+ FileUtils.rm_f(Dir.glob("#{build_folder}/*"))
110
+
111
+ version = localization_lock_hash['metadata']['version']
112
+ all_languages = localization_lock_hash['data'].keys
113
+
114
+ localization_lock_hash['data'].each do |language_name, language_data|
115
+ file_path = File.join(build_folder, "#{language_name}.json")
116
+ file_content = {
117
+ strings: language_data,
118
+ allLanguages: all_languages,
119
+ version: version,
120
+ }
121
+
122
+ File.open(file_path, 'w') {|f| f.write(JSON.pretty_generate(file_content))}
123
+ end
124
+ end
125
+
94
126
  def help
95
127
  puts %(
96
128
  Commands:
97
129
  - init \t [project-name] [language-1] [language-2] ... [language-n]
98
130
  - apply \t Create localization.json file to edit localizations
99
131
  - commit \t Update .localization.lock with the localization.json updates
132
+ - build \t generate each language localization file
100
133
  )
101
134
  end
102
135
  end
@@ -1,3 +1,3 @@
1
1
  module I18n
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luciano Prestes Cavalcanti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-18 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler