i18n-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ea830cd441b75d3ea4670ac9f9f4440ff545db6a0350b19d97effd6275054bfe
4
+ data.tar.gz: 8f28722809953be6aae84bc0572f5c465ea253aaba14954ee6bc4fb680415176
5
+ SHA512:
6
+ metadata.gz: 0eeff5b4381e3b1a593574156fe98db8e4e93e82ab7802bddcf93142954ac6e686e9ae8fb972beb7ce3f0785189504d7204ed73a41637ad21773a9c285016647
7
+ data.tar.gz: 6a208aef422e97891bc9154ad4fe842de3dd2f7741b300bcb0af613ae53d9fcf4ff87f51e515c9b662be022581533a7e1447b3a65a57d002afeda48775e78b58
data/bin/i18n ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'i18n-cli/i18n-cli'
4
+
5
+ I18n::I18n.new.run(ARGV)
@@ -0,0 +1,91 @@
1
+ require 'json'
2
+ require 'i18n-cli/version'
3
+
4
+ module I18n
5
+
6
+ LOCALIZATION_FILE = 'localization.json'
7
+ LOCALIZATION_LOCK_FILE = '.localization.lock'
8
+
9
+ class I18n
10
+
11
+ def run(argv)
12
+ command = argv[0]
13
+
14
+ case command
15
+ when 'init'
16
+ init(argv)
17
+ when 'apply'
18
+ apply
19
+ when 'commit'
20
+ commit
21
+ else
22
+ help
23
+ end
24
+ end
25
+
26
+ def init(argv)
27
+ project_name = argv[1]
28
+ languages = argv[2..-1]
29
+
30
+ localization_lock_hash = {
31
+ data: languages.each_with_object({}) {|i, hash| hash[i] = {}},
32
+ metadata: {
33
+ cliVersion: VERSION,
34
+ projectName: project_name,
35
+ version: "0.1"
36
+ }
37
+ }
38
+
39
+ file_content = JSON.pretty_generate(localization_lock_hash)
40
+ File.write(LOCALIZATION_LOCK_FILE, file_content)
41
+ end
42
+
43
+ def apply
44
+ file_content = File.open(LOCALIZATION_LOCK_FILE, &:read)
45
+ localization_lock_hash = JSON.parse(file_content)
46
+ data = localization_lock_hash['data']
47
+ languages = data.keys
48
+ localization_keys = data[languages[0]].keys
49
+
50
+ keys_hash = Hash[localization_keys.map{ |k| [k, Hash[languages.map{ |l| [l, data[l][k]] }]] }]
51
+
52
+ localization_hash = {
53
+ strings: keys_hash,
54
+ version: localization_lock_hash['metadata']['version']
55
+ }
56
+
57
+ file_content = JSON.pretty_generate(localization_hash)
58
+ File.write(LOCALIZATION_FILE, file_content)
59
+ end
60
+
61
+ def commit
62
+ localization_hash = JSON.parse(File.open(LOCALIZATION_FILE, &:read))
63
+ keys_hash = localization_hash['strings']
64
+ localization_keys = keys_hash.keys
65
+ languages = keys_hash[localization_keys[0]].keys
66
+
67
+ data = Hash[languages.map{ |l| [l, Hash[localization_keys.map{ |k| [k, keys_hash[k][l]] }]] }]
68
+
69
+ old_localization_lock_hash = JSON.parse(File.open(LOCALIZATION_LOCK_FILE, &:read))
70
+ version = old_localization_lock_hash['metadata']['version']
71
+ version_split = version.split('.')
72
+
73
+ localization_lock_hash = {
74
+ data: data,
75
+ metadata: {
76
+ cliVersion: VERSION,
77
+ projectName: old_localization_lock_hash['metadata']['projectName'],
78
+ version: "#{version_split[0]}.#{version_split[1].to_i + 1}"
79
+ }
80
+ }
81
+
82
+ file_content = JSON.pretty_generate(localization_lock_hash)
83
+ File.write(LOCALIZATION_LOCK_FILE, file_content)
84
+ end
85
+
86
+ def help
87
+ puts "Help..."
88
+ end
89
+ end
90
+
91
+ end
@@ -0,0 +1,3 @@
1
+ module I18n
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: i18n-cli
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Luciano Prestes Cavalcanti
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-05-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.4.10
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.4.10
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 13.0.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 13.0.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 3.12.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 3.12.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.14.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.14.2
69
+ description: I18n CLI is a program that manage json files tocreate localization texts
70
+ email:
71
+ - lucianopcbr@gmail.com
72
+ executables:
73
+ - i18n
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - "./lib/i18n-cli/i18n-cli.rb"
78
+ - "./lib/i18n-cli/version.rb"
79
+ - bin/i18n
80
+ homepage: https://gitlab.com/LucianoPC/i18n-cli
81
+ licenses:
82
+ - Expat
83
+ metadata: {}
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ requirements: []
99
+ rubygems_version: 3.4.10
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: A program that manage localization keys
103
+ test_files: []