web_translate_it 2.7.0 → 2.7.2
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 +4 -4
- data/history.md +9 -0
- data/lib/web_translate_it/command_line.rb +0 -3
- data/lib/web_translate_it/configuration.rb +33 -33
- data/lib/web_translate_it/connection.rb +1 -7
- data/lib/web_translate_it/project.rb +1 -2
- data/lib/web_translate_it/string.rb +0 -2
- data/lib/web_translate_it/term.rb +0 -3
- data/lib/web_translate_it/term_translation.rb +0 -3
- data/lib/web_translate_it/translation.rb +0 -3
- data/lib/web_translate_it/translation_file.rb +7 -15
- data/lib/web_translate_it/util.rb +0 -2
- data/lib/web_translate_it.rb +12 -2
- data/readme.md +7 -3
- metadata +5 -5
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c59f3a4a6ea7997d54567b00007c0606e07b250473678f2fc2a14bf2b73c8cc8
         | 
| 4 | 
            +
              data.tar.gz: 3dd474c5c9e05312122fcd6817478068f11bb5ea4e4fadb743a57b4ca8f24a83
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 69b6977f8438f0364261334b1cd1b0b26181b084113dbdd5573d95fe52f33f09a1c0043b7fcaf0f51ff28b8aa5c5728f275bd25726078611a825a6700784fd2a
         | 
| 7 | 
            +
              data.tar.gz: 4b687e74044b6884b3ee13c83e9eafb26d1aee6991d183882d5bfeaa0ae94930003f21db598d78469f910e491d0b16954949b037343e24052a6f78af50a3c859
         | 
    
        data/history.md
    CHANGED
    
    | @@ -1,3 +1,12 @@ | |
| 1 | 
            +
            ## Version 2.7.2 / 2022-10-14
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            * Specify a minimum version for dependency `multipart_post`.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            ## Version 2.7.1 / 2022-10-14
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            * Potential fix potential for issue `uninitialized constant WebTranslateIt::TranslationFile::Multipart`.
         | 
| 8 | 
            +
            * Code refactoring.
         | 
| 9 | 
            +
             | 
| 1 10 | 
             
            ## Version 2.7.0 / 2022-10-10
         | 
| 2 11 |  | 
| 3 12 | 
             
            * New: Ability to see translation statistics per file.
         | 
| @@ -2,8 +2,6 @@ module WebTranslateIt | |
| 2 2 |  | 
| 3 3 | 
             
              class CommandLine # rubocop:todo Metrics/ClassLength
         | 
| 4 4 |  | 
| 5 | 
            -
                require 'fileutils'
         | 
| 6 | 
            -
                require 'set'
         | 
| 7 5 | 
             
                attr_accessor :configuration, :global_options, :command_options, :parameters
         | 
| 8 6 |  | 
| 9 7 | 
             
                def initialize(command, command_options, _global_options, parameters, project_path) # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength
         | 
| @@ -418,7 +416,6 @@ module WebTranslateIt | |
| 418 416 | 
             
                  puts 'Warning: `config/translation.yml` is deprecated in favour of a `.wti` file.'
         | 
| 419 417 | 
             
                  return 'config/translation.yml' unless Util.ask_yes_no('Would you like to migrate your configuration now?', true)
         | 
| 420 418 |  | 
| 421 | 
            -
                  require 'fileutils'
         | 
| 422 419 | 
             
                  return '.wti' if FileUtils.mv('config/translation.yml', '.wti')
         | 
| 423 420 |  | 
| 424 421 | 
             
                  puts 'Couldn’t move `config/translation.yml`.'
         | 
| @@ -8,9 +8,6 @@ module WebTranslateIt | |
| 8 8 | 
             
              #
         | 
| 9 9 | 
             
              class Configuration
         | 
| 10 10 |  | 
| 11 | 
            -
                require 'yaml'
         | 
| 12 | 
            -
                require 'fileutils'
         | 
| 13 | 
            -
                require 'erb'
         | 
| 14 11 | 
             
                attr_accessor :path, :api_key, :source_locale, :target_locales, :files, :ignore_locales, :needed_locales, :logger, :before_pull, :after_pull, :before_push, :after_push, :project_name, :path_to_config_file, :ignore_files
         | 
| 15 12 |  | 
| 16 13 | 
             
                # Load configuration file from the path.
         | 
| @@ -30,10 +27,11 @@ module WebTranslateIt | |
| 30 27 | 
             
                    else
         | 
| 31 28 | 
             
                      YAML.load WebTranslateIt::Project.fetch_info(api_key)
         | 
| 32 29 | 
             
                    end
         | 
| 33 | 
            -
                     | 
| 34 | 
            -
                     | 
| 35 | 
            -
                     | 
| 36 | 
            -
                     | 
| 30 | 
            +
                    self.ignore_locales = locales_to_ignore(configuration)
         | 
| 31 | 
            +
                    self.needed_locales = locales_needed(configuration)
         | 
| 32 | 
            +
                    self.files = files_from_project(project_info['project'])
         | 
| 33 | 
            +
                    self.source_locale = source_locale_from_project(project_info['project'])
         | 
| 34 | 
            +
                    self.target_locales = target_locales_from_project(project_info['project'])
         | 
| 37 35 | 
             
                    self.project_name = project_info['project']['name']
         | 
| 38 36 | 
             
                  else
         | 
| 39 37 | 
             
                    puts StringUtil.failure("\nNo configuration file found in #{File.expand_path(path_to_config_file, path)}")
         | 
| @@ -43,23 +41,24 @@ module WebTranslateIt | |
| 43 41 |  | 
| 44 42 | 
             
                # Reload project data
         | 
| 45 43 | 
             
                #
         | 
| 46 | 
            -
                def reload
         | 
| 44 | 
            +
                def reload # rubocop:todo Metrics/AbcSize
         | 
| 47 45 | 
             
                  project_info = YAML.load WebTranslateIt::Project.fetch_info(api_key)
         | 
| 48 | 
            -
                   | 
| 49 | 
            -
                   | 
| 50 | 
            -
                   | 
| 51 | 
            -
                   | 
| 46 | 
            +
                  self.ignore_locales = locales_to_ignore(configuration)
         | 
| 47 | 
            +
                  self.needed_locales = locales_needed(configuration)
         | 
| 48 | 
            +
                  self.files = files_from_project(project_info['project'])
         | 
| 49 | 
            +
                  self.source_locale = source_locale_from_project(project_info['project'])
         | 
| 50 | 
            +
                  self.target_locales = target_locales_from_project(project_info['project'])
         | 
| 52 51 | 
             
                  self.project_name = project_info['project']['name']
         | 
| 53 52 | 
             
                end
         | 
| 54 53 |  | 
| 55 | 
            -
                #  | 
| 56 | 
            -
                 | 
| 57 | 
            -
             | 
| 58 | 
            -
                 | 
| 59 | 
            -
             | 
| 60 | 
            -
                 | 
| 61 | 
            -
             | 
| 62 | 
            -
                   | 
| 54 | 
            +
                # Returns the source locale from the Project API.
         | 
| 55 | 
            +
                def source_locale_from_project(project)
         | 
| 56 | 
            +
                  project['source_locale']['code']
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                # Returns the target locales from the Project API.
         | 
| 60 | 
            +
                def target_locales_from_project(project)
         | 
| 61 | 
            +
                  project['target_locales'].map { |locale| locale['code'] }
         | 
| 63 62 | 
             
                end
         | 
| 64 63 |  | 
| 65 64 | 
             
                # Set the project files from the Project API.
         | 
| @@ -67,33 +66,34 @@ module WebTranslateIt | |
| 67 66 | 
             
                #
         | 
| 68 67 | 
             
                #   configuration = WebTranslateIt::Configuration.new
         | 
| 69 68 | 
             
                #   files = configuration.files # returns an array of TranslationFile
         | 
| 70 | 
            -
                def  | 
| 71 | 
            -
                   | 
| 69 | 
            +
                def files_from_project(project) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
         | 
| 70 | 
            +
                  array_files = []
         | 
| 72 71 | 
             
                  project['project_files'].each do |project_file|
         | 
| 73 72 | 
             
                    if project_file['name'].nil? || (project_file['name'].strip == '')
         | 
| 74 73 | 
             
                      puts "File #{project_file['id']} not set up"
         | 
| 75 74 | 
             
                    elsif ignore_files&.any? { |glob| File.fnmatch(glob, project_file['name']) }
         | 
| 76 75 | 
             
                      puts "Ignoring #{project_file['name']}"
         | 
| 77 76 | 
             
                    else
         | 
| 78 | 
            -
                       | 
| 77 | 
            +
                      array_files.push TranslationFile.new(project_file['id'], project_file['name'], project_file['locale_code'], api_key, project_file['updated_at'], project_file['hash_file'], project_file['master_project_file_id'], project_file['fresh'])
         | 
| 79 78 | 
             
                    end
         | 
| 80 79 | 
             
                  end
         | 
| 80 | 
            +
                  array_files
         | 
| 81 81 | 
             
                end
         | 
| 82 82 |  | 
| 83 | 
            -
                #  | 
| 84 | 
            -
                def  | 
| 85 | 
            -
                   | 
| 83 | 
            +
                # Returns an array of locales to ignore from the configuration file, if set.
         | 
| 84 | 
            +
                def locales_to_ignore(configuration)
         | 
| 85 | 
            +
                  Array(configuration['ignore_locales']).map(&:to_s)
         | 
| 86 86 | 
             
                end
         | 
| 87 87 |  | 
| 88 | 
            -
                #  | 
| 89 | 
            -
                def  | 
| 90 | 
            -
                   | 
| 88 | 
            +
                # Returns an array of locales to specifically pull from the configuration file, if set
         | 
| 89 | 
            +
                def locales_needed(configuration)
         | 
| 90 | 
            +
                  Array(configuration['needed_locales']).map(&:to_s)
         | 
| 91 91 | 
             
                end
         | 
| 92 92 |  | 
| 93 | 
            -
                # Set files to ignore from the configuration file, if set.
         | 
| 94 | 
            -
                def  | 
| 95 | 
            -
             | 
| 96 | 
            -
                end
         | 
| 93 | 
            +
                # # Set files to ignore from the configuration file, if set.
         | 
| 94 | 
            +
                # def ignore_files(configuration)
         | 
| 95 | 
            +
                #   Array(configuration['ignore_files']).map(&:to_s)
         | 
| 96 | 
            +
                # end
         | 
| 97 97 |  | 
| 98 98 | 
             
                # Convenience method which returns the endpoint for fetching a list of locales for a project.
         | 
| 99 99 | 
             
                def api_url
         | 
| @@ -1,15 +1,9 @@ | |
| 1 | 
            -
            require 'English'
         | 
| 2 1 | 
             
            module WebTranslateIt
         | 
| 3 2 |  | 
| 4 3 | 
             
              class Connection
         | 
| 5 4 |  | 
| 6 5 | 
             
                attr_reader :api_key, :http_connection
         | 
| 7 6 |  | 
| 8 | 
            -
                require 'net/http'
         | 
| 9 | 
            -
                require 'net/https'
         | 
| 10 | 
            -
                require 'openssl'
         | 
| 11 | 
            -
                require 'uri'
         | 
| 12 | 
            -
             | 
| 13 7 | 
             
                @api_key = nil
         | 
| 14 8 | 
             
                @http_connection = nil
         | 
| 15 9 | 
             
                @debug = false
         | 
| @@ -49,7 +43,7 @@ module WebTranslateIt | |
| 49 43 | 
             
                    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
         | 
| 50 44 | 
             
                    @http_connection = http.start
         | 
| 51 45 | 
             
                    yield @http_connection if block_given?
         | 
| 52 | 
            -
                  rescue
         | 
| 46 | 
            +
                  rescue StandardError
         | 
| 53 47 | 
             
                    puts $ERROR_INFO
         | 
| 54 48 | 
             
                  end
         | 
| 55 49 | 
             
                end
         | 
| @@ -8,11 +8,6 @@ module WebTranslateIt | |
| 8 8 | 
             
              # manipulate a _target_ language file.
         | 
| 9 9 | 
             
              class TranslationFile # rubocop:todo Metrics/ClassLength
         | 
| 10 10 |  | 
| 11 | 
            -
                require 'net/https'
         | 
| 12 | 
            -
                require 'net/http/post/multipart'
         | 
| 13 | 
            -
                require 'time'
         | 
| 14 | 
            -
                require 'fileutils'
         | 
| 15 | 
            -
             | 
| 16 11 | 
             
                attr_accessor :id, :file_path, :locale, :api_key, :updated_at, :remote_checksum, :master_id, :fresh
         | 
| 17 12 |  | 
| 18 13 | 
             
                def initialize(id, file_path, locale, api_key, updated_at = nil, remote_checksum = '', master_id = nil, fresh = nil) # rubocop:todo Metrics/ParameterLists
         | 
| @@ -65,7 +60,7 @@ module WebTranslateIt | |
| 65 60 | 
             
                        else
         | 
| 66 61 | 
             
                          success = false
         | 
| 67 62 | 
             
                        end
         | 
| 68 | 
            -
                      rescue
         | 
| 63 | 
            +
                      rescue StandardError
         | 
| 69 64 | 
             
                        display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
         | 
| 70 65 | 
             
                        success = false
         | 
| 71 66 | 
             
                      end
         | 
| @@ -115,7 +110,7 @@ module WebTranslateIt | |
| 115 110 | 
             
                        else
         | 
| 116 111 | 
             
                          success = false
         | 
| 117 112 | 
             
                        end
         | 
| 118 | 
            -
                      rescue
         | 
| 113 | 
            +
                      rescue StandardError
         | 
| 119 114 | 
             
                        display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
         | 
| 120 115 | 
             
                        success = false
         | 
| 121 116 | 
             
                      end
         | 
| @@ -164,7 +159,7 @@ module WebTranslateIt | |
| 164 159 | 
             
                      else
         | 
| 165 160 | 
             
                        success = false
         | 
| 166 161 | 
             
                      end
         | 
| 167 | 
            -
                    rescue
         | 
| 162 | 
            +
                    rescue StandardError
         | 
| 168 163 | 
             
                      display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
         | 
| 169 164 | 
             
                      success = false
         | 
| 170 165 | 
             
                    end
         | 
| @@ -195,7 +190,7 @@ module WebTranslateIt | |
| 195 190 | 
             
                      else
         | 
| 196 191 | 
             
                        success = false
         | 
| 197 192 | 
             
                      end
         | 
| 198 | 
            -
                    rescue
         | 
| 193 | 
            +
                    rescue StandardError
         | 
| 199 194 | 
             
                      display.push StringUtil.failure("An error occured: #{$ERROR_INFO}")
         | 
| 200 195 | 
             
                      success = false
         | 
| 201 196 | 
             
                    end
         | 
| @@ -234,12 +229,9 @@ module WebTranslateIt | |
| 234 229 | 
             
                end
         | 
| 235 230 |  | 
| 236 231 | 
             
                def local_checksum
         | 
| 237 | 
            -
                   | 
| 238 | 
            -
             | 
| 239 | 
            -
             | 
| 240 | 
            -
                  rescue
         | 
| 241 | 
            -
                    ''
         | 
| 242 | 
            -
                  end
         | 
| 232 | 
            +
                  Digest::SHA1.hexdigest(File.read(file_path))
         | 
| 233 | 
            +
                rescue StandardError
         | 
| 234 | 
            +
                  ''
         | 
| 243 235 | 
             
                end
         | 
| 244 236 |  | 
| 245 237 | 
             
              end
         | 
    
        data/lib/web_translate_it.rb
    CHANGED
    
    | @@ -1,3 +1,15 @@ | |
| 1 | 
            +
            require 'fileutils'
         | 
| 2 | 
            +
            require 'yaml'
         | 
| 3 | 
            +
            require 'erb'
         | 
| 4 | 
            +
            require 'net/http'
         | 
| 5 | 
            +
            require 'net/https'
         | 
| 6 | 
            +
            require 'net/http/post/multipart'
         | 
| 7 | 
            +
            require 'openssl'
         | 
| 8 | 
            +
            require 'uri'
         | 
| 9 | 
            +
            require 'multi_json'
         | 
| 10 | 
            +
            require 'digest/sha1'
         | 
| 11 | 
            +
            require 'English'
         | 
| 12 | 
            +
             | 
| 1 13 | 
             
            require 'web_translate_it/connection'
         | 
| 2 14 | 
             
            require 'web_translate_it/util'
         | 
| 3 15 | 
             
            require 'web_translate_it/util/array_util'
         | 
| @@ -13,8 +25,6 @@ require 'web_translate_it/auto_fetch' | |
| 13 25 | 
             
            require 'web_translate_it/command_line'
         | 
| 14 26 | 
             
            require 'web_translate_it/project'
         | 
| 15 27 |  | 
| 16 | 
            -
            require 'English'
         | 
| 17 | 
            -
             | 
| 18 28 | 
             
            module WebTranslateIt
         | 
| 19 29 |  | 
| 20 30 | 
             
              def self.fetch_translations # rubocop:todo Metrics/AbcSize
         | 
    
        data/readme.md
    CHANGED
    
    | @@ -187,7 +187,11 @@ Append `--help` for each command for more information. For instance: | |
| 187 187 | 
             
              </tr>
         | 
| 188 188 | 
             
              <tr>
         | 
| 189 189 | 
             
                <td>wti status</td>
         | 
| 190 | 
            -
                <td>View project statistics</td>
         | 
| 190 | 
            +
                <td>View project translation statistics</td>
         | 
| 191 | 
            +
              </tr>
         | 
| 192 | 
            +
              <tr>
         | 
| 193 | 
            +
                <td>wti status config/locales/app/en.yml</td>
         | 
| 194 | 
            +
                <td>View translation statistics on file config/locales/app/en.yml</td>
         | 
| 191 195 | 
             
              </tr>
         | 
| 192 196 | 
             
              <tr>
         | 
| 193 197 | 
             
                <td>wti match</td>
         | 
| @@ -210,7 +214,7 @@ Check the [sample `.wti`](https://github.com/webtranslateit/webtranslateit/blob/ | |
| 210 214 |  | 
| 211 215 | 
             
            ## Exit codes
         | 
| 212 216 |  | 
| 213 | 
            -
             | 
| 217 | 
            +
            `wti` returns exit codes on failure. The exit code is `0` if the command executed successfully and `1` if the command executed but encountered at least one error. This is useful to act upon errors if you use `wti` to pull files in an automated build process.
         | 
| 214 218 |  | 
| 215 219 | 
             
            ``` zsh
         | 
| 216 220 | 
             
            ~/code/webtranslateit.com[master]% wti pull
         | 
| @@ -239,7 +243,7 @@ Pulled 3 files at 3 files/sec, using 3 threads. | |
| 239 243 | 
             
            1
         | 
| 240 244 | 
             
            ```
         | 
| 241 245 |  | 
| 242 | 
            -
             | 
| 246 | 
            +
            `wti status` command also returns meaningful codes. It will exit with `0` if the project is 100% translated and proofread, `100` if the project is not 100% translated and `101` if the project is not 100% proofread. This could allow you to check if a project is 100% translated or completed before deploying a project.
         | 
| 243 247 |  | 
| 244 248 | 
             
            ``` zsh
         | 
| 245 249 | 
             
            ~/Desktop/test% wti status
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: web_translate_it
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.7. | 
| 4 | 
            +
              version: 2.7.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Edouard Briere
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2022-10- | 
| 11 | 
            +
            date: 2022-10-14 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: multi_json
         | 
| @@ -30,14 +30,14 @@ dependencies: | |
| 30 30 | 
             
                requirements:
         | 
| 31 31 | 
             
                - - "~>"
         | 
| 32 32 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 | 
            -
                    version: '2. | 
| 33 | 
            +
                    version: '2.2'
         | 
| 34 34 | 
             
              type: :runtime
         | 
| 35 35 | 
             
              prerelease: false
         | 
| 36 36 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 37 | 
             
                requirements:
         | 
| 38 38 | 
             
                - - "~>"
         | 
| 39 39 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 | 
            -
                    version: '2. | 
| 40 | 
            +
                    version: '2.2'
         | 
| 41 41 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 42 42 | 
             
              name: optimist
         | 
| 43 43 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 114 114 | 
             
                - !ruby/object:Gem::Version
         | 
| 115 115 | 
             
                  version: '0'
         | 
| 116 116 | 
             
            requirements: []
         | 
| 117 | 
            -
            rubygems_version: 3.3. | 
| 117 | 
            +
            rubygems_version: 3.3.23
         | 
| 118 118 | 
             
            signing_key:
         | 
| 119 119 | 
             
            specification_version: 4
         | 
| 120 120 | 
             
            summary: A CLI tool to sync locale files with WebTranslateIt.com.
         |