phraseapp_updater 3.3.0 → 3.3.1
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/lib/phraseapp_updater/phraseapp_api.rb +42 -18
- data/lib/phraseapp_updater/version.rb +1 -1
- metadata +16 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 5d137755330d9711327e6731a7b4ae1fc701ec705ce719055bca7479dcd3579a
         | 
| 4 | 
            +
              data.tar.gz: ab2839920b873ed264759eadf926d6b9df837b511b163f1f18e4ef777bcfc820
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: afe9e8266f248e39c52095a762a64a9e1823bf94f825a4cbe7d166946892cd1c171252d2218b3dce0c47c6dd6e4cfe224c826a5ffea812d8f3011f07991c5034
         | 
| 7 | 
            +
              data.tar.gz: ba81fe027f6016fc759e72b5cf27c88e1c31ca7e08e1580dd4c5b110ecaa83dcd6f603ec686978b21071fbb5bc9e02e5967e32a1a102612a5a16448094c3158a
         | 
| @@ -4,6 +4,7 @@ require 'phraseapp_updater/locale_file' | |
| 4 4 | 
             
            require 'phraseapp_updater/index_by'
         | 
| 5 5 | 
             
            require 'uri'
         | 
| 6 6 | 
             
            require 'phrase'
         | 
| 7 | 
            +
            require 'concurrent'
         | 
| 7 8 | 
             
            require 'parallel'
         | 
| 8 9 | 
             
            require 'tempfile'
         | 
| 9 10 |  | 
| @@ -96,38 +97,60 @@ class PhraseAppUpdater | |
| 96 97 | 
             
                  end
         | 
| 97 98 | 
             
                end
         | 
| 98 99 |  | 
| 99 | 
            -
                # Empirically, PhraseApp fails to parse the uploaded files when uploaded in
         | 
| 100 | 
            -
                # parallel. Give it a better chance by uploading them one at a time.
         | 
| 101 100 | 
             
                def upload_files(locale_files, default_locale:)
         | 
| 102 | 
            -
                   | 
| 101 | 
            +
                  locale_files = locale_files.sort_by(&:locale_name)
         | 
| 102 | 
            +
                  default_locale_file = locale_files.detect { |l| l.locale_name == default_locale }
         | 
| 103 | 
            +
                  locale_files.delete(default_locale_file) if default_locale_file
         | 
| 103 104 |  | 
| 104 | 
            -
                  # Ensure the locales all exist
         | 
| 105 | 
            -
                  STDERR.puts('Creating locales')
         | 
| 106 105 | 
             
                  known_locales = fetch_locales.index_by(&:name)
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                  # Phraseapp appears to use to use the first file uploaded to resolve conflicts
         | 
| 108 | 
            +
                  # between pluralized and non-pluralized keys. Upload and verify the canonical
         | 
| 109 | 
            +
                  # default locale first before uploading translated locales.
         | 
| 110 | 
            +
                  if default_locale_file
         | 
| 111 | 
            +
                    unless known_locales.has_key?(default_locale_file.locale_name)
         | 
| 112 | 
            +
                      STDERR.puts("Creating default locale (#{default_locale_file})")
         | 
| 113 | 
            +
                      create_locale(default_locale_file.locale_name, default: true)
         | 
| 114 | 
            +
                    end
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                    STDERR.puts("Uploading default locale (#{default_locale_file})")
         | 
| 117 | 
            +
                    upload_id = upload_file(default_locale_file)
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                    successful_default_upload = verify_uploads({ upload_id => default_locale_file })
         | 
| 120 | 
            +
                  else
         | 
| 121 | 
            +
                    STDERR.puts("No upload for default locale (#{default_locale})")
         | 
| 122 | 
            +
                  end
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                  # Ensure the locales all exist
         | 
| 125 | 
            +
                  STDERR.puts('Creating translation locales')
         | 
| 107 126 | 
             
                  threaded_request(locale_files) do |locale_file|
         | 
| 108 127 | 
             
                    unless known_locales.has_key?(locale_file.locale_name)
         | 
| 109 | 
            -
                      create_locale(locale_file.locale_name, default:  | 
| 128 | 
            +
                      create_locale(locale_file.locale_name, default: false)
         | 
| 110 129 | 
             
                    end
         | 
| 111 130 | 
             
                  end
         | 
| 112 131 |  | 
| 113 | 
            -
                   | 
| 114 | 
            -
                  locale_files.sort! do |a, b|
         | 
| 115 | 
            -
                    next -1 if is_default.(a)
         | 
| 116 | 
            -
                    next 1  if is_default.(b)
         | 
| 132 | 
            +
                  uploads = Concurrent::Hash.new
         | 
| 117 133 |  | 
| 118 | 
            -
             | 
| 134 | 
            +
                  threaded_request(locale_files) do |locale_file|
         | 
| 135 | 
            +
                    STDERR.puts("Uploading #{locale_file}")
         | 
| 136 | 
            +
                    upload_id = upload_file(locale_file)
         | 
| 137 | 
            +
                    uploads[upload_id] = locale_file
         | 
| 119 138 | 
             
                  end
         | 
| 120 139 |  | 
| 121 | 
            -
                   | 
| 140 | 
            +
                  successful_uploads = verify_uploads(uploads)
         | 
| 122 141 |  | 
| 123 | 
            -
                   | 
| 124 | 
            -
                     | 
| 125 | 
            -
                    upload_id = upload_file(locale_file)
         | 
| 126 | 
            -
                    [upload_id, locale_file]
         | 
| 142 | 
            +
                  if default_locale_file
         | 
| 143 | 
            +
                    successful_uploads = successful_uploads.merge(successful_default_upload)
         | 
| 127 144 | 
             
                  end
         | 
| 128 145 |  | 
| 129 | 
            -
                   | 
| 130 | 
            -
             | 
| 146 | 
            +
                  successful_uploads
         | 
| 147 | 
            +
                end
         | 
| 148 | 
            +
             | 
| 149 | 
            +
                # Given a map of {upload_id => locale_file} pairs, use the upload_show
         | 
| 150 | 
            +
                # API to verify that they're complete, and re-upload them if they failed.
         | 
| 151 | 
            +
                # Return a map of locale name to upload id.
         | 
| 152 | 
            +
                def verify_uploads(uploads)
         | 
| 153 | 
            +
                  successful_upload_ids = Concurrent::Hash.new
         | 
| 131 154 |  | 
| 132 155 | 
             
                  STDERR.puts('Verifying uploads...')
         | 
| 133 156 | 
             
                  until uploads.empty?
         | 
| @@ -157,6 +180,7 @@ class PhraseAppUpdater | |
| 157 180 | 
             
                  successful_upload_ids
         | 
| 158 181 | 
             
                end
         | 
| 159 182 |  | 
| 183 | 
            +
             | 
| 160 184 | 
             
                def remove_keys_not_in_uploads(upload_ids)
         | 
| 161 185 | 
             
                  threaded_request(upload_ids) do |upload_id|
         | 
| 162 186 | 
             
                    STDERR.puts "Removing keys not in upload #{upload_id}"
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: phraseapp_updater
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 3.3. | 
| 4 | 
            +
              version: 3.3.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - iKnow Team
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2024- | 
| 11 | 
            +
            date: 2024-10-01 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: thor
         | 
| @@ -94,6 +94,20 @@ dependencies: | |
| 94 94 | 
             
                - - "~>"
         | 
| 95 95 | 
             
                  - !ruby/object:Gem::Version
         | 
| 96 96 | 
             
                    version: '1.23'
         | 
| 97 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 98 | 
            +
              name: concurrent-ruby
         | 
| 99 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 100 | 
            +
                requirements:
         | 
| 101 | 
            +
                - - "~>"
         | 
| 102 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 103 | 
            +
                    version: 1.0.2
         | 
| 104 | 
            +
              type: :runtime
         | 
| 105 | 
            +
              prerelease: false
         | 
| 106 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 107 | 
            +
                requirements:
         | 
| 108 | 
            +
                - - "~>"
         | 
| 109 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 110 | 
            +
                    version: 1.0.2
         | 
| 97 111 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 98 112 | 
             
              name: bundler
         | 
| 99 113 | 
             
              requirement: !ruby/object:Gem::Requirement
         |