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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5935fba9f02fe6b32f835ce25ce5bd32ff8d477ccfa292ffa77ffac437568cb3
4
- data.tar.gz: eedafc5365f8cf312326cf9afaeb05d5d28a1eb10c92fe780472a1b0004859f3
3
+ metadata.gz: f1a151aecd35d65f11f3bddfd9446dc2313cd4e5e9adbc1bff580f18ad0369f5
4
+ data.tar.gz: bc3e5294a08640a74d2c7db601e7cc81007b05e5e9ef7f97fc92afe82c7dc44a
5
5
  SHA512:
6
- metadata.gz: 10a5418ce724f2a5fbf289eee0056a1916fbdf1db0f2a81952525c05484fa6d70dd8a45c5c3cb5f1bd453c2001917341544d589e0f207c061ad16e426afcf2bc
7
- data.tar.gz: 59fb636dfce9eeb21a1b105100b8dac67874119651952aae124eb61afe4b486137f7e450f79b6f3834fa44bd90fc918b515c7a195c9d87967522d3d4bb4a6207
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.1.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.20.0)
15
- mime-types (~> 3.0)
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
- mime-types (3.4.1)
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.1)
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
@@ -14,7 +14,7 @@ module MissingTranslation
14
14
  File.open(FILE_NAME, 'w+') do |f|
15
15
  f.flock(File::LOCK_EX)
16
16
  f.rewind
17
- f.write({ key: nil }.to_yaml)
17
+ f.write({ key: nil, locale_prefix: true }.to_yaml)
18
18
  f.flush
19
19
  end
20
20
  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 #{directory}/#{filename}..."
61
- File.write("#{directory}/#{filename}", result.yaml)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MissingTranslation
4
- VERSION = "0.2.1"
4
+ VERSION = "0.4.0"
5
5
  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.2.1
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: 2022-11-08 00:00:00.000000000 Z
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
- - !ruby/object:Gem::Dependency
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: []