missing_translation 0.2.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +5 -11
- data/README.md +5 -0
- data/lib/missing_translation/cli.rb +13 -0
- data/lib/missing_translation/configuration.rb +1 -1
- data/lib/missing_translation/translation_file.rb +7 -18
- data/lib/missing_translation/util.rb +42 -0
- data/lib/missing_translation/version.rb +1 -1
- data/lib/missing_translation/yaml_processor.rb +38 -0
- metadata +8 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1a151aecd35d65f11f3bddfd9446dc2313cd4e5e9adbc1bff580f18ad0369f5
|
4
|
+
data.tar.gz: bc3e5294a08640a74d2c7db601e7cc81007b05e5e9ef7f97fc92afe82c7dc44a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed75fa219082540942650895c32274aa05bead3250820f2363d9047f543b2875655654158fa4dc4e8cee8d6298edfea390593809e17132e9a556eb6075bfefd0
|
7
|
+
data.tar.gz: 758eab57f048daa7b974f596a8cb89f2c7e5b1bf6f8cb20107cbb88ba0f7b89afd44d932a28724cee4532ae6d721c12674be62195d3c69e5fbb4c8b5b2fce767
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
missing_translation (0.
|
4
|
+
missing_translation (0.4.0)
|
5
5
|
httparty (~> 0.18)
|
6
|
-
net-sftp (~> 3.0.0)
|
7
6
|
thor (~> 1.1)
|
8
7
|
|
9
8
|
GEM
|
@@ -11,17 +10,12 @@ GEM
|
|
11
10
|
specs:
|
12
11
|
ast (2.4.2)
|
13
12
|
diff-lcs (1.5.0)
|
14
|
-
httparty (0.
|
15
|
-
|
13
|
+
httparty (0.21.0)
|
14
|
+
mini_mime (>= 1.0.0)
|
16
15
|
multi_xml (>= 0.5.2)
|
17
16
|
json (2.6.2)
|
18
|
-
|
19
|
-
mime-types-data (~> 3.2015)
|
20
|
-
mime-types-data (3.2022.0105)
|
17
|
+
mini_mime (1.1.5)
|
21
18
|
multi_xml (0.6.0)
|
22
|
-
net-sftp (3.0.0)
|
23
|
-
net-ssh (>= 5.0.0, < 7.0.0)
|
24
|
-
net-ssh (6.1.0)
|
25
19
|
parallel (1.22.1)
|
26
20
|
parser (3.1.2.1)
|
27
21
|
ast (~> 2.4.1)
|
@@ -55,7 +49,7 @@ GEM
|
|
55
49
|
rubocop-ast (1.22.0)
|
56
50
|
parser (>= 3.1.1.0)
|
57
51
|
ruby-progressbar (1.11.0)
|
58
|
-
thor (1.2.
|
52
|
+
thor (1.2.2)
|
59
53
|
unicode-display_width (2.3.0)
|
60
54
|
|
61
55
|
PLATFORMS
|
data/README.md
CHANGED
@@ -29,6 +29,11 @@ bundle exec missing_translation upload
|
|
29
29
|
```
|
30
30
|
bundle exec missing_translation download
|
31
31
|
```
|
32
|
+
|
33
|
+
### Sort yaml files
|
34
|
+
```
|
35
|
+
bundle exec missing_translation sort
|
36
|
+
```
|
32
37
|
## Development
|
33
38
|
|
34
39
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'thor'
|
2
2
|
require 'missing_translation/configuration'
|
3
3
|
require 'missing_translation/translation_file'
|
4
|
+
require 'missing_translation/util'
|
4
5
|
require 'missing_translation_api'
|
5
6
|
|
6
7
|
module MissingTranslation
|
@@ -35,6 +36,9 @@ module MissingTranslation
|
|
35
36
|
|
36
37
|
desc "download", "Download all file from missing translation"
|
37
38
|
def download
|
39
|
+
MissingTranslation::Cli.new().sort
|
40
|
+
return if MissingTranslation::Util.uncommitted_changes?
|
41
|
+
|
38
42
|
directory = "./config/locales"
|
39
43
|
configuration = Configuration.new
|
40
44
|
api = MissingTranslationApi.new(configuration.config[:key])
|
@@ -48,6 +52,15 @@ module MissingTranslation
|
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
55
|
+
desc "sort", "Sort all yaml translations"
|
56
|
+
def sort
|
57
|
+
return if MissingTranslation::Util.uncommitted_changes?
|
58
|
+
|
59
|
+
config_folder = "./config/locales/*.yml"
|
60
|
+
MissingTranslation::Util.sort(config_folder)
|
61
|
+
MissingTranslation::Util.commit_all_changes("locale: Sort yml files")
|
62
|
+
end
|
63
|
+
|
51
64
|
end
|
52
65
|
|
53
66
|
end
|
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'yaml'
|
2
2
|
require 'psych'
|
3
|
+
require 'missing_translation/translation_file'
|
3
4
|
|
4
5
|
module MissingTranslation
|
5
6
|
class TranslationFile
|
6
|
-
attr_accessor :pathname, :content, :group, :language, :translations
|
7
|
+
attr_accessor :pathname, :content, :group, :language, :translations, :locale_prefix
|
7
8
|
|
8
9
|
def initialize(pathname = nil)
|
9
10
|
return unless pathname
|
@@ -41,24 +42,12 @@ module MissingTranslation
|
|
41
42
|
|
42
43
|
def write(directory)
|
43
44
|
return nil unless translations
|
44
|
-
|
45
|
-
result = Psych.parse_stream translations.to_yaml
|
46
|
-
result.grep(Psych::Nodes::Scalar).each do |node|
|
47
|
-
node.plain = false
|
48
|
-
node.quoted = true
|
49
|
-
node.style = Psych::Nodes::Scalar::DOUBLE_QUOTED
|
50
|
-
end
|
51
|
-
result.grep(Psych::Nodes::Mapping).each do |node|
|
52
|
-
node.children.each_slice(2) do |k, _|
|
53
|
-
k.plain = true
|
54
|
-
k.quoted = false
|
55
|
-
k.style = Psych::Nodes::Scalar::ANY
|
56
|
-
end
|
57
|
-
end
|
58
45
|
filename = [group, language, "yml"].compact.reject{|s| s.size <= 0}.join('.')
|
59
|
-
|
60
|
-
p "Writing file #{
|
61
|
-
|
46
|
+
filepath = "#{directory}/#{filename}"
|
47
|
+
p "Writing file #{filepath}..."
|
48
|
+
|
49
|
+
File.write(filepath, translations.to_yaml)
|
50
|
+
MissingTranslation::Util.sort_file(filepath)
|
62
51
|
end
|
63
52
|
|
64
53
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'missing_translation/yaml_processor'
|
3
|
+
|
4
|
+
module MissingTranslation
|
5
|
+
class Util
|
6
|
+
|
7
|
+
def self.uncommitted_changes?
|
8
|
+
status = `git status --porcelain`
|
9
|
+
return false if $CHILD_STATUS.success? && status.empty?
|
10
|
+
|
11
|
+
error = if $CHILD_STATUS.success?
|
12
|
+
"You have uncommitted code. Please commit or stash your changes before continuing"
|
13
|
+
else
|
14
|
+
"You do not have Git installed. Please install Git, and commit your changes before continuing"
|
15
|
+
end
|
16
|
+
p error
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.commit_all_changes(message)
|
21
|
+
status = `git add .`
|
22
|
+
status = system "git commit -m \"#{message}\""
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.sort_file(filepath)
|
26
|
+
content = YAML.load_file(filepath)
|
27
|
+
hash = MissingTranslation::YamlProcessor.denormalize_translations_hash(content)
|
28
|
+
translations = MissingTranslation::YamlProcessor.normalize_translations_hash(hash)
|
29
|
+
|
30
|
+
File.write(filepath, translations.to_yaml)
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.sort(file_pattern = "./config/locales/#{file_extension}/*.yml")
|
34
|
+
file_pathnames = Dir[file_pattern]
|
35
|
+
return unless file_pathnames && file_pathnames.size > 0
|
36
|
+
|
37
|
+
file_pathnames.each do |filepath|
|
38
|
+
sort_file(filepath)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
module MissingTranslation
|
3
|
+
class YamlProcessor
|
4
|
+
def self.denormalize_translations_hash(translations, parent_key='')
|
5
|
+
ans = {}
|
6
|
+
translations.each do |key, val|
|
7
|
+
if val.is_a? Hash
|
8
|
+
aux = denormalize_translations_hash(val, "#{parent_key}#{key}.")
|
9
|
+
aux.each do |k, v|
|
10
|
+
ans[k] = v
|
11
|
+
end
|
12
|
+
else
|
13
|
+
ans["#{parent_key}#{key}"] = val
|
14
|
+
end
|
15
|
+
end
|
16
|
+
ans
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.dig_set(obj, keys, value)
|
20
|
+
key = keys.first
|
21
|
+
if keys.length == 1
|
22
|
+
obj[key] = value
|
23
|
+
else
|
24
|
+
obj[key] = {} unless obj[key]
|
25
|
+
dig_set(obj[key], keys.slice(1..-1), value)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.normalize_translations_hash(hash)
|
30
|
+
result = {}
|
31
|
+
hash.keys.sort.each do |key|
|
32
|
+
dig_set(result, key.split("."), hash[key])
|
33
|
+
end
|
34
|
+
result
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: missing_translation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Clercin
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -38,21 +38,7 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.18'
|
41
|
-
|
42
|
-
name: net-sftp
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.0.0
|
55
|
-
description:
|
41
|
+
description:
|
56
42
|
email:
|
57
43
|
- kevin@9troisquarts.com
|
58
44
|
executables:
|
@@ -74,7 +60,9 @@ files:
|
|
74
60
|
- lib/missing_translation/cli.rb
|
75
61
|
- lib/missing_translation/configuration.rb
|
76
62
|
- lib/missing_translation/translation_file.rb
|
63
|
+
- lib/missing_translation/util.rb
|
77
64
|
- lib/missing_translation/version.rb
|
65
|
+
- lib/missing_translation/yaml_processor.rb
|
78
66
|
- lib/missing_translation_api.rb
|
79
67
|
- sig/missing_translation.rbs
|
80
68
|
homepage: https://github.com/9troisquarts/missing_translation
|
@@ -84,7 +72,7 @@ metadata:
|
|
84
72
|
homepage_uri: https://github.com/9troisquarts/missing_translation
|
85
73
|
source_code_uri: https://github.com/9troisquarts/missing_translation
|
86
74
|
changelog_uri: https://github.com/9troisquarts/missing_translation/CHANGELOG.md
|
87
|
-
post_install_message:
|
75
|
+
post_install_message:
|
88
76
|
rdoc_options: []
|
89
77
|
require_paths:
|
90
78
|
- lib
|
@@ -100,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
88
|
version: '0'
|
101
89
|
requirements: []
|
102
90
|
rubygems_version: 3.3.7
|
103
|
-
signing_key:
|
91
|
+
signing_key:
|
104
92
|
specification_version: 4
|
105
93
|
summary: Upload and download your I18n to missing translation
|
106
94
|
test_files: []
|