- Strengthen config options
- Various code updates and enhancements
- Test with Ruby 4
- Relaxed rubyzip dependency, allow rubyzip v3
- Test with Ruby 3.5
- Added a new export option
export_filename_generator (lambda or proc) that allows to control the filename sent to Lokalise for each uploaded file. The lambda takes two arguments: full file path and relative path (both Pathname instances). The relative path is calculated based on your locales_path setting — it shows the file's location inside your locales folder. The lambda must return a string or Pathname (or anything convertible to string) with the desired filename. By default, the relative path is used as the filename.
c.export_filename_generator = ->(_full_path, relative_path) { relative_path.to_s.upcase }
- Added a new export option
export_preprocessor (lambda or proc) that enables you to specify additional processing logic for your translation files' content before uploading to Lokalise. This option defaults to ->(raw_data, _path) { raw_data } (no processing).
c.export_preprocessor = ->(raw_data, _path) { raw_data.upcase }
- Strengthened configuration merging logic for
import_opts and export_opts to retain default values when overridden.
- Prevent error swallowing in rare cases
- Added support for
import_async option (default to false). When enabled, the import process will happen in the background and the gem will use exponential backoff to wait for its completion according to the max_retries_import option.
- Breaking change: rename the
timeouts config method to additional_client_opts. It has the same usage but now enables you to set both client timeouts and override the API host to send requests to.
additional_client_opts: {
open_timeout: 100,
timeout: 500,
api_host: 'http://example.com/api'
}
- Update documentation, minor code fixes
- Handle rare case when the server returns HTML instead of JSON which happens when too many requests are sent
- Breaking change: require Ruby 3+. Version 2.7 has reached end-of-life and thus we are not planning to support it anymore. If you need support for Ruby 2.7, please stay on 4.0.0.
- Potential breaking change: lambda returned by the
lang_iso_inferer method has been slightly enhanced. It now accepts not only the file data but also the full path to the file. Therefore, if you redefine the lang_iso_inferer option please make sure that the returned lambda accepts two params, not one. This way, you can be more flexible when inferring the locale. For example:
lang_iso_inferer: ->(_data, path) { path.basename('.yml').to_s }
- Use ruby-lokalise-api v9.0.0
- Use ruby-lokalise-api version 8. It should not introduce any breaking changes (as main methods have similar signatures) but you should be aware that v8 is a complete rewrite of the original SDK so please make sure your tests pass.
- Replace VCR with WebMock in tests
- Various minor updates
- Do not test with Ruby 2.7 (EOL)
- Use newer ruby-lokalise-api
- Minor updates
- Fixed an issue when
\n inside translations was imported as \\n. The default value for the translations_converter is now ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }.
- The default format is now
ruby_yaml (it used to be yaml)
- Breaking change: Require Ruby 2.7 or above
- Breaking change (potentially): Use ruby-lokalise-api v6. In general, this transition should not affect you if you employ
export! and import! methods only. However, please be aware that ruby-lokalise-api has a few breaking changes listed in its own changelog
- Use Zeitwerk loader
- Prettify and update source code
- Replaced
filter with select as it does not work with Ruby 2.5
- Use ruby-lokalise-api v5
- Don't use any compression options (compression is now enabled by default)
- Update tests
- Breaking change:
export! will now return an array of objects responding to the following methods:
success — usually returns true (to learn more, check documentation for the :raise_on_export_fail option below)
process — returns an object (an instance of the Lokalise::Resources::QueuedProcess) representing a queued background process as uploading is done in the background on Lokalise. You can use this object to check the process status (whether the uploading is completed or not).
path — returns an instance of the Pathname class which represent the file being uploaded.
- Here's an example:
def uploaded?(process)
5.times do # try to check the status 5 times
process = process.reload_data # load new data
return(true) if process.status == 'finished' # return true is the upload has finished
sleep 1 # wait for 1 second, adjust this number with regards to the upload size
end
false # if all 5 checks failed, return false (probably something is wrong)
end
processes = exporter.export!
puts "Checking status for the #{processes[0].path} file"
uploaded? processes[0].process
- Introduced a new option
raise_on_export_fail (boolean) which is true by default. When this option is enabled, LokaliseManager will re-raise any exceptions that happened during the file uploading. When this option is disabled, the exporting process will continue even if something goes wrong. In this case you'll probably need to check the result yourself and make the necessary actions. For example:
processes = exporter.export!
processes.each do |proc_data|
if proc_data.success
# Everything is good, the uploading is queued
puts "#{proc_data.path} is sent to Lokalise!"
process = proc_data.process
puts "Current process status is #{process.status}"
else
# Something bad has happened
puts "Could not send #{proc_data.path} to Lokalise"
puts "Error #{proc_data.error.class}: #{proc_data.error.message}"
# Or you could re-raise this exception:
# raise proc_data.error.class
end
end
export! method is now taking advantage of multi-threading (as Lokalise API allows to send requests in parallel since January 2022)
- Test with Ruby 3.1.0
- Other minor fixes
- Use refinements instead of monkey patching to add hash methods
- Don't use
OpenStruct anymore to store config opts
- Minor fixes
- Add a new option
:silent_mode which is false by default. When silent mode is enabled, no debug info will be printed out to $stdout. The only exception are the "safe mode" messages — you'll still be prompted to continue if the target directory is not empty.
- Use
#deep_merge instead of a simple merge when processing options.
- Add a new option
:use_oauth2_token which is false by default. When enabled, you'll be able to provide a token obtained via OAuth 2 flow rather than generated via Lokalise profile. The token should still be provided via the :api_token option:
importer = LokaliseManager.importer api_token: 'TOKEN_VIA_OAUTH2', project_id: '123.abc', use_oauth2_token: true