missing_translation 0.2.1 → 0.3.0
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 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: a13074eb2d7b2c22ace7a15de282c480769412b37eebb599d914ad1f963b4177
         | 
| 4 | 
            +
              data.tar.gz: 481a55cb94f2f837b9bb5aa32f2b3ea41b91e67bb7d5ba6d7d423cbd566a2a27
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d208bce285cfab32f9435c2305fae703ce8afff13d7382166b197c28b299f6d2600ff0d2c504ae5d506aee8278e0f6d41bd5d74094e214baa4e01c01cf398975
         | 
| 7 | 
            +
              data.tar.gz: 1b441d38d2d51ae804999bf24b19f825bd9fd3b53badd2a11ad601c3dd5591c467f40e967c818919634773929099eefb6cf04db523b14ff7352d64b8684d370a
         | 
| @@ -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,5 +1,6 @@ | |
| 1 1 | 
             
            require 'yaml'
         | 
| 2 2 | 
             
            require 'psych'
         | 
| 3 | 
            +
            require 'missing_translation/translation_file'
         | 
| 3 4 |  | 
| 4 5 | 
             
            module MissingTranslation
         | 
| 5 6 | 
             
              class TranslationFile
         | 
| @@ -41,24 +42,11 @@ 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 | 
            -
                  File.write( | 
| 46 | 
            +
                  filepath = "#{directory}/#{filename}"
         | 
| 47 | 
            +
                  p "Writing file #{filepath}..."
         | 
| 48 | 
            +
                  File.write(filepath, translations.to_yaml)
         | 
| 49 | 
            +
                  MissingTranslation::Util.sort_file(filepath)
         | 
| 62 50 | 
             
                end
         | 
| 63 51 |  | 
| 64 52 | 
             
              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.3.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Kevin Clercin
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date:  | 
| 11 | 
            +
            date: 2023-01-13 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         | 
| @@ -74,7 +74,9 @@ files: | |
| 74 74 | 
             
            - lib/missing_translation/cli.rb
         | 
| 75 75 | 
             
            - lib/missing_translation/configuration.rb
         | 
| 76 76 | 
             
            - lib/missing_translation/translation_file.rb
         | 
| 77 | 
            +
            - lib/missing_translation/util.rb
         | 
| 77 78 | 
             
            - lib/missing_translation/version.rb
         | 
| 79 | 
            +
            - lib/missing_translation/yaml_processor.rb
         | 
| 78 80 | 
             
            - lib/missing_translation_api.rb
         | 
| 79 81 | 
             
            - sig/missing_translation.rbs
         | 
| 80 82 | 
             
            homepage: https://github.com/9troisquarts/missing_translation
         |