Skip to content

Commit

Permalink
prepare for v5
Browse files Browse the repository at this point in the history
  • Loading branch information
bodrovis committed Nov 9, 2023
1 parent 70ffe41 commit 35f5bb7
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ jobs:
- '3.0'
- 3.1
- 3.2
- '3.3.0-preview2'
runs-on: ${{ matrix.os }}
env:
LOKALISE_API_TOKEN: 123abc
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require:
- rubocop-rake

AllCops:
TargetRubyVersion: 2.7
TargetRubyVersion: 3.0
NewCops: enable

Metrics/BlockLength:
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 5.0.0 (09-Nov-2023)

* **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:

```ruby
lang_iso_inferer: ->(_data, path) { path.basename('.yml').to_s }
```

* Use ruby-lokalise-api v9.0.0

## 4.0.0 (27-Jul-2023)

* **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.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ If your translation files are not in YAML format, you will need to adjust the fo
* `file_ext_regexp` (`regexp`) — regular expression applied to file extensions to determine which files should be imported and exported. Defaults to `/\.ya?ml\z/i` (YAML files).
* `translations_loader` (`lambda` or `proc`) — loads translations data and makes sure they are valid before saving them to a translation file. Defaults to `->(raw_data) { YAML.safe_load raw_data }`. In the simplest case you may just return the data back, for example `-> (raw_data) { raw_data }`.
* `translations_converter` (`lambda` or `proc`) — converts translations data to a proper format before saving them to a translation file. Defaults to `->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') }`. In the simplest case you may just return the data back, for example `-> (raw_data) { raw_data }`.
* `lang_iso_inferer` (`lambda` or `proc`) — infers language ISO code based on the translation file data before uploading it to Lokalise. Defaults to `->(data) { YAML.safe_load(data)&.keys&.first }`.
* `lang_iso_inferer` (`lambda` or `proc`) — infers language ISO code based on the translation file data and path before uploading it to Lokalise. Defaults to `->(data, _path) { YAML.safe_load(data)&.keys&.first }`. To infer locale based on the filename, you can use something like `->(_data, path) { path.basename('.yml').to_s }`. `path` is an instance of the `Pathname` class.

### Customizing JSON parser and network adapter

Expand Down
1 change: 0 additions & 1 deletion lib/lokalise_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'zeitwerk'
require 'yaml'
require 'psych'

loader = Zeitwerk::Loader.for_gem
loader.setup
Expand Down
4 changes: 3 additions & 1 deletion lib/lokalise_manager/global_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ def translations_converter
end

# Infers lang ISO for the given translation file
# The lambda expects to accept the raw contents of the translation file
# and the full path to the file (instance of the `Pathname` class)
def lang_iso_inferer
@lang_iso_inferer || ->(data) { YAML.safe_load(data)&.keys&.first }
@lang_iso_inferer || ->(data, _path) { YAML.safe_load(data)&.keys&.first }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/lokalise_manager/task_definitions/exporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def opts(full_p, relative_p)
initial_opts = {
data: Base64.strict_encode64(content.strip),
filename: relative_p,
lang_iso: config.lang_iso_inferer.call(content)
lang_iso: config.lang_iso_inferer.call(content, full_p)
}

initial_opts.merge config.export_opts
Expand Down
2 changes: 1 addition & 1 deletion lib/lokalise_manager/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module LokaliseManager
VERSION = '4.0.0'
VERSION = '5.0.0'
end
4 changes: 2 additions & 2 deletions lokalise_manager.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/bodrovis/lokalise_manager'
spec.license = 'MIT'
spec.platform = Gem::Platform::RUBY
spec.required_ruby_version = '>= 2.7'
spec.required_ruby_version = '>= 3.0'

spec.files = Dir['README.md', 'LICENSE',
'CHANGELOG.md', 'lib/**/*.rb',
Expand All @@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
spec.extra_rdoc_files = ['README.md']
spec.require_paths = ['lib']

spec.add_dependency 'ruby-lokalise-api', '~> 8.0'
spec.add_dependency 'ruby-lokalise-api', '~> 9.0'
spec.add_dependency 'rubyzip', '~> 2.3'
spec.add_dependency 'zeitwerk', '~> 2.4'

Expand Down
2 changes: 1 addition & 1 deletion spec/lib/lokalise_manager/global_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
end

it 'is possible to set lang_iso_inferer' do
runner = ->(f) { f.to_json }
runner = ->(f, _) { f.to_json }
allow(fake_class).to receive(:lang_iso_inferer=).with(runner)
fake_class.lang_iso_inferer = runner
expect(fake_class).to have_received(:lang_iso_inferer=)
Expand Down
14 changes: 14 additions & 0 deletions spec/lib/lokalise_manager/task_definitions/exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,20 @@
expect(process.project_id).to eq(project_id)
expect(process.status).to eq('queued')
end

it 'can infer locale based on the path' do
allow(described_object.config).to receive(:lang_iso_inferer).and_return(
->(_data, path) { path.basename('.yml').to_s }
)

paths = described_object.send(:all_files).flatten
opts = described_object.send(:opts, *paths)

expect(opts[:filename].to_s).to eq('nested/en.yml')
expect(opts[:lang_iso].to_s).to eq('en')

expect(described_object.config).to have_received(:lang_iso_inferer)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

require_relative '../lib/lokalise_manager'

Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f }
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

RSpec.configure do |config|
config.include FileManager
Expand Down

0 comments on commit 35f5bb7

Please sign in to comment.