From 325d45d3ee7f2fbd66825a134987a1da40677ddd Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 15 Mar 2022 15:58:20 +0200 Subject: [PATCH 01/49] ignore files for zeitwerk --- Gemfile | 2 +- gemfiles/Gemfile-rails-6-0 | 2 +- gemfiles/Gemfile-rails-6-1 | 2 +- lib/lokalise_rails.rb | 2 ++ 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index aa0d2d1..f0d95a4 100644 --- a/Gemfile +++ b/Gemfile @@ -16,5 +16,5 @@ group :test do gem 'simplecov', '~> 0.16' gem 'sprockets-rails', '~> 3' gem 'tzinfo-data' # , platforms: %i[mingw mswin x64_mingw jruby] - gem 'vcr', '~> 6.0' + gem 'vcr', '~> 6.1' end diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index f4031d7..2c211a1 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -13,5 +13,5 @@ group :test do gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' - gem 'vcr', '~> 6.0' + gem 'vcr', '~> 6.1' end \ No newline at end of file diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index 8471e01..f311199 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -13,5 +13,5 @@ group :test do gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' - gem 'vcr', '~> 6.0' + gem 'vcr', '~> 6.1' end \ No newline at end of file diff --git a/lib/lokalise_rails.rb b/lib/lokalise_rails.rb index 0e3b200..32f6a94 100644 --- a/lib/lokalise_rails.rb +++ b/lib/lokalise_rails.rb @@ -5,6 +5,8 @@ loader = Zeitwerk::Loader.for_gem loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" +loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" +loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" loader.setup # Main LokaliseRails module From 820c8f1753755e894986058bfc9c85028ea6aa73 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 15 Mar 2022 16:04:55 +0200 Subject: [PATCH 02/49] Version 5.0.1 [skip ci] --- CHANGELOG.md | 4 ++++ lib/lokalise_rails/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc118f..9a2d3e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 5.0.1 (15-Mar-2022) + +* Fix issue with Zeitwerk and files loading + ## 5.0.0 (11-Mar-2022) * **Breaking change**: require Ruby 2.7+ diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index fab0149..77e6e33 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -2,6 +2,6 @@ # :nocov: module LokaliseRails - VERSION = '5.0.0' + VERSION = '5.0.1' end # :nocov: From 1b246352020db82bd770f02eb8b9fa46f49ed54e Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 17 Aug 2022 19:29:42 +0300 Subject: [PATCH 03/49] fix readme [skip ci] --- README.md | 2 +- lib/generators/templates/lokalise_rails_config.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bd5cc3e..dd6939f 100644 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ LokaliseRails::GlobalConfig.config do |c| # Import options have the following defaults: # c.import_opts = { - # format: 'yaml', + # format: 'ruby_yaml', # placeholder_format: :icu, # yaml_include_root: true, # original_filenames: true, diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index c169a6c..aca0b02 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -22,7 +22,7 @@ # Import options have the following defaults: # c.import_opts = { - # format: 'yaml', + # format: 'ruby_yaml', # placeholder_format: :icu, # yaml_include_root: true, # original_filenames: true, From be31030fa5183c6c12cf437c4fd8f6c20a715061 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 26 Aug 2022 18:30:25 +0300 Subject: [PATCH 04/49] Version 5.1.0 --- CHANGELOG.md | 6 ++++++ LICENSE | 2 +- README.md | 4 ++-- lib/generators/templates/lokalise_rails_config.rb | 2 +- lib/lokalise_rails/version.rb | 4 +--- lokalise_rails.gemspec | 5 ++--- spec/lib/lokalise_rails/global_config_spec.rb | 6 +++--- spec/lib/tasks/export_task_spec.rb | 2 +- spec/lib/tasks/import_task_spec.rb | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a2d3e9..a7ef654 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 5.1.0 (26-Aug-2022) + +* Fixed an issue with `\n` being improperly imported +* Changed default `yaml` format to `ruby_yaml` +* Update dependencies + ## 5.0.1 (15-Mar-2022) * Fix issue with Zeitwerk and files loading diff --git a/LICENSE b/LICENSE index 750b10a..c303786 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Lokalise team, Ilya Bodrov +Copyright (c) 2020 Lokalise team, Ilya Krukowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index dd6939f..964794f 100644 --- a/README.md +++ b/README.md @@ -156,7 +156,7 @@ LokaliseRails::GlobalConfig.config do |c| ## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data } ## Convert translations data to a proper format: - ## c.translations_converter = ->(raw_data) { raw_data.to_yaml } + ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } ## Infer language ISO code for the translation file: ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } @@ -170,4 +170,4 @@ end ## License -Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Bodrov](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE). +Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE). diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index aca0b02..e71df71 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -47,7 +47,7 @@ ## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data } ## Convert translations data to a proper format: - ## c.translations_converter = ->(raw_data) { raw_data.to_yaml } + ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } ## Infer language ISO code for the translation file: ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 77e6e33..0561e80 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# :nocov: module LokaliseRails - VERSION = '5.0.1' + VERSION = '5.1.0' end -# :nocov: diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index e99daf2..b625e16 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -5,7 +5,7 @@ require File.expand_path('lib/lokalise_rails/version', __dir__) Gem::Specification.new do |spec| spec.name = 'lokalise_rails' spec.version = LokaliseRails::VERSION - spec.authors = ['Ilya Bodrov-Krukowski'] + spec.authors = ['Ilya Krukowski'] spec.email = ['golosizpru@gmail.com'] spec.summary = 'Lokalise integration for Ruby on Rails' spec.description = 'This gem allows to exchange translation files between your Rails app and Lokalise TMS.' @@ -19,11 +19,10 @@ Gem::Specification.new do |spec| 'lib/**/*.rake', 'lokalise_rails.gemspec', '.github/*.md', 'Gemfile', 'Rakefile'] - spec.test_files = Dir['spec/**/*.rb'] spec.extra_rdoc_files = ['README.md'] spec.require_paths = ['lib'] - spec.add_dependency 'lokalise_manager', '~> 3.0' + spec.add_dependency 'lokalise_manager', '~> 3.2' spec.add_dependency 'zeitwerk', '~> 2.4' spec.metadata = { diff --git a/spec/lib/lokalise_rails/global_config_spec.rb b/spec/lib/lokalise_rails/global_config_spec.rb index 9d6c689..7f86af8 100644 --- a/spec/lib/lokalise_rails/global_config_spec.rb +++ b/spec/lib/lokalise_rails/global_config_spec.rb @@ -11,8 +11,8 @@ it 'can be redefined' do child_config.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) c.branch = 'develop' end @@ -20,7 +20,7 @@ expect(child_config.branch).to eq('develop') importer = LokaliseManager::TaskDefinitions::Importer.new({}, child_config) expect(importer.config.branch).to eq('develop') - expect(importer.config.api_token).to eq(ENV['LOKALISE_API_TOKEN']) + expect(importer.config.api_token).to eq(ENV.fetch('LOKALISE_API_TOKEN', nil)) end describe 'parameters' do diff --git a/spec/lib/tasks/export_task_spec.rb b/spec/lib/tasks/export_task_spec.rb index 2abf626..35d9ca6 100644 --- a/spec/lib/tasks/export_task_spec.rb +++ b/spec/lib/tasks/export_task_spec.rb @@ -32,7 +32,7 @@ describe 'export' do it 'is callable' do - allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do + allow_project_id global_config, ENV.fetch('LOKALISE_PROJECT_ID', nil) do VCR.use_cassette('upload_files') do expect { Rake::Task['lokalise_rails:export'].execute }.to output(/complete!/).to_stdout end diff --git a/spec/lib/tasks/import_task_spec.rb b/spec/lib/tasks/import_task_spec.rb index 5f260dc..5b492a1 100644 --- a/spec/lib/tasks/import_task_spec.rb +++ b/spec/lib/tasks/import_task_spec.rb @@ -31,7 +31,7 @@ describe 'import' do it 'is callable' do - allow_project_id global_config, ENV['LOKALISE_PROJECT_ID'] do + allow_project_id global_config, ENV.fetch('LOKALISE_PROJECT_ID', nil) do VCR.use_cassette('download_files') do expect { Rake::Task['lokalise_rails:import'].execute }.to output(/complete!/).to_stdout end From ab104bd9873d004eb3deb9dee38452176d1d3cbe Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 26 Aug 2022 18:37:25 +0300 Subject: [PATCH 05/49] bump --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index c303786..addd775 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Lokalise team, Ilya Krukowski +Copyright (c) 2022 Lokalise team, Ilya Krukowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From ae21bb9742611c6f3a971d4c46db9455ac7ec283 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 26 Aug 2022 18:39:33 +0300 Subject: [PATCH 06/49] weird stuff with version --- lib/lokalise_rails/version.rb | 2 ++ spec/dummy/config/lokalise_rails.rb | 9 +++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 0561e80..8efd280 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +# :nocov: module LokaliseRails VERSION = '5.1.0' end +# :nocov: diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 6cfcca6..21fd716 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,5 +1,6 @@ -LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] +# frozen_string_literal: true -end \ No newline at end of file +LokaliseRails::GlobalConfig.config do |c| + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) +end From bc0e53860c9916713084c1dbe287e70fe29fcb2f Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 19 Oct 2022 14:50:01 +0300 Subject: [PATCH 07/49] bump --- .github/workflows/ci.yml | 1 + CHANGELOG.md | 5 +++ lib/lokalise_rails/version.rb | 2 +- lokalise_rails.gemspec | 2 +- spec/fixtures/vcr_cassettes/upload_files.yml | 36 +++++++++++--------- 5 files changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b4a540..ab0db32 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,7 @@ jobs: ruby: - 2.7 - '3.0' + - 3.1 runs-on: ${{ matrix.os }} env: LOKALISE_API_TOKEN: 123abc diff --git a/CHANGELOG.md b/CHANGELOG.md index 15aabb8..0499b0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 4.0.0 (27-Jan-22) + +* File exporting is now multi-threaded as Lokalise API started to support parallel requests since January 2022 +* Test with Ruby 3.1 + ## 3.0.0 (14-Oct-21) This is a major re-write of this gem. The actual import/export functionality was extracted to a separate gem called [lokalise_manager](https://github.com/bodrovis/lokalise_manager) that you can use to run your tasks programmatically from *any* Ruby scripts (powered or not powered by Rails). LokaliseRails now has only the Rails-related logic (even though it should probably work with other frameworks as well). diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index aacc158..7ad1955 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -2,6 +2,6 @@ # :nocov: module LokaliseRails - VERSION = '3.0.0' + VERSION = '4.0.0' end # :nocov: diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index 6428826..ea46d66 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.extra_rdoc_files = ['README.md'] spec.require_paths = ['lib'] - spec.add_dependency 'lokalise_manager', '~> 1.0' + spec.add_dependency 'lokalise_manager', '~> 2.0' spec.metadata = { 'rubygems_mfa_required' => 'true' diff --git a/spec/fixtures/vcr_cassettes/upload_files.yml b/spec/fixtures/vcr_cassettes/upload_files.yml index de80a73..1f413d3 100644 --- a/spec/fixtures/vcr_cassettes/upload_files.yml +++ b/spec/fixtures/vcr_cassettes/upload_files.yml @@ -10,8 +10,8 @@ http_interactions: Accept: - application/json User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: + - ruby-lokalise-api gem/4.5.1 + x-api-token: - "" Accept-Encoding: - gzip,deflate @@ -23,7 +23,7 @@ http_interactions: server: - nginx date: - - Thu, 14 Oct 2021 13:12:40 GMT + - Thu, 27 Jan 2022 17:39:17 GMT content-type: - application/json transfer-encoding: @@ -33,7 +33,7 @@ http_interactions: cache-control: - max-age=0, must-revalidate, no-cache, no-store, private location: - - "/api2/projects/672198945b7d72fc048021.15940510/processes/5a21acbc6dd11ccce38f5f9e3f4fd4e9d556a7c2" + - "/api2/projects/672198945b7d72fc048021.15940510/processes/1cab0ef1cd376687fcebd4bc266c44fd49bffe74" pragma: - no-cache x-content-type-options: @@ -46,13 +46,15 @@ http_interactions: - max-age=31536000 referrer-policy: - origin + x-lokalise-process-id: + - c06f5c8e-00d9-4e78-ad03-f602383ea527 expires: - - Thu, 14 Oct 2021 13:12:40 GMT + - Thu, 27 Jan 2022 17:39:17 GMT body: encoding: UTF-8 - string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"5a21acbc6dd11ccce38f5f9e3f4fd4e9d556a7c2","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2021-10-14 - 13:12:39 (Etc\/UTC)","created_at_timestamp":1634217159}}' - recorded_at: Thu, 14 Oct 2021 13:12:40 GMT + string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"1cab0ef1cd376687fcebd4bc266c44fd49bffe74","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2022-01-27 + 17:39:17 (Etc\/UTC)","created_at_timestamp":1643305157}}' + recorded_at: Thu, 27 Jan 2022 17:39:17 GMT - request: method: post uri: https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/upload @@ -63,8 +65,8 @@ http_interactions: Accept: - application/json User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: + - ruby-lokalise-api gem/4.5.1 + x-api-token: - "" Accept-Encoding: - gzip,deflate @@ -76,7 +78,7 @@ http_interactions: server: - nginx date: - - Thu, 14 Oct 2021 13:12:40 GMT + - Thu, 27 Jan 2022 17:39:17 GMT content-type: - application/json transfer-encoding: @@ -86,7 +88,7 @@ http_interactions: cache-control: - max-age=0, must-revalidate, no-cache, no-store, private location: - - "/api2/projects/672198945b7d72fc048021.15940510/processes/cdf7bb1f65c6dc8d48845e71e39042e3870056f9" + - "/api2/projects/672198945b7d72fc048021.15940510/processes/c13c4fa9e9530776eb651e8454e09843dc585966" pragma: - no-cache x-content-type-options: @@ -99,11 +101,13 @@ http_interactions: - max-age=31536000 referrer-policy: - origin + x-lokalise-process-id: + - 9693626d-6b58-4ea0-b14a-782d572e3400 expires: - - Thu, 14 Oct 2021 13:12:40 GMT + - Thu, 27 Jan 2022 17:39:17 GMT body: encoding: UTF-8 - string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"cdf7bb1f65c6dc8d48845e71e39042e3870056f9","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2021-10-14 - 13:12:40 (Etc\/UTC)","created_at_timestamp":1634217160}}' - recorded_at: Thu, 14 Oct 2021 13:12:41 GMT + string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"c13c4fa9e9530776eb651e8454e09843dc585966","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2022-01-27 + 17:39:17 (Etc\/UTC)","created_at_timestamp":1643305157}}' + recorded_at: Thu, 27 Jan 2022 17:39:17 GMT recorded_with: VCR 6.0.0 From 170244045bfbf9992b7b89afe9da2a4c26a3ef48 Mon Sep 17 00:00:00 2001 From: Ilya Krukowski Date: Thu, 20 Oct 2022 19:56:08 +0300 Subject: [PATCH 08/49] min version [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 964794f..80a3afc 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails ### Requirements -This gem requires Ruby 2.5+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile. +This gem requires Ruby 2.7+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile. Alternatively, you can utilize a token obtained via OAuth 2 flow. When using such a token, you'll have to set `:use_oauth2_token` option to `true` (please check [options docs](https://github.com/bodrovis/lokalise_manager#common-config) to learn more). From f32d0ae4f8d3ee2785b3739e2988cf8ea7cddfde Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 18 Nov 2022 21:58:11 +0200 Subject: [PATCH 09/49] fix tests --- .github/workflows/ci.yml | 4 +- .rubocop.yml | 1 + Gemfile | 5 +- README.md | 2 +- Rakefile | 31 ++++- gemfiles/Gemfile-rails-6-0 | 2 +- gemfiles/Gemfile-rails-6-1 | 2 +- lib/tasks/lokalise_rails_tasks.rake | 2 + spec/fixtures/trans.zip | Bin 0 -> 4605 bytes .../fixtures/vcr_cassettes/download_files.yml | 62 ---------- .../vcr_cassettes/download_files_error.yml | 53 -------- spec/fixtures/vcr_cassettes/upload_files.yml | 113 ------------------ .../vcr_cassettes/upload_files_error.yml | 106 ---------------- spec/lib/lokalise_rails/global_config_spec.rb | 33 +++++ spec/lib/tasks/export_task_spec.rb | 36 ++++-- spec/lib/tasks/import_task_spec.rb | 45 +++++-- spec/spec_helper.rb | 1 + spec/support/vcr.rb | 11 -- 18 files changed, 133 insertions(+), 376 deletions(-) create mode 100644 spec/fixtures/trans.zip delete mode 100644 spec/fixtures/vcr_cassettes/download_files.yml delete mode 100644 spec/fixtures/vcr_cassettes/download_files_error.yml delete mode 100644 spec/fixtures/vcr_cassettes/upload_files.yml delete mode 100644 spec/fixtures/vcr_cassettes/upload_files_error.yml delete mode 100644 spec/support/vcr.rb diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ab0db32..c5cf357 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,10 +24,10 @@ jobs: LOKALISE_PROJECT_ID: 672198945b7d72fc048021.15940510 BUNDLE_GEMFILE: ${{ matrix.gemfile }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake spec \ No newline at end of file + - run: bundle exec rake rubospec \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 395adad..d57c324 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,6 +1,7 @@ require: - rubocop-performance - rubocop-rspec + - rubocop-rake AllCops: TargetRubyVersion: 2.7 diff --git a/Gemfile b/Gemfile index f0d95a4..6748f63 100644 --- a/Gemfile +++ b/Gemfile @@ -12,9 +12,10 @@ group :test do gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' gem 'rubocop-performance', '~> 1.5' + gem 'rubocop-rake', '~> 0.6' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' gem 'sprockets-rails', '~> 3' - gem 'tzinfo-data' # , platforms: %i[mingw mswin x64_mingw jruby] - gem 'vcr', '~> 6.1' + gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + gem 'webmock', '~> 3.14' end diff --git a/README.md b/README.md index 80a3afc..b60cb61 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,7 @@ end ## Running tests -1. Copypaste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use pre-recorded VCR cassettes, so the actual API requests won’t be sent. However, providing at least some values is required. +1. Copypaste `.env.example` file as `.env`. Put your Lokalise API token and project ID inside. The `.env` file is excluded from version control so your data is safe. All in all, we use stubbed requests, so the actual API requests won't be sent. However, providing at least some values is required. 2. Run `rspec .`. Observe test results and code coverage. ## License diff --git a/Rakefile b/Rakefile index 9abd806..2fe8622 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,9 @@ # frozen_string_literal: true require 'rake' +require 'rake/clean' +require 'rspec/core/rake_task' +require 'rubocop/rake_task' begin require 'bundler/setup' @@ -9,13 +12,33 @@ rescue LoadError puts 'although not required, bundler is recommened for running the tests' end -task default: :spec - -require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -require 'rubocop/rake_task' RuboCop::RakeTask.new do |task| task.requires << 'rubocop-performance' task.requires << 'rubocop-rspec' + task.requires << 'rubocop-rake' +end + +CLOBBER.include(FileList['./*.gem']) + +namespace :lokalise do + desc 'Updates RubyGems, installs dependencies' + task :install do + puts 'Running bundle install' + sh 'gem update --system' + sh 'bundle' + end + + desc 'Builds the gem' + task :build do + puts 'Building' + sh 'gem build lokalise_manager.gemspec' + end end + +task rubospec: %w[rubocop spec] + +task full_build: %w[clobber lokalise:install lokalise:build] + +task default: :full_build diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index 2c211a1..9a4559f 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -13,5 +13,5 @@ group :test do gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' - gem 'vcr', '~> 6.1' + gem 'webmock', '~> 3.14' end \ No newline at end of file diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index f311199..358db51 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -13,5 +13,5 @@ group :test do gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' - gem 'vcr', '~> 6.1' + gem 'webmock', '~> 3.14' end \ No newline at end of file diff --git a/lib/tasks/lokalise_rails_tasks.rake b/lib/tasks/lokalise_rails_tasks.rake index ceb8c73..e486299 100644 --- a/lib/tasks/lokalise_rails_tasks.rake +++ b/lib/tasks/lokalise_rails_tasks.rake @@ -5,6 +5,7 @@ require 'lokalise_rails' require "#{LokaliseRails::Utils.root}/config/lokalise_rails" namespace :lokalise_rails do + desc 'Imports translation files from Lokalise to the current Rails project' task :import do importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig) importer.import! @@ -12,6 +13,7 @@ namespace :lokalise_rails do abort e.inspect end + desc 'Exports translation files from the current Rails project to Lokalise' task :export do exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig) exporter.export! diff --git a/spec/fixtures/trans.zip b/spec/fixtures/trans.zip new file mode 100644 index 0000000000000000000000000000000000000000..2cc4fa570ca5a7b6866fbcfc5ee6827d5015d8f9 GIT binary patch literal 4605 zcmai12RPMl|2|e$_MTZ$#z6>CB#spa*_%+p;o#uddmJOjjBJ&?S9W&Udz1Ld%C3$P zUL~dX*Z=*0&vl*8`Ciw3-S=~z=lML(eXA&9V3GsAKe4fQRDb;V`Gs*>%^|!hzW@pU z1;9H4K+GK+&CUJ?j_41ZnYp>$FE9?kC0<08Q=2P6|5VNv2LQP8Z?J>;LtBWMi9OuN z90G*fSodgxH;4Ex*KaDRcl${dhUnAs$(wyY+=toAlQz8`RqwG`_qUu#h zUtWE>eGQlxn5hnU?z4uCVg!gu3`le7O)>=3xzk^jwzQlhjQo_;j_KS#P*K(p0?W*_ zS*stePa#WQLb^7vwQ)0j8Ak6|lbPg1Dyb}rSho(;-g+`q2A$f!4GlMrG@IDVC&;}! zF5F>*&fpgrk%Cwj^V)cS@=~G)$snF6;;r*AJi3h`t3r5&Kag}plR4z-Ynha6f_b7< zHx)sj*C8MStfITp2Y~CcHOn}y3BJO`Ar6xGllT$UKucn`cY7xEmk4xnGB^&Bd5Jb> zYCm*2P_>Cw7BBV9hZ?HxBaFa?2G|{B9fspQtqr6i&4=}4(IRSE=$5)U%i$CtGuBiy zDD&n{nx>e3E@D>kRqrT%6;GLKoh+(5~??inDOZ9#1glu6*7@%EQ zp1r?xNQ4AL*Ak9Xrx)|lL&TmL^QF?4vlKvxEX|1tDojvnaoe~gA zj%STxG-eFGmWIg42HPjteJMFvmVMRORKm9>`rs3VZpagPaZ}dRhDm*|Oz)#sd(F$s zbUE2WMwFL>m*ZyVoEcp_c!B#U7ek7I=?ANVLx2MsoVDs6eHq7_VIKqep>KEpNgG{_ z!4rS{FjAF+U#Mt!NR=j($<*p8Tz zt7$m{+r<3yH}=NBLEnrGpZQttgclN7@1R=Nr}A=hHH`r0-G0`X=z_K_*ysR&6D9ya z@ke9Ym{>x7wxfZ1SHu+G<+>%V;AyfKO<(8rbU%-;qt84(~xaC8- z11E*UcF+chLo@Kvy-m8=;hIe)!TEBH_L-OI3pNjz<1?iXVXvfj7r3avGXFjObC zZ>MJGLujgvd;~<@JgIe>b6xUo#Q4Q(PR)yzZcK3KcgD%jBpe1pykm?tutpo`=nfK4 z3ZPO zTv0+=?6oS&`+ZXZ=@Nb}Eokj@g$g08gm)B!`;X<&&3!f)%{vDCM^37D$9*A?nT~$t zVc>xnUvzsPZiaP^%HAE4+oFXwh>VPGJIZE4`@zSPt&p7EiI40vgCH3CqgrFm$n63^ zWLr`CruLfpGwi|ZUCeToJecMzhsKqoIZxRqeNpM91mjORbh4V=wpSN-e0Ag^0jS(H zmM@9d)P0)+1B#E<#%)QbZc#30RV(&fFFCx9`^l+ z_fYSFOiB_r?2>z;snAx$PrEKVXyaRVD^yZVSWQm9HPQ=_yJktK@$xuVt;k;z9j%+| zQ-f;bgn=IOlZUtq$@>;go(%~WWfN}^ejwuF2vUrc?TGFg$3W?v`{np;4oT}n$Q*P+ z*^?LCAFzFn^T#ao@!`$V?!&q`q-S&x;F~n$C4Qc3jI;_e)#qDJ1ngoM`-WN*Wz$FshY@QdE zO28^&-tJ5)%OCRlSPLW>E%DsKOW{ljP-gh*M$=VIV2S9q0JgkIN?;B!R>pX%8M9Jp zpUF|6nO7q%eSMXj5R>(aH@8V6PB(TZ5#i<)4D)pF#6;vh4V(26!FiJ~=Oz}!A_qd$ zdE_RQ4-IPsk|=dCqsvMvtp?eR*=O=u25jvBu@R=MaLaL(tKxN#$+l8IiqTb;XKXQ+ za%M7>+rT*5%8x#1;7B>PjqkKW9dqR_VOHB@Yo73x2e3l{Z>N(0Mh0fRHg9K5b-qZx zQ+e0G(KEcWN}ubW&Wj7imr%CRI5kf&doBND!}WDh(;auvaQ8g zMYZQoaZv4}_)!L}$H!!tY+}J$Zf;=WNEd0kTJ%oEDi$XTg%_&Nw(EjzWWAO}dvJNM zz*z&m#e$EaS0DTDz?WpiNNx(xRXO#(idZdFCE-a{st2svnHVA!0>oGHSWRyOb!(yN zQ#?U&b73=D&TJqw=(7oUor5EhBd+PXp7s{HD47Ks?}J9tENbj72^Ix;Pj3#1Vbi(} zpzcXz@Stqv%hb#Qn-hYKstsKNT^cX6KTq8oi;Q_Zr)>cz0079&TI06`I_r-atuDxr zB>BuPMGJZfE*A5+S=S}zaR8}emr`ImOE_|Ui=5Qb+gDB1$6qp77+*73kS%BT%@J1L z6=-iVG%=8c*q5Ln%Eb^h>#$KRu)r!CK_8sBh@r4@4KI@#yqD+yAy%@(P$>9lv8FIi z<9OIneYUU6J&I`8*81}f^bY^i9@msap|bQHhOn>O5`515kE|yH7`ip~DP3z{CEIrG zrM>8`(P=^OjL!pTF{lmwD%|$O-z)(G-KhOwLpPo)2KThBB#Stqr*|5WvcbY}QkQ1j zgRHvm={9?fS#xshXFd|NEYI8Gdqd?43X28zszkcP7V8wbc1`LL6zPn^1B0{n7)>oS z)m)nK+KP8^uQ+k1xFg=n?!^v}Kg>a&yz}k8^=8!70UA2uA_w}F7c@e3Y@aoc($I=- zm+beH<1cq69x23AFTP#Cdi-iV-zQo7Q1zuIaQ+RVyPQpetPE+p`ErCE*yhjgndPQ^ z$Mf45_oIIVt}1?-!!Eenq;jbp0PB_&P85v}?+^8j)g^8DBzu*)g6;M&O%p#zyucwm zL(4Y{k0Y!G`w%_HuCsUDqxldq619q?UWc+r`|us^-A8ItAxZP3aPl3g(QsQ!35t1c zvd4*J&9Z*Wh~Z~}xN7rj>H#*ayy6a_#|O-(Ne|s&)x|VYQfa- zX}M;%(XQk{ zY|pya?d!|CCb)*uM}w4cn*IDejY5(`O!r!)K{{NOfJ1GK;MaWIne&c%i4W!fk(eJ7~IsQg;~gtaacog1ns z-`z!1l_jiM^4Jxc*EN3sdhBt&pmEe;6CqitaCLverUp#kgqv5gf^X*=sI^U2PYMz~!DR~tc^`4fjZfP!WZH^P zaTF}HaW0t%TfA^0i>w!gCHW)276z8kr}TBR?wWZ*IURsOCK;@ohz9uWu-v4*<0`Df zN0B^XM?Md`7lHkdF6o<}3H-m9E6c(-q@_kiPZpf*HIu&TumKGjqyLk%aFc0b_-Z~Vl&89>})oJOwb{uNc z#(H{wGb^Ra!W4G?{FQ=QWAAEaCs-CIVdK zmj8qMN3{N50=D|3DSrz5Er6d3e4hlTe+&G+i_YTsML|HRZB1y@DB9Nr-XF7cUVqQl z--5+OK_bkHvvnb6{7t4@_Dtry{+9Wh3q64% QIHw=XQ$xP+-E#x}0})NWO8@`> literal 0 HcmV?d00001 diff --git a/spec/fixtures/vcr_cassettes/download_files.yml b/spec/fixtures/vcr_cassettes/download_files.yml deleted file mode 100644 index d7fee08..0000000 --- a/spec/fixtures/vcr_cassettes/download_files.yml +++ /dev/null @@ -1,62 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/download - body: - encoding: UTF-8 - string: '{"format":"yaml","placeholder_format":"icu","yaml_include_root":true,"original_filenames":true,"directory_prefix":"","indentation":"2sp"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 200 - message: OK - headers: - server: - - nginx - date: - - Thu, 14 Oct 2021 13:14:50 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - vary: - - Accept-Encoding - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - expires: - - Thu, 14 Oct 2021 13:14:50 GMT - access-control-allow-origin: - - "*" - access-control-allow-headers: - - Content-Type - content-encoding: - - gzip - body: - encoding: ASCII-8BIT - string: !binary |- - H4sIAAAAAAAEA4WPS27DIBRF98K4mI9NsTPOAqqOkaxneFZosbF4WIkSde+lK+joSkd3cM6LHSV/oa9zDOzC3q1W0zgNZrHB6tXLYZRadcpMgzRKsje2FNj9rV03oIrlj5x7SDifJTV6q/WgixNOUM/x5HekylUHGzzzDnfqfN6cSPkbUiTkQISVnFhjwjb4OHKpTvyj4YS00tje2sFij2bxflIrNkcddFj6MDpxxS3PnxATzR+tkKfsIWH3jAf7+QUYhJNA9QAAAA== - recorded_at: Thu, 14 Oct 2021 13:14:51 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/fixtures/vcr_cassettes/download_files_error.yml b/spec/fixtures/vcr_cassettes/download_files_error.yml deleted file mode 100644 index 7b6f79d..0000000 --- a/spec/fixtures/vcr_cassettes/download_files_error.yml +++ /dev/null @@ -1,53 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.lokalise.com/api2/projects/fake/files/download - body: - encoding: UTF-8 - string: '{"format":"yaml","placeholder_format":"icu","yaml_include_root":true,"original_filenames":true,"directory_prefix":"","indentation":"2sp"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 400 - message: Bad Request - headers: - server: - - nginx - date: - - Thu, 14 Oct 2021 13:12:42 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - expires: - - Thu, 14 Oct 2021 13:12:42 GMT - body: - encoding: UTF-8 - string: '{"error":{"message":"Invalid `project_id` parameter","code":400}}' - recorded_at: Thu, 14 Oct 2021 13:12:43 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/fixtures/vcr_cassettes/upload_files.yml b/spec/fixtures/vcr_cassettes/upload_files.yml deleted file mode 100644 index 1f413d3..0000000 --- a/spec/fixtures/vcr_cassettes/upload_files.yml +++ /dev/null @@ -1,113 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/upload - body: - encoding: UTF-8 - string: '{"data":"ZW46CiAgbXlfa2V5OiAiTXkgdmFsdWUiCiAgbmVzdGVkOgogICAga2V5OiAiVmFsdWUgMiI=","filename":"nested/en.yml","lang_iso":"en"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.5.1 - x-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 202 - message: Accepted - headers: - server: - - nginx - date: - - Thu, 27 Jan 2022 17:39:17 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - location: - - "/api2/projects/672198945b7d72fc048021.15940510/processes/1cab0ef1cd376687fcebd4bc266c44fd49bffe74" - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - x-lokalise-process-id: - - c06f5c8e-00d9-4e78-ad03-f602383ea527 - expires: - - Thu, 27 Jan 2022 17:39:17 GMT - body: - encoding: UTF-8 - string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"1cab0ef1cd376687fcebd4bc266c44fd49bffe74","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2022-01-27 - 17:39:17 (Etc\/UTC)","created_at_timestamp":1643305157}}' - recorded_at: Thu, 27 Jan 2022 17:39:17 GMT -- request: - method: post - uri: https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/upload - body: - encoding: UTF-8 - string: '{"data":"cnVfUlU6CiAgbXlfa2V5OiAi0JzQvtGRINC30L3QsNGH0LXQvdC40LUiCiAgbmVzdGVkOgogICAga2V5OiAi0JfQvdCw0YfQtdC90LjQtSAyIg==","filename":"ru.yml","lang_iso":"ru_RU"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.5.1 - x-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 202 - message: Accepted - headers: - server: - - nginx - date: - - Thu, 27 Jan 2022 17:39:17 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - location: - - "/api2/projects/672198945b7d72fc048021.15940510/processes/c13c4fa9e9530776eb651e8454e09843dc585966" - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - x-lokalise-process-id: - - 9693626d-6b58-4ea0-b14a-782d572e3400 - expires: - - Thu, 27 Jan 2022 17:39:17 GMT - body: - encoding: UTF-8 - string: '{"project_id":"672198945b7d72fc048021.15940510","branch":"master","process":{"process_id":"c13c4fa9e9530776eb651e8454e09843dc585966","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2022-01-27 - 17:39:17 (Etc\/UTC)","created_at_timestamp":1643305157}}' - recorded_at: Thu, 27 Jan 2022 17:39:17 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/fixtures/vcr_cassettes/upload_files_error.yml b/spec/fixtures/vcr_cassettes/upload_files_error.yml deleted file mode 100644 index 6ab46cf..0000000 --- a/spec/fixtures/vcr_cassettes/upload_files_error.yml +++ /dev/null @@ -1,106 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.lokalise.com/api2/projects/542886116159f798720dc4.94769464/files/upload - body: - encoding: UTF-8 - string: '{"data":"ZW46CiAgbXlfa2V5OiAiTXkgdmFsdWUiCiAgbmVzdGVkOgogICAga2V5OiAiVmFsdWUgMiI=","filename":"nested/en.yml","lang_iso":"en"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 202 - message: Accepted - headers: - server: - - nginx - date: - - Thu, 14 Oct 2021 13:12:18 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - location: - - "/api2/projects/542886116159f798720dc4.94769464/processes/53663aee179cb7508630e44700361d2275a06657" - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - expires: - - Thu, 14 Oct 2021 13:12:18 GMT - body: - encoding: UTF-8 - string: '{"project_id":"542886116159f798720dc4.94769464","branch":"master","process":{"process_id":"53663aee179cb7508630e44700361d2275a06657","type":"file-import","status":"queued","message":"","created_by":20181,"created_by_email":"bodrovis@protonmail.com","created_at":"2021-10-14 - 13:12:18 (Etc\/UTC)","created_at_timestamp":1634217138}}' - recorded_at: Thu, 14 Oct 2021 13:12:19 GMT -- request: - method: post - uri: https://api.lokalise.com/api2/projects/542886116159f798720dc4.94769464/files/upload - body: - encoding: UTF-8 - string: '{"data":"cnVfUlU6CiAgbXlfa2V5OiAi0JzQvtGRINC30L3QsNGH0LXQvdC40LUiCiAgbmVzdGVkOgogICAga2V5OiAi0JfQvdCw0YfQtdC90LjQtSAyIg==","filename":"ru.yml","lang_iso":"ru_RU"}' - headers: - Accept: - - application/json - User-Agent: - - ruby-lokalise-api gem/4.3.1 - X-api-token: - - "" - Accept-Encoding: - - gzip,deflate - response: - status: - code: 400 - message: Bad Request - headers: - server: - - nginx - date: - - Thu, 14 Oct 2021 13:12:19 GMT - content-type: - - application/json - transfer-encoding: - - chunked - connection: - - keep-alive - cache-control: - - max-age=0, must-revalidate, no-cache, no-store, private - pragma: - - no-cache - x-content-type-options: - - nosniff - x-frame-options: - - deny - x-xss-protection: - - 1; mode=block - strict-transport-security: - - max-age=31536000 - referrer-policy: - - origin - expires: - - Thu, 14 Oct 2021 13:12:19 GMT - body: - encoding: UTF-8 - string: '{"error":{"message":"Unknown `lang_iso`","code":400}}' - recorded_at: Thu, 14 Oct 2021 13:12:19 GMT -recorded_with: VCR 6.0.0 diff --git a/spec/lib/lokalise_rails/global_config_spec.rb b/spec/lib/lokalise_rails/global_config_spec.rb index 7f86af8..5ff24ec 100644 --- a/spec/lib/lokalise_rails/global_config_spec.rb +++ b/spec/lib/lokalise_rails/global_config_spec.rb @@ -29,11 +29,31 @@ it 'is possible to set project_id' do allow(fake_class).to receive(:project_id=).with('123.abc') fake_class.project_id = '123.abc' + expect(fake_class).to have_received(:project_id=) + end + + it 'is possible to set raise_on_export_fail' do + allow(fake_class).to receive(:raise_on_export_fail=).with(false) + fake_class.raise_on_export_fail = false + expect(fake_class).to have_received(:raise_on_export_fail=) + end + + it 'is possible to set silent_mode' do + allow(fake_class).to receive(:silent_mode=).with(true) + fake_class.silent_mode = true + expect(fake_class).to have_received(:silent_mode=) + end + + it 'is possible to set use_oauth2_token' do + allow(fake_class).to receive(:use_oauth2_token=).with(true) + fake_class.use_oauth2_token = true + expect(fake_class).to have_received(:use_oauth2_token=) end it 'is possible to set file_ext_regexp' do allow(fake_class).to receive(:file_ext_regexp=).with(Regexp.new('.*')) fake_class.file_ext_regexp = Regexp.new('.*') + expect(fake_class).to have_received(:file_ext_regexp=) end it 'is possible to set import_opts' do @@ -42,6 +62,7 @@ format: 'json', indentation: '8sp' } + expect(fake_class).to have_received(:import_opts=) end it 'is possible to set export_opts' do @@ -50,11 +71,13 @@ convert_placeholders: true, detect_icu_plurals: true } + expect(fake_class).to have_received(:export_opts=) end it 'is possible to set branch' do allow(fake_class).to receive(:branch=).with('custom') fake_class.branch = 'custom' + expect(fake_class).to have_received(:branch=) end it 'is possible to set timeouts' do @@ -63,55 +86,65 @@ open_timeout: 100, timeout: 500 } + expect(fake_class).to have_received(:timeouts=) end it 'is possible to set import_safe_mode' do allow(fake_class).to receive(:import_safe_mode=).with(true) fake_class.import_safe_mode = true + expect(fake_class).to have_received(:import_safe_mode=) end it 'is possible to set max_retries_export' do allow(fake_class).to receive(:max_retries_export=).with(10) fake_class.max_retries_export = 10 + expect(fake_class).to have_received(:max_retries_export=) end it 'is possible to set max_retries_import' do allow(fake_class).to receive(:max_retries_import=).with(10) fake_class.max_retries_import = 10 + expect(fake_class).to have_received(:max_retries_import=) end it 'is possible to set api_token' do allow(fake_class).to receive(:api_token=).with('abc') fake_class.api_token = 'abc' + expect(fake_class).to have_received(:api_token=) end it 'is possible to override locales_path' do allow(fake_class).to receive(:locales_path=).with('/demo/path') fake_class.locales_path = '/demo/path' + expect(fake_class).to have_received(:locales_path=) end it 'is possible to set skip_file_export' do cond = ->(f) { f.nil? } allow(fake_class).to receive(:skip_file_export=).with(cond) fake_class.skip_file_export = cond + expect(fake_class).to have_received(:skip_file_export=) end it 'is possible to set translations_loader' do runner = ->(f) { f.to_json } allow(fake_class).to receive(:translations_loader=).with(runner) fake_class.translations_loader = runner + expect(fake_class).to have_received(:translations_loader=) end it 'is possible to set translations_converter' do runner = ->(f) { f.to_json } allow(fake_class).to receive(:translations_converter=).with(runner) fake_class.translations_converter = runner + expect(fake_class).to have_received(:translations_converter=) end it 'is possible to set lang_iso_inferer' do 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=) end end end diff --git a/spec/lib/tasks/export_task_spec.rb b/spec/lib/tasks/export_task_spec.rb index 35d9ca6..3be60a6 100644 --- a/spec/lib/tasks/export_task_spec.rb +++ b/spec/lib/tasks/export_task_spec.rb @@ -19,9 +19,6 @@ end context 'with two translation files' do - let(:filename_ru) { 'ru.yml' } - let(:path_ru) { "#{Rails.root}/config/locales/#{filename_ru}" } - before do add_translation_files! with_ru: true end @@ -33,17 +30,38 @@ describe 'export' do it 'is callable' do allow_project_id global_config, ENV.fetch('LOKALISE_PROJECT_ID', nil) do - VCR.use_cassette('upload_files') do - expect { Rake::Task['lokalise_rails:export'].execute }.to output(/complete!/).to_stdout - end + stub_request(:post, 'https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/upload'). + to_return( + status: 200, + body: JSON.dump({ + project_id: '672198945b7d72fc048021.15940510', + branch: 'master', + process: { + process_id: '1cab0ef1cd376687fcebd4bc266c44fd49bffe74', + type: 'file-import', + status: 'queued', + message: '', + created_by: 20_181, + created_by_email: 'bodrovis@protonmail.com', + created_at: '2022-01-27 17:39:17 (Etc/UTC)', + created_at_timestamp: 1_643_305_157 + } + }) + ) + + expect { Rake::Task['lokalise_rails:export'].execute }.to output(/complete!/).to_stdout end end it 're-raises export errors' do allow_project_id global_config, '542886116159f798720dc4.94769464' do - VCR.use_cassette('upload_files_error') do - expect { Rake::Task['lokalise_rails:export'].execute }.to raise_error(SystemExit, /Unknown `lang_iso`/) - end + stub_request(:post, 'https://api.lokalise.com/api2/projects/542886116159f798720dc4.94769464/files/upload'). + to_return( + status: 400, + body: JSON.dump({error: {message: 'Unknown `lang_iso`', code: 400}}) + ) + + expect { Rake::Task['lokalise_rails:export'].execute }.to raise_error(SystemExit, /Unknown `lang_iso`/) end end end diff --git a/spec/lib/tasks/import_task_spec.rb b/spec/lib/tasks/import_task_spec.rb index 5b492a1..8a68d1f 100644 --- a/spec/lib/tasks/import_task_spec.rb +++ b/spec/lib/tasks/import_task_spec.rb @@ -32,25 +32,48 @@ describe 'import' do it 'is callable' do allow_project_id global_config, ENV.fetch('LOKALISE_PROJECT_ID', nil) do - VCR.use_cassette('download_files') do - expect { Rake::Task['lokalise_rails:import'].execute }.to output(/complete!/).to_stdout - end + fake_bundle = "#{Dir.getwd}/spec/fixtures/trans.zip" + + stub_request(:post, 'https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/download'). + with( + body: JSON.dump({ + format: 'ruby_yaml', + placeholder_format: 'icu', + yaml_include_root: true, + original_filenames: true, + directory_prefix: '', + indentation: '2sp' + }) + ). + to_return( + status: 200, + body: JSON.dump({ + project_id: '672198945b7d72fc048021.15940510', + bundle_url: fake_bundle + }) + ) + + expect { Rake::Task['lokalise_rails:import'].execute }.to output(/complete!/).to_stdout expect(count_translations).to eq(4) - expect_file_exist loc_path, 'en.yml' - expect_file_exist loc_path, 'ru.yml' - expect_file_exist loc_path, 'yo.yml' + expect_file_exist loc_path, 'en/nested/main_en.yml' + expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml' + expect_file_exist loc_path, 'ru/main_ru.yml' end end it 're-raises export errors' do allow_project_id global_config, 'fake' do - VCR.use_cassette('download_files_error') do - expect do - Rake::Task['lokalise_rails:import'].execute - end.to raise_error(SystemExit, /Invalid `project_id` parameter/) - end + stub_request(:post, 'https://api.lokalise.com/api2/projects/fake/files/download'). + to_return( + status: 400, + body: '{"error":{"message":"Invalid `project_id` parameter","code":400}}' + ) + + expect do + Rake::Task['lokalise_rails:import'].execute + end.to raise_error(SystemExit, /Invalid `project_id` parameter/) end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c6331c3..664ff45 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,6 +2,7 @@ require 'dotenv/load' require 'simplecov' +require 'webmock/rspec' SimpleCov.start 'rails' do add_filter 'spec/' diff --git a/spec/support/vcr.rb b/spec/support/vcr.rb deleted file mode 100644 index 530746c..0000000 --- a/spec/support/vcr.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -require 'vcr' - -VCR.configure do |c| - c.ignore_hosts 'codeclimate.com' - c.hook_into :faraday - c.cassette_library_dir = File.join(File.dirname(__FILE__), '..', 'fixtures', 'vcr_cassettes') - c.filter_sensitive_data('') { ENV.fetch('LOKALISE_API_TOKEN') } - c.configure_rspec_metadata! -end From c5d68b375227ea8a0cf9a3d3fdab79ca7c6fba8f Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 18 Nov 2022 22:00:33 +0200 Subject: [PATCH 10/49] add rubocop --- gemfiles/Gemfile-rails-6-0 | 1 + gemfiles/Gemfile-rails-6-1 | 1 + 2 files changed, 2 insertions(+) diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index 9a4559f..52eaaed 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -12,6 +12,7 @@ group :test do gem 'rubocop', '~> 1.0' gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' + gem 'rubocop-rake', '~> 0.6' gem 'simplecov', '~> 0.16' gem 'webmock', '~> 3.14' end \ No newline at end of file diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index 358db51..8e9eb6a 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -12,6 +12,7 @@ group :test do gem 'rubocop', '~> 1.0' gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rspec', '~> 2.6' + gem 'rubocop-rake', '~> 0.6' gem 'simplecov', '~> 0.16' gem 'webmock', '~> 3.14' end \ No newline at end of file From 8a1941a3b7984c7641b143a2c0ce11e1f5ca480d Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 18 Nov 2022 22:01:17 +0200 Subject: [PATCH 11/49] simplify workflows --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5cf357..7215c96 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake rubospec \ No newline at end of file + - run: bundle exec rake rspec \ No newline at end of file From a7a5e864a9fbfa69dedf7f6a738a53c68981a37a Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 18 Nov 2022 22:02:34 +0200 Subject: [PATCH 12/49] spec --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7215c96..22e7827 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,4 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake rspec \ No newline at end of file + - run: bundle exec rake spec \ No newline at end of file From 36f9f3cf62c76e3653ebbd3710afecade66efa1e Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 3 Jan 2023 21:08:51 +0200 Subject: [PATCH 13/49] cleanup --- .github/workflows/ci.yml | 1 + .rubocop.yml | 4 +++- Gemfile | 4 +--- README.md | 1 - gemfiles/Gemfile-rails-6-0 | 1 - gemfiles/Gemfile-rails-6-1 | 1 - spec/dummy/.ruby-version | 1 - spec/dummy/README.md | 24 ------------------- spec/dummy/app/assets/config/manifest.js | 2 -- spec/dummy/app/assets/images/.keep | 0 .../app/assets/stylesheets/application.css | 15 ------------ spec/dummy/app/helpers/application_helper.rb | 4 ---- .../app/views/layouts/application.html.erb | 2 -- spec/dummy/config/application.rb | 1 - spec/dummy/config/environments/production.rb | 2 +- spec/dummy/config/initializers/assets.rb | 14 ----------- .../config/initializers/cookies_serializer.rb | 7 ------ .../initializers/filter_parameter_logging.rb | 6 ----- spec/dummy/config/lokalise_rails.rb | 9 ++++--- spec/dummy/vendor/.keep | 0 spec/lib/utils_spec.rb | 4 ++-- spec/spec_helper.rb | 5 ---- 22 files changed, 12 insertions(+), 96 deletions(-) delete mode 100644 spec/dummy/.ruby-version delete mode 100644 spec/dummy/README.md delete mode 100644 spec/dummy/app/assets/config/manifest.js delete mode 100644 spec/dummy/app/assets/images/.keep delete mode 100644 spec/dummy/app/assets/stylesheets/application.css delete mode 100644 spec/dummy/app/helpers/application_helper.rb delete mode 100644 spec/dummy/config/initializers/assets.rb delete mode 100644 spec/dummy/config/initializers/cookies_serializer.rb delete mode 100644 spec/dummy/config/initializers/filter_parameter_logging.rb delete mode 100644 spec/dummy/vendor/.keep diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 22e7827..0f9f9b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,6 +18,7 @@ jobs: - 2.7 - '3.0' - 3.1 + - 3.2 runs-on: ${{ matrix.os }} env: LOKALISE_API_TOKEN: 123abc diff --git a/.rubocop.yml b/.rubocop.yml index d57c324..d5802a8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -8,7 +8,9 @@ AllCops: NewCops: enable Exclude: - 'spec/dummy/bin/*' - - '*.md' + - vendor/** + - vendor/bundle/**/* + - bin/** Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space diff --git a/Gemfile b/Gemfile index 6748f63..ed7d254 100644 --- a/Gemfile +++ b/Gemfile @@ -5,9 +5,8 @@ source 'http://rubygems.org' gemspec group :test do - gem 'codecov', '~> 0.2' gem 'dotenv', '~> 2.5' - gem 'rails', '~> 7.0' + gem 'rails', '~> 7.0.4' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' @@ -15,7 +14,6 @@ group :test do gem 'rubocop-rake', '~> 0.6' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.16' - gem 'sprockets-rails', '~> 3' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'webmock', '~> 3.14' end diff --git a/README.md b/README.md index b60cb61..3851fa9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # LokaliseRails ![Gem](https://img.shields.io/gem/v/lokalise_rails) -![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg) [![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails) ![Downloads total](https://img.shields.io/gem/dt/lokalise_rails) diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index 52eaaed..3e6bbf0 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -4,7 +4,6 @@ gemspec path: ".." group :test do gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] - gem 'codecov', '~> 0.2' gem 'dotenv', '~> 2.5' gem 'rails', '~> 6.0' gem 'rake', '~> 13.0' diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index 8e9eb6a..7d6f6a3 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -4,7 +4,6 @@ gemspec path: ".." group :test do gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] - gem 'codecov', '~> 0.2' gem 'dotenv', '~> 2.5' gem 'rails', '~> 6.1' gem 'rake', '~> 13.0' diff --git a/spec/dummy/.ruby-version b/spec/dummy/.ruby-version deleted file mode 100644 index d7edb56..0000000 --- a/spec/dummy/.ruby-version +++ /dev/null @@ -1 +0,0 @@ -ruby-2.6.5 diff --git a/spec/dummy/README.md b/spec/dummy/README.md deleted file mode 100644 index 7db80e4..0000000 --- a/spec/dummy/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# README - -This README would normally document whatever steps are necessary to get the -application up and running. - -Things you may want to cover: - -* Ruby version - -* System dependencies - -* Configuration - -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js deleted file mode 100644 index 5918193..0000000 --- a/spec/dummy/app/assets/config/manifest.js +++ /dev/null @@ -1,2 +0,0 @@ -//= link_tree ../images -//= link_directory ../stylesheets .css diff --git a/spec/dummy/app/assets/images/.keep b/spec/dummy/app/assets/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css deleted file mode 100644 index d05ea0f..0000000 --- a/spec/dummy/app/assets/stylesheets/application.css +++ /dev/null @@ -1,15 +0,0 @@ -/* - * This is a manifest file that'll be compiled into application.css, which will include all the files - * listed below. - * - * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's - * vendor/assets/stylesheets directory can be referenced here using a relative path. - * - * You're free to add application-wide styles to this file and they'll appear at the bottom of the - * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS - * files in this directory. Styles in this file should be added after the last require_* statement. - * It is generally better to create a new file per style scope. - * - *= require_tree . - *= require_self - */ diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb deleted file mode 100644 index 15b06f0..0000000 --- a/spec/dummy/app/helpers/application_helper.rb +++ /dev/null @@ -1,4 +0,0 @@ -# frozen_string_literal: true - -module ApplicationHelper -end diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb index 24307d3..2969ad1 100644 --- a/spec/dummy/app/views/layouts/application.html.erb +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -4,8 +4,6 @@ Dummy <%= csrf_meta_tags %> <%= csp_meta_tag %> - - <%= stylesheet_link_tag 'application', media: 'all' %> diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index d5363bb..ba4edcb 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -14,7 +14,6 @@ # require "action_text/engine" require 'action_view/railtie' # require "action_cable/engine" -require 'sprockets/railtie' # require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb index d089e0c..af1d6dc 100644 --- a/spec/dummy/config/environments/production.rb +++ b/spec/dummy/config/environments/production.rb @@ -62,7 +62,7 @@ config.active_support.deprecation = :notify # Use default logging formatter so that PID and timestamp are not suppressed. - config.log_formatter = ::Logger::Formatter.new + config.log_formatter = Logger::Formatter.new # Use a different logger for distributed setups. # require 'syslog/logger' diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb deleted file mode 100644 index bcafccd..0000000 --- a/spec/dummy/config/initializers/assets.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# Version of your assets, change this if you want to expire all your assets. -Rails.application.config.assets.version = '1.0' - -# Add additional assets to the asset load path. -# Rails.application.config.assets.paths << Emoji.images_path - -# Precompile additional assets. -# application.js, application.css, and all non-JS/CSS in the app/assets -# folder are already added. -# Rails.application.config.assets.precompile += %w( admin.js admin.css ) diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb deleted file mode 100644 index ee8dff9..0000000 --- a/spec/dummy/config/initializers/cookies_serializer.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# Specify a serializer for the signed and encrypted cookie jars. -# Valid options are :json, :marshal, and :hybrid. -Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb deleted file mode 100644 index 7a4f47b..0000000 --- a/spec/dummy/config/initializers/filter_parameter_logging.rb +++ /dev/null @@ -1,6 +0,0 @@ -# frozen_string_literal: true - -# Be sure to restart your server when you modify this file. - -# Configure sensitive parameters which will be filtered from the log file. -Rails.application.config.filter_parameters += [:password] diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 21fd716..6cfcca6 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,6 +1,5 @@ -# frozen_string_literal: true - LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) - c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) -end + c.api_token = ENV['LOKALISE_API_TOKEN'] + c.project_id = ENV['LOKALISE_PROJECT_ID'] + +end \ No newline at end of file diff --git a/spec/dummy/vendor/.keep b/spec/dummy/vendor/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/spec/lib/utils_spec.rb b/spec/lib/utils_spec.rb index 1eec304..af897b9 100644 --- a/spec/lib/utils_spec.rb +++ b/spec/lib/utils_spec.rb @@ -3,13 +3,13 @@ describe LokaliseRails::Utils do describe '.rails_root' do it 'returns RAILS_ROOT if defined' do - allow(::Rails).to receive(:root).and_return(nil) + allow(Rails).to receive(:root).and_return(nil) stub_const('RAILS_ROOT', '/stub') expect(described_class.rails_root).to eq('/stub') end it 'fallbacks if neither roots are present' do - allow(::Rails).to receive(:root).and_return(nil) + allow(Rails).to receive(:root).and_return(nil) expect(described_class.rails_root).to be_nil end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 664ff45..95651e3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -10,11 +10,6 @@ add_filter 'lib/generators/templates/' end -if ENV['CI'] == 'true' - require 'codecov' - SimpleCov.formatter = SimpleCov::Formatter::Codecov -end - # Support files Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } From 931ea5aad45078c8db9cc7d20daf3ea97bf9ffe8 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Mon, 23 Jan 2023 17:07:19 +0200 Subject: [PATCH 14/49] bump --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3851fa9..96e936a 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # LokaliseRails ![Gem](https://img.shields.io/gem/v/lokalise_rails) -[![Test Coverage](https://codecov.io/gh/bodrovis/lokalise_rails/graph/badge.svg)](https://codecov.io/gh/bodrovis/lokalise_rails) +![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg) ![Downloads total](https://img.shields.io/gem/dt/lokalise_rails) This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails and allows to exchange translation files easily. It relies on [lokalise_manager](https://github.com/bodrovis/lokalise_manager) which perform the actual import/export and can be used to run this task in any Ruby script. From 9927217f7777f03be0ce792e5dc476d13449f68f Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 26 Jan 2023 16:06:27 +0200 Subject: [PATCH 15/49] Check if the gem is loaded, closes #11 --- .../templates/lokalise_rails_config.rb | 78 ++++++++++--------- lib/lokalise_rails/version.rb | 2 +- spec/dummy/config/lokalise_rails.rb | 11 ++- spec/support/file_manager.rb | 9 ++- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index e71df71..b462883 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -1,54 +1,56 @@ # frozen_string_literal: true -LokaliseRails::GlobalConfig.config do |c| - # These are mandatory options that you must set before running rake tasks: - # c.api_token = ENV['LOKALISE_API_TOKEN'] - # c.project_id = ENV['LOKALISE_PROJECT_ID'] +if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) + LokaliseRails::GlobalConfig.config do |c| + # These are mandatory options that you must set before running rake tasks: + # c.api_token = ENV['LOKALISE_API_TOKEN'] + # c.project_id = ENV['LOKALISE_PROJECT_ID'] - # Provide a custom path to the directory with your translation files: - # c.locales_path = "#{Rails.root}/config/locales" + # Provide a custom path to the directory with your translation files: + # c.locales_path = "#{Rails.root}/config/locales" - # Provide a Lokalise project branch to use: - # c.branch = '' + # Provide a Lokalise project branch to use: + # c.branch = '' - # Provide request timeouts for the Lokalise API client: - # c.timeouts = {open_timeout: nil, timeout: nil} + # Provide request timeouts for the Lokalise API client: + # c.timeouts = {open_timeout: nil, timeout: nil} - # Provide maximum number of retries for file exporting: - # c.max_retries_export = 5 + # Provide maximum number of retries for file exporting: + # c.max_retries_export = 5 - # Provide maximum number of retries for file importing: - # c.max_retries_import = 5 + # Provide maximum number of retries for file importing: + # c.max_retries_import = 5 - # Import options have the following defaults: - # c.import_opts = { - # format: 'ruby_yaml', - # placeholder_format: :icu, - # yaml_include_root: true, - # original_filenames: true, - # directory_prefix: '', - # indentation: '2sp' - # } + # Import options have the following defaults: + # c.import_opts = { + # format: 'ruby_yaml', + # placeholder_format: :icu, + # yaml_include_root: true, + # original_filenames: true, + # directory_prefix: '', + # indentation: '2sp' + # } - # Safe mode for imports is disabled by default: - # c.import_safe_mode = false + # Safe mode for imports is disabled by default: + # c.import_safe_mode = false - # Additional export options (only filename, contents, and lang_iso params are provided by default) - # c.export_opts = {} + # Additional export options (only filename, contents, and lang_iso params are provided by default) + # c.export_opts = {} - # Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported) - # c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') } + # Provide additional file exclusion criteria for exports (by default, any file with the proper extension will be exported) + # c.skip_file_export = ->(file) { file.split[1].to_s.include?('fr') } - # Set the options below if you would like to work with format other than YAML - ## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise - ## c.file_ext_regexp = /\.ya?ml\z/i + # Set the options below if you would like to work with format other than YAML + ## Regular expression to use when choosing the files to extract from the downloaded archive and upload to Lokalise + ## c.file_ext_regexp = /\.ya?ml\z/i - ## Load translations data and make sure they are valid: - ## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data } + ## Load translations data and make sure they are valid: + ## c.translations_loader = ->(raw_data) { YAML.safe_load raw_data } - ## Convert translations data to a proper format: - ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } + ## Convert translations data to a proper format: + ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } - ## Infer language ISO code for the translation file: - ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } + ## Infer language ISO code for the translation file: + ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } + end end diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 8efd280..6f9f745 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -2,6 +2,6 @@ # :nocov: module LokaliseRails - VERSION = '5.1.0' + VERSION = '5.2.0' end # :nocov: diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 6cfcca6..9fe1f0f 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,5 +1,8 @@ -LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] +# frozen_string_literal: true -end \ No newline at end of file +if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) + LokaliseRails::GlobalConfig.config do |c| + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) + end +end diff --git a/spec/support/file_manager.rb b/spec/support/file_manager.rb index 61ef3a2..9d6f8b4 100644 --- a/spec/support/file_manager.rb +++ b/spec/support/file_manager.rb @@ -40,13 +40,14 @@ def add_translation_files!(with_ru: false, additional: nil) def add_config!(custom_text = '') data = <<~DATA - LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) + LokaliseRails::GlobalConfig.config do |c| + c.api_token = ENV['LOKALISE_API_TOKEN'] + c.project_id = ENV['LOKALISE_PROJECT_ID'] DATA data += custom_text - data += "\nend" + data += "end\nend" open_and_write('config/lokalise_rails.rb') { |f| f.write data } end From fd7db52b601479e22521bacce6be66d78ef13633 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 26 Jan 2023 16:12:26 +0200 Subject: [PATCH 16/49] Version 5.2.0 [skip ci] --- CHANGELOG.md | 5 +++++ Gemfile | 2 +- LICENSE | 2 +- README.md | 2 +- lib/lokalise_rails/version.rb | 4 +--- spec/dummy/config/lokalise_rails.rb | 8 +++----- 6 files changed, 12 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7ef654..ffbfadc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 5.2.0 (26-Jan-2023) + +* The gem can now be added to the `development` group instead of `production` to reduce the bundle size +* Update dependences, test with Ruby 3.2 + ## 5.1.0 (26-Aug-2022) * Fixed an issue with `\n` being improperly imported diff --git a/Gemfile b/Gemfile index ed7d254..03ab5b5 100644 --- a/Gemfile +++ b/Gemfile @@ -13,7 +13,7 @@ group :test do gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rake', '~> 0.6' gem 'rubocop-rspec', '~> 2.6' - gem 'simplecov', '~> 0.16' + gem 'simplecov', '~> 0.22' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'webmock', '~> 3.14' end diff --git a/LICENSE b/LICENSE index addd775..a899ed1 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Lokalise team, Ilya Krukowski +Copyright (c) 2023 Lokalise team, Ilya Krukowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/README.md b/README.md index 96e936a..2d220cd 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Alternatively, you can utilize a token obtained via OAuth 2 flow. When using suc ### Installation -Add the gem to your `Gemfile`: +Add the gem to your `Gemfile` (it can be added to the `development` group if you're not planning to import/export translations in production): ```ruby gem 'lokalise_rails' diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 6f9f745..1b143f6 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -# :nocov: module LokaliseRails VERSION = '5.2.0' -end -# :nocov: +end \ No newline at end of file diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 9fe1f0f..01e8fad 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,8 +1,6 @@ -# frozen_string_literal: true - if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) - c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) - end + c.api_token = ENV['LOKALISE_API_TOKEN'] + c.project_id = ENV['LOKALISE_PROJECT_ID'] end +end \ No newline at end of file From 18d894e076bc19f8b6f2773e300fb1834ee959a8 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 26 Jan 2023 16:14:31 +0200 Subject: [PATCH 17/49] Fix rake task --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 2fe8622..5eb782c 100644 --- a/Rakefile +++ b/Rakefile @@ -33,7 +33,7 @@ namespace :lokalise do desc 'Builds the gem' task :build do puts 'Building' - sh 'gem build lokalise_manager.gemspec' + sh 'gem build lokalise_rails.gemspec' end end From 3ba9337d06293547d90815b181c7f1c0194eb513 Mon Sep 17 00:00:00 2001 From: Elijah Krukowski Date: Sat, 28 Jan 2023 05:51:13 +0200 Subject: [PATCH 18/49] [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2d220cd..3043f8c 100644 --- a/README.md +++ b/README.md @@ -169,4 +169,4 @@ end ## License -Copyright (c) [Lokalise team](http://lokalise.com), [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE). +Copyright (c) [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE). From c1cccd17f3d2fd9adc2bb01e655f99862490106e Mon Sep 17 00:00:00 2001 From: Elijah Krukowski Date: Sat, 28 Jan 2023 05:51:40 +0200 Subject: [PATCH 19/49] [skip ci] --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a899ed1..9534806 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Lokalise team, Ilya Krukowski +Copyright (c) 2023 Ilya Krukowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 2d8b0d3ae4ff5f30ded3fc95c78a9ca958b04860 Mon Sep 17 00:00:00 2001 From: Elijah Krukowski Date: Thu, 11 May 2023 13:14:00 +0300 Subject: [PATCH 20/49] Update README.md --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 3043f8c..7b01f98 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,30 @@ importer.import! exporter.export! ``` +### Example: Multiple translation paths + +Creating custom import/export script can come in really handy if you have a non-standard setup, for instance, your translation files are stored in multiple directories (not only in the default `./config/locales`. To overcome this problem, create a custom Rake task and provide as many importers/exporters as needed: + +```ruby +require 'rake' +require 'lokalise_rails' +require "#{LokaliseRails::Utils.root}/config/lokalise_rails" + +namespace :lokalise_custom do + task :export do + # importing from the default directory (./config/locales/) + exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig) + exporter.export! + + # importing from the custom directory + exporter = LokaliseManager.exporter({locales_path: "#{Rails.root}/config/custom_locales"}, LokaliseRails::GlobalConfig) + exporter.export! + rescue StandardError => e + abort e.inspect + end +end +``` + ## Configuration Options are specified in the `config/lokalise_rails.rb` file. From dac0b190a3aff9baaee73df447aef7329317e064 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 21 Jul 2023 13:49:07 +0300 Subject: [PATCH 21/49] Version 6 --- .github/workflows/ci.yml | 1 - .rubocop.yml | 3 +++ CHANGELOG.md | 5 +++++ lib/lokalise_rails/version.rb | 4 ++-- lokalise_rails.gemspec | 2 +- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0f9f9b7..4d82f6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,7 +15,6 @@ jobs: - gemfiles/Gemfile-rails-6-1 - gemfiles/Gemfile-rails-6-0 ruby: - - 2.7 - '3.0' - 3.1 - 3.2 diff --git a/.rubocop.yml b/.rubocop.yml index d5802a8..a2b7b19 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -76,3 +76,6 @@ RSpec/FilePath: RSpec/MultipleMemoizedHelpers: Max: 10 + +Gemspec/DevelopmentDependencies: + EnforcedStyle: gemspec \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ffbfadc..a24ed0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 6.0.0 (27-Jul-2023) + +* Use lokalise-manager v4 and ruby-lokalise-api v8. The latter is a major rewrite of the original SDK and has some breaking changes (however 95% of the methods have similar signatures). Therefore please make sure that your tests pass. +* Do not test with Ruby 2.7 (EOL) + ## 5.2.0 (26-Jan-2023) * The gem can now be added to the `development` group instead of `production` to reduce the bundle size diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 1b143f6..47d2ab7 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '5.2.0' -end \ No newline at end of file + VERSION = '6.0.0' +end diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index b625e16..23d9b8e 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.extra_rdoc_files = ['README.md'] spec.require_paths = ['lib'] - spec.add_dependency 'lokalise_manager', '~> 3.2' + spec.add_dependency 'lokalise_manager', '~> 4.0' spec.add_dependency 'zeitwerk', '~> 2.4' spec.metadata = { From b53d4041bcc7a8b47758581050dab473286f3944 Mon Sep 17 00:00:00 2001 From: Elijah Krukowski Date: Wed, 30 Aug 2023 17:53:35 +0300 Subject: [PATCH 22/49] Update README.md [skip ci] --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7b01f98..70c4851 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ![Gem](https://img.shields.io/gem/v/lokalise_rails) ![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg) +[![Maintainability](https://api.codeclimate.com/v1/badges/6e5c98f76227de00b0f2/maintainability)](https://codeclimate.com/github/bodrovis/lokalise_rails/maintainability) ![Downloads total](https://img.shields.io/gem/dt/lokalise_rails) This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails and allows to exchange translation files easily. It relies on [lokalise_manager](https://github.com/bodrovis/lokalise_manager) which perform the actual import/export and can be used to run this task in any Ruby script. From 27737d1cf17930dcdd18ca03001628deb1c32c55 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 30 Aug 2023 17:59:53 +0300 Subject: [PATCH 23/49] coveralls --- .github/workflows/ci.yml | 4 +++- Gemfile | 1 + gemfiles/Gemfile-rails-6-0 | 1 + gemfiles/Gemfile-rails-6-1 | 1 + spec/spec_helper.rb | 11 +++++++++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4d82f6b..8b3a2c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,4 +30,6 @@ jobs: with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - - run: bundle exec rake spec \ No newline at end of file + - run: bundle exec rake spec + - name: Coveralls + uses: coverallsapp/github-action@v2 \ No newline at end of file diff --git a/Gemfile b/Gemfile index 03ab5b5..2d24216 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ group :test do gem 'rubocop-rake', '~> 0.6' gem 'rubocop-rspec', '~> 2.6' gem 'simplecov', '~> 0.22' + gem 'simplecov-lcov', '~> 0.8' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'webmock', '~> 3.14' end diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 index 3e6bbf0..ec91170 100644 --- a/gemfiles/Gemfile-rails-6-0 +++ b/gemfiles/Gemfile-rails-6-0 @@ -13,5 +13,6 @@ group :test do gem 'rubocop-rspec', '~> 2.6' gem 'rubocop-rake', '~> 0.6' gem 'simplecov', '~> 0.16' + gem 'simplecov-lcov', '~> 0.8' gem 'webmock', '~> 3.14' end \ No newline at end of file diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index 7d6f6a3..1a2608f 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -13,5 +13,6 @@ group :test do gem 'rubocop-rspec', '~> 2.6' gem 'rubocop-rake', '~> 0.6' gem 'simplecov', '~> 0.16' + gem 'simplecov-lcov', '~> 0.8' gem 'webmock', '~> 3.14' end \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 95651e3..34d843b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,6 +5,17 @@ require 'webmock/rspec' SimpleCov.start 'rails' do + if ENV['CI'] + require 'simplecov-lcov' + + SimpleCov::Formatter::LcovFormatter.config do |c| + c.report_with_single_file = true + c.single_report_path = 'coverage/lcov.info' + end + + formatter SimpleCov::Formatter::LcovFormatter + end + add_filter 'spec/' add_filter '.github/' add_filter 'lib/generators/templates/' From 22e0ac8d725d7ec844ea5fa4648d0d95954fc5a3 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 30 Aug 2023 18:07:33 +0300 Subject: [PATCH 24/49] cleanup --- README.md | 1 + spec/lib/lokalise_rails/version_spec.rb | 7 ------- spec/spec_helper.rb | 3 ++- 3 files changed, 3 insertions(+), 8 deletions(-) delete mode 100644 spec/lib/lokalise_rails/version_spec.rb diff --git a/README.md b/README.md index 70c4851..0e5ce45 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ ![Gem](https://img.shields.io/gem/v/lokalise_rails) ![CI](https://github.com/bodrovis/lokalise_rails/actions/workflows/ci.yml/badge.svg) +[![Coverage Status](https://coveralls.io/repos/github/bodrovis/lokalise_rails/badge.svg?branch=master)](https://coveralls.io/github/bodrovis/lokalise_rails?branch=master) [![Maintainability](https://api.codeclimate.com/v1/badges/6e5c98f76227de00b0f2/maintainability)](https://codeclimate.com/github/bodrovis/lokalise_rails/maintainability) ![Downloads total](https://img.shields.io/gem/dt/lokalise_rails) diff --git a/spec/lib/lokalise_rails/version_spec.rb b/spec/lib/lokalise_rails/version_spec.rb deleted file mode 100644 index 2de229a..0000000 --- a/spec/lib/lokalise_rails/version_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -describe LokaliseRails do - it 'returns a proper version' do - expect(LokaliseRails::VERSION).to be_a(String) - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 34d843b..138bb5e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -15,10 +15,11 @@ formatter SimpleCov::Formatter::LcovFormatter end - + add_filter 'spec/' add_filter '.github/' add_filter 'lib/generators/templates/' + add_filter 'lib/lokalise_rails/version.rb' end # Support files From 9ea9a923448266b8936941f1c353c0d3f71d54cf Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 19 Oct 2023 17:55:06 +0300 Subject: [PATCH 25/49] test with Rails 7.1 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2d24216..2dfda3f 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gemspec group :test do gem 'dotenv', '~> 2.5' - gem 'rails', '~> 7.0.4' + gem 'rails', '~> 7.1' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' From 1667d44bbaf22c40946a4a8f501d086994227323 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 19 Oct 2023 18:01:41 +0300 Subject: [PATCH 26/49] bump --- .rubocop.yml | 6 +++++- spec/lib/{ => lokalise_rails}/utils_spec.rb | 0 2 files changed, 5 insertions(+), 1 deletion(-) rename spec/lib/{ => lokalise_rails}/utils_spec.rb (100%) diff --git a/.rubocop.yml b/.rubocop.yml index a2b7b19..cf35e9b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -78,4 +78,8 @@ RSpec/MultipleMemoizedHelpers: Max: 10 Gemspec/DevelopmentDependencies: - EnforcedStyle: gemspec \ No newline at end of file + EnforcedStyle: gemspec + +RSpec/SpecFilePathFormat: + Exclude: + - spec/lib/generators/lokalise_rails/**/*.rb \ No newline at end of file diff --git a/spec/lib/utils_spec.rb b/spec/lib/lokalise_rails/utils_spec.rb similarity index 100% rename from spec/lib/utils_spec.rb rename to spec/lib/lokalise_rails/utils_spec.rb From 1366dd43c05716fb0c221f877c38fe32045783aa Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 19 Oct 2023 18:02:43 +0300 Subject: [PATCH 27/49] bump --- spec/dummy/config/lokalise_rails.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 01e8fad..9fe1f0f 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) + end end -end \ No newline at end of file From 467a0b6a683d267b8e1690dbff2a99216b13d091 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 9 Nov 2023 17:28:01 +0200 Subject: [PATCH 28/49] prepare for v7 --- .github/workflows/ci.yml | 2 +- .rubocop.yml | 2 +- CHANGELOG.md | 12 ++++++++++++ README.md | 2 +- gemfiles/Gemfile-rails-6-0 | 18 ------------------ .../templates/lokalise_rails_config.rb | 2 +- lib/lokalise_rails/version.rb | 2 +- lokalise_rails.gemspec | 4 ++-- spec/dummy/config/application.rb | 2 ++ spec/dummy/config/lokalise_rails.rb | 8 +++----- spec/lib/lokalise_rails/global_config_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 12 files changed, 26 insertions(+), 32 deletions(-) delete mode 100644 gemfiles/Gemfile-rails-6-0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8b3a2c9..e1d807a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,11 +13,11 @@ jobs: gemfile: - Gemfile - gemfiles/Gemfile-rails-6-1 - - gemfiles/Gemfile-rails-6-0 ruby: - '3.0' - 3.1 - 3.2 + - '3.3.0-preview2' runs-on: ${{ matrix.os }} env: LOKALISE_API_TOKEN: 123abc diff --git a/.rubocop.yml b/.rubocop.yml index cf35e9b..7a73bbf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,7 @@ require: - rubocop-rake AllCops: - TargetRubyVersion: 2.7 + TargetRubyVersion: 3.0 NewCops: enable Exclude: - 'spec/dummy/bin/*' diff --git a/CHANGELOG.md b/CHANGELOG.md index a24ed0a..ec70010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 7.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 6.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 newer lokalise_manager and ruby-lokalise-api. +* Test with Ruby 3.3, do not test with Rails 6.0 (EOL) + ## 6.0.0 (27-Jul-2023) * Use lokalise-manager v4 and ruby-lokalise-api v8. The latter is a major rewrite of the original SDK and has some breaking changes (however 95% of the methods have similar signatures). Therefore please make sure that your tests pass. diff --git a/README.md b/README.md index 0e5ce45..42990ea 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,7 @@ LokaliseRails::GlobalConfig.config do |c| ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } ## Infer language ISO code for the translation file: - ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } + ## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first } end ``` diff --git a/gemfiles/Gemfile-rails-6-0 b/gemfiles/Gemfile-rails-6-0 deleted file mode 100644 index ec91170..0000000 --- a/gemfiles/Gemfile-rails-6-0 +++ /dev/null @@ -1,18 +0,0 @@ -source "https://rubygems.org" - -gemspec path: ".." - -group :test do - gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] - gem 'dotenv', '~> 2.5' - gem 'rails', '~> 6.0' - gem 'rake', '~> 13.0' - gem 'rspec', '~> 3.6' - gem 'rubocop', '~> 1.0' - gem 'rubocop-performance', '~> 1.5' - gem 'rubocop-rspec', '~> 2.6' - gem 'rubocop-rake', '~> 0.6' - gem 'simplecov', '~> 0.16' - gem 'simplecov-lcov', '~> 0.8' - gem 'webmock', '~> 3.14' -end \ No newline at end of file diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index b462883..b07284b 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -51,6 +51,6 @@ ## c.translations_converter = ->(raw_data) { YAML.dump(raw_data).gsub(/\\\\n/, '\n') } ## Infer language ISO code for the translation file: - ## c.lang_iso_inferer = ->(data) { YAML.safe_load(data)&.keys&.first } + ## c.lang_iso_inferer = ->(data, _path) { YAML.safe_load(data)&.keys&.first } end end diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 47d2ab7..9082123 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '6.0.0' + VERSION = '7.0.0' end diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index 23d9b8e..8530b8f 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -12,7 +12,7 @@ Gem::Specification.new do |spec| spec.homepage = 'https://github.com/bodrovis/lokalise_rails' spec.license = 'MIT' spec.platform = Gem::Platform::RUBY - spec.required_ruby_version = '>= 2.7.0' + spec.required_ruby_version = '>= 3.0' spec.files = Dir['README.md', 'LICENSE', 'CHANGELOG.md', 'lib/**/*.rb', @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.extra_rdoc_files = ['README.md'] spec.require_paths = ['lib'] - spec.add_dependency 'lokalise_manager', '~> 4.0' + spec.add_dependency 'lokalise_manager', '~> 5.0' spec.add_dependency 'zeitwerk', '~> 2.4' spec.metadata = { diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index ba4edcb..2cde753 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -31,5 +31,7 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil + + config.load_defaults 6.1 end end diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 9fe1f0f..01e8fad 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,8 +1,6 @@ -# frozen_string_literal: true - if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) - c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) - end + c.api_token = ENV['LOKALISE_API_TOKEN'] + c.project_id = ENV['LOKALISE_PROJECT_ID'] end +end \ No newline at end of file diff --git a/spec/lib/lokalise_rails/global_config_spec.rb b/spec/lib/lokalise_rails/global_config_spec.rb index 5ff24ec..2c9a638 100644 --- a/spec/lib/lokalise_rails/global_config_spec.rb +++ b/spec/lib/lokalise_rails/global_config_spec.rb @@ -141,7 +141,7 @@ end it 'is possible to set lang_iso_inferer' do - runner = ->(f) { f.to_json } + runner = ->(f, _path) { 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=) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 138bb5e..b651c01 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,7 +23,7 @@ end # Support files -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].sort.each { |f| require f } +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } # Configure Rails Environment ENV['RAILS_ENV'] = 'test' From 086e4bd2919ba3129dd5fcfaead85c28f631e835 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 9 Nov 2023 17:33:13 +0200 Subject: [PATCH 29/49] update readme [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 42990ea..f5b4a67 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ This gem provides [Lokalise](http://lokalise.com) integration for Ruby on Rails ### Requirements -This gem requires Ruby 2.7+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile. +This gem requires Ruby 3.0+ and Rails 5.1+. It might work with older versions of Rails though. You will also need to [setup a Lokalise account](https://app.lokalise.com/signup) and create a [translation project](https://docs.lokalise.com/en/articles/1400460-projects). Finally, you will need to generate a [read/write API token](https://docs.lokalise.com/en/articles/1929556-api-tokens) at your Lokalise profile. Alternatively, you can utilize a token obtained via OAuth 2 flow. When using such a token, you'll have to set `:use_oauth2_token` option to `true` (please check [options docs](https://github.com/bodrovis/lokalise_manager#common-config) to learn more). From 4ed48a4b308719e33742d30339b253a3e75b4909 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 21 Nov 2023 19:49:32 +0200 Subject: [PATCH 30/49] update gh actions --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e1d807a..d3606d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: LOKALISE_PROJECT_ID: 672198945b7d72fc048021.15940510 BUNDLE_GEMFILE: ${{ matrix.gemfile }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: From d7a2d3a3408965f2260f4767219c84726a58bcdf Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 22 Dec 2023 19:46:48 +0200 Subject: [PATCH 31/49] bump --- spec/dummy/config/lokalise_rails.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 01e8fad..9fe1f0f 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) + end end -end \ No newline at end of file From 0203886ff2b6ad87d95df29cba936ea10df67e35 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 26 Dec 2023 20:50:15 +0200 Subject: [PATCH 32/49] test with ruby 3.3 --- .github/workflows/ci.yml | 2 +- spec/dummy/config/application.rb | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d3606d6..7c0df05 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: - '3.0' - 3.1 - 3.2 - - '3.3.0-preview2' + - 3.3 runs-on: ${{ matrix.os }} env: LOKALISE_API_TOKEN: 123abc diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 2cde753..b4b670c 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -32,6 +32,10 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil - config.load_defaults 6.1 + if Rails.version < Gem::Version.new('7.0') + config.load_defaults 6.1 + else + config.load_defaults 7.0 + end end end From de58c87107f2c4f051ad7735dd703606d9f61d6b Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 26 Dec 2023 20:53:37 +0200 Subject: [PATCH 33/49] fix tests --- spec/dummy/config/application.rb | 2 +- spec/dummy/config/lokalise_rails.rb | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index b4b670c..7933391 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -32,7 +32,7 @@ class Application < Rails::Application # Don't generate system test files. config.generators.system_tests = nil - if Rails.version < Gem::Version.new('7.0') + if Rails.gem_version < Gem::Version.new('7.0') config.load_defaults 6.1 else config.load_defaults 7.0 diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 9fe1f0f..01e8fad 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,8 +1,6 @@ -# frozen_string_literal: true - if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) - c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) - end + c.api_token = ENV['LOKALISE_API_TOKEN'] + c.project_id = ENV['LOKALISE_PROJECT_ID'] end +end \ No newline at end of file From 0209c22602994d73252ca60b1859c4ac604ba392 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Sun, 31 Dec 2023 22:26:50 +0200 Subject: [PATCH 34/49] happy new 2024 :christmas_tree: --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 9534806..ed70961 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2023 Ilya Krukowski +Copyright (c) 2024 Ilya Krukowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the From 355fbf9de8886b86a30a9cff52197d429f36c4c7 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 9 Feb 2024 15:18:32 +0200 Subject: [PATCH 35/49] bump --- spec/dummy/config/lokalise_rails.rb | 8 +++++--- spec/support/file_manager.rb | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/spec/dummy/config/lokalise_rails.rb b/spec/dummy/config/lokalise_rails.rb index 01e8fad..fc6e125 100644 --- a/spec/dummy/config/lokalise_rails.rb +++ b/spec/dummy/config/lokalise_rails.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) +end end -end \ No newline at end of file diff --git a/spec/support/file_manager.rb b/spec/support/file_manager.rb index 9d6f8b4..e45e53a 100644 --- a/spec/support/file_manager.rb +++ b/spec/support/file_manager.rb @@ -40,14 +40,16 @@ def add_translation_files!(with_ru: false, additional: nil) def add_config!(custom_text = '') data = <<~DATA + # frozen_string_literal: true + if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| - c.api_token = ENV['LOKALISE_API_TOKEN'] - c.project_id = ENV['LOKALISE_PROJECT_ID'] + c.api_token = ENV.fetch('LOKALISE_API_TOKEN', nil) + c.project_id = ENV.fetch('LOKALISE_PROJECT_ID', nil) DATA data += custom_text - data += "end\nend" + data += "end\nend\n" open_and_write('config/lokalise_rails.rb') { |f| f.write data } end From 66efeca9890146777019f668fe20e92da9225a3a Mon Sep 17 00:00:00 2001 From: bodrovis Date: Sun, 25 Feb 2024 21:15:39 +0200 Subject: [PATCH 36/49] bump --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2dfda3f..37da4ad 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,7 @@ source 'http://rubygems.org' gemspec group :test do - gem 'dotenv', '~> 2.5' + gem 'dotenv', '~> 3.0' gem 'rails', '~> 7.1' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' From bced5bdc5cc496038d2c343d1d343243c2bf7060 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 10 May 2024 15:08:32 +0300 Subject: [PATCH 37/49] version 7.0.1 --- .rubocop.yml | 1 + CHANGELOG.md | 4 ++++ .../lokalise_rails/install_generator.rb | 13 ++++++++++--- lib/lokalise_rails.rb | 13 +++++++++---- lib/lokalise_rails/global_config.rb | 9 ++++++++- lib/lokalise_rails/railtie.rb | 11 ++++++++++- lib/lokalise_rails/utils.rb | 16 ++++++++++++++-- lib/lokalise_rails/version.rb | 2 +- lib/tasks/lokalise_rails_tasks.rake | 15 +++++++++++++-- spec/dummy/db/seeds.rb | 1 + 10 files changed, 71 insertions(+), 14 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7a73bbf..60b503f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ require: AllCops: TargetRubyVersion: 3.0 NewCops: enable + SuggestExtensions: false Exclude: - 'spec/dummy/bin/*' - vendor/** diff --git a/CHANGELOG.md b/CHANGELOG.md index ec70010..d1751fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 7.0.1 + +* Update documentation, minor code tweaks + ## 7.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 6.0.0. diff --git a/lib/generators/lokalise_rails/install_generator.rb b/lib/generators/lokalise_rails/install_generator.rb index 99b00db..c60481f 100644 --- a/lib/generators/lokalise_rails/install_generator.rb +++ b/lib/generators/lokalise_rails/install_generator.rb @@ -3,15 +3,22 @@ require 'rails/generators' module LokaliseRails - # Generators for LokaliseRails module Generators - # Installs LokaliseRails config + # Generator that sets up the LokaliseRails configuration in a Rails application. + # It copies a predefined configuration template into the appropriate directory within the Rails application, + # making it easier for users to configure and use LokaliseRails. class InstallGenerator < Rails::Generators::Base + # Sets the directory containing the template files relative to this file's location. source_root File.expand_path('../templates', __dir__) - desc 'Creates a LokaliseRails config file.' + # Description of the generator's purpose, which is displayed in the Rails generators list. + desc 'Creates a LokaliseRails config file in your Rails application.' + # The primary method of this generator, responsible for copying the LokaliseRails configuration template + # from the gem to the Rails application's config directory. This is where users can customize + # their Lokalise settings. def copy_config + # Copies the configuration template to the Rails application's config directory. template 'lokalise_rails_config.rb', "#{Rails.root}/config/lokalise_rails.rb" end end diff --git a/lib/lokalise_rails.rb b/lib/lokalise_rails.rb index 32f6a94..1862fb8 100644 --- a/lib/lokalise_rails.rb +++ b/lib/lokalise_rails.rb @@ -3,14 +3,19 @@ require 'zeitwerk' require 'lokalise_manager' +# Configure Zeitwerk loader specific for gem environments. This loader is set up to ignore certain files +# that should not be autoloaded, such as Rails-specific files or templates which are not part of the main load path. loader = Zeitwerk::Loader.for_gem -loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" -loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" -loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" +loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" # Ignore the Railtie in non-Rails environments +loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" # Ignore the generator templates +loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" # Ignore installation generator scripts loader.setup -# Main LokaliseRails module +# Main module for the LokaliseRails gem. This module serves as the namespace for all components +# related to the LokaliseRails integration. It provides a structured way to manage translations +# through the Lokalise platform within Ruby on Rails applications. module LokaliseRails end +# Require the Railtie only if Rails is defined to integrate with Rails without manual configuration. require_relative 'lokalise_rails/railtie' if defined?(Rails) diff --git a/lib/lokalise_rails/global_config.rb b/lib/lokalise_rails/global_config.rb index 92402eb..6e31159 100644 --- a/lib/lokalise_rails/global_config.rb +++ b/lib/lokalise_rails/global_config.rb @@ -1,10 +1,17 @@ # frozen_string_literal: true module LokaliseRails - # Global configuration, based on LokaliseManager config + # Inherits from LokaliseManager::GlobalConfig to provide a global configuration specific to the LokaliseRails gem. + # This class is primarily used to manage configuration settings that affect how the LokaliseRails gem operates + # within a Ruby on Rails application, particularly in managing locale paths. class GlobalConfig < LokaliseManager::GlobalConfig class << self + # Provides the path to the locales directory where translation files are stored. If not set explicitly, + # it defaults to the `config/locales` directory within the root of the application using this gem. + # + # @return [String] the path to the locales directory def locales_path + # If @locales_path is not set, it defaults to a path under the application's root directory. @locales_path || "#{LokaliseRails::Utils.root}/config/locales" end end diff --git a/lib/lokalise_rails/railtie.rb b/lib/lokalise_rails/railtie.rb index 5c41af8..51a9be0 100644 --- a/lib/lokalise_rails/railtie.rb +++ b/lib/lokalise_rails/railtie.rb @@ -1,9 +1,18 @@ # frozen_string_literal: true module LokaliseRails - # Load Rake tasks + # The Railtie class in Rails is used to extend Rails' functionality within an application, or in this case, + # a gem. This Railtie is specifically used to add custom Rake tasks from the + # LokaliseRails gem into the Rails application. + # + # It leverages Rails' Railtie architecture to ensure the Rake + # tasks are loaded when the application boots up and Rake is invoked. class Railtie < Rails::Railtie + # Register Rake tasks that are defined within this gem. This block is called by Rails during the initialization + # process and ensures that all Rake tasks specific to LokaliseRails are available to the application. rake_tasks do + # Loads the Rake tasks from a file located relative to this file. Ensure this file exists and contains + # valid Rake task definitions specifically tailored for Lokalise integration. load 'tasks/lokalise_rails_tasks.rake' end end diff --git a/lib/lokalise_rails/utils.rb b/lib/lokalise_rails/utils.rb index e383406..f870798 100644 --- a/lib/lokalise_rails/utils.rb +++ b/lib/lokalise_rails/utils.rb @@ -6,16 +6,28 @@ module LokaliseRails # Util methods module Utils class << self - # Current project root + # Retrieves the root directory of the current project. + # It attempts to find the Rails root directory if Rails is loaded. + # If Rails is not present, it defaults to the current working directory of the process. + # + # @return [Pathname] A Pathname object pointing to the root directory of the project. def root + # Uses Pathname to create a robust path object from the rails_root or the current working directory. Pathname.new(rails_root || Dir.getwd) end - # Tries to get Rails root if Rails is defined + # Attempts to determine the root directory of a Rails + # project by checking the presence of Rails and its root method. + # If Rails is older and does not have the root method, it falls back to the RAILS_ROOT constant if defined. + # + # @return [String, nil] the path to the root directory if Rails is defined, or nil if it cannot be determined. def rails_root + # First, check if Rails.root is defined and return its path if available. return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root + # Fallback to the RAILS_ROOT constant from older Rails versions. return RAILS_ROOT.to_s if defined?(RAILS_ROOT) + # Returns nil if none of the above are defined, indicating Rails is not present. nil end end diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 9082123..7618574 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '7.0.0' + VERSION = '7.0.1' end diff --git a/lib/tasks/lokalise_rails_tasks.rake b/lib/tasks/lokalise_rails_tasks.rake index e486299..0d7e492 100644 --- a/lib/tasks/lokalise_rails_tasks.rake +++ b/lib/tasks/lokalise_rails_tasks.rake @@ -2,22 +2,33 @@ require 'rake' require 'lokalise_rails' +# Loads the configuration settings from the lokalise_rails configuration file within the Rails project. require "#{LokaliseRails::Utils.root}/config/lokalise_rails" +# Namespace for Rake tasks related to the LokaliseRails gem. +# These tasks facilitate the synchronization of localization files between the Rails project and the Lokalise platform. namespace :lokalise_rails do + # Imports translation files from Lokalise and integrates them into the current Rails project. + # This task utilizes the LokaliseManager to handle the import process according to the configuration specified + # in the GlobalConfig class. desc 'Imports translation files from Lokalise to the current Rails project' task :import do importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig) importer.import! rescue StandardError => e - abort e.inspect + # Aborts the task and prints the error message. + # Ensures that any exceptions raised during import are handled gracefully. + abort "Import failed: #{e.message}" end + # Exports translation files from the current Rails project to Lokalise. + # Similar to the import task, it leverages the LokaliseManager and uses the GlobalConfig for configuration settings. desc 'Exports translation files from the current Rails project to Lokalise' task :export do exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig) exporter.export! rescue StandardError => e - abort e.inspect + # Aborts the task and prints the error message. Provides clear feedback on why the export failed. + abort "Export failed: #{e.message}" end end diff --git a/spec/dummy/db/seeds.rb b/spec/dummy/db/seeds.rb index 8744e3c..ebd1889 100644 --- a/spec/dummy/db/seeds.rb +++ b/spec/dummy/db/seeds.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup). # From 424bea5257ac1f32f034d35c0fb3879596bf8973 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 10 May 2024 18:23:36 +0300 Subject: [PATCH 38/49] changelog [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1751fe..5eb9a3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## 7.0.1 +## 7.0.1 (10-May-2024) * Update documentation, minor code tweaks From 9d0f7b70b4dfa03b89a584d82fbe1ea6e26d01ef Mon Sep 17 00:00:00 2001 From: bodrovis Date: Thu, 13 Jun 2024 20:03:35 +0300 Subject: [PATCH 39/49] minor updates --- .rubocop.yml | 3 --- Gemfile | 2 +- spec/lib/lokalise_rails/global_config_spec.rb | 6 +++--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 60b503f..422ad1c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -72,9 +72,6 @@ RSpec/MultipleExpectations: RSpec/ExampleLength: Max: 35 -RSpec/FilePath: - Enabled: false - RSpec/MultipleMemoizedHelpers: Max: 10 diff --git a/Gemfile b/Gemfile index 37da4ad..239321f 100644 --- a/Gemfile +++ b/Gemfile @@ -12,7 +12,7 @@ group :test do gem 'rubocop', '~> 1.0' gem 'rubocop-performance', '~> 1.5' gem 'rubocop-rake', '~> 0.6' - gem 'rubocop-rspec', '~> 2.6' + gem 'rubocop-rspec', '~> 3.0' gem 'simplecov', '~> 0.22' gem 'simplecov-lcov', '~> 0.8' gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] diff --git a/spec/lib/lokalise_rails/global_config_spec.rb b/spec/lib/lokalise_rails/global_config_spec.rb index 2c9a638..14b1810 100644 --- a/spec/lib/lokalise_rails/global_config_spec.rb +++ b/spec/lib/lokalise_rails/global_config_spec.rb @@ -120,21 +120,21 @@ end it 'is possible to set skip_file_export' do - cond = ->(f) { f.nil? } + cond = lambda(&:nil?) allow(fake_class).to receive(:skip_file_export=).with(cond) fake_class.skip_file_export = cond expect(fake_class).to have_received(:skip_file_export=) end it 'is possible to set translations_loader' do - runner = ->(f) { f.to_json } + runner = lambda(&:to_json) allow(fake_class).to receive(:translations_loader=).with(runner) fake_class.translations_loader = runner expect(fake_class).to have_received(:translations_loader=) end it 'is possible to set translations_converter' do - runner = ->(f) { f.to_json } + runner = lambda(&:to_json) allow(fake_class).to receive(:translations_converter=).with(runner) fake_class.translations_converter = runner expect(fake_class).to have_received(:translations_converter=) From 431867280306265f54b86088024045bc8f219c03 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 1 Nov 2024 22:08:09 +0200 Subject: [PATCH 40/49] bump --- lib/generators/templates/lokalise_rails_config.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index b07284b..b371bbf 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -if defined?(LokaliseRails) && defined?(LokaliseRails::GlobalConfig) +if defined?(LokaliseRails::GlobalConfig) LokaliseRails::GlobalConfig.config do |c| # These are mandatory options that you must set before running rake tasks: # c.api_token = ENV['LOKALISE_API_TOKEN'] From 08e597b65faf7d387599c6f9ee955c43e5c9e648 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 1 Nov 2024 22:16:25 +0200 Subject: [PATCH 41/49] test with rails 8 --- .github/workflows/ci.yml | 6 ++++++ CHANGELOG.md | 4 ++++ Gemfile | 2 +- gemfiles/Gemfile-rails-7-2 | 18 ++++++++++++++++++ spec/dummy/config/application.rb | 4 +++- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gemfiles/Gemfile-rails-7-2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7c0df05..c88e6ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,11 +13,17 @@ jobs: gemfile: - Gemfile - gemfiles/Gemfile-rails-6-1 + - gemfiles/Gemfile-rails-7-2 ruby: - '3.0' - 3.1 - 3.2 - 3.3 + exclude: + - gemfile: Gemfile + ruby: '3.0' + - gemfile: Gemfile + ruby: 3.1 runs-on: ${{ matrix.os }} env: LOKALISE_API_TOKEN: 123abc diff --git a/CHANGELOG.md b/CHANGELOG.md index 5eb9a3c..2a4bab8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## Unreleased + +* Test with Rails 8 + ## 7.0.1 (10-May-2024) * Update documentation, minor code tweaks diff --git a/Gemfile b/Gemfile index 239321f..4831009 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gemspec group :test do gem 'dotenv', '~> 3.0' - gem 'rails', '~> 7.1' + gem 'rails', '8.0.0.rc2' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' diff --git a/gemfiles/Gemfile-rails-7-2 b/gemfiles/Gemfile-rails-7-2 new file mode 100644 index 0000000..3492039 --- /dev/null +++ b/gemfiles/Gemfile-rails-7-2 @@ -0,0 +1,18 @@ +source "https://rubygems.org" + +gemspec path: ".." + +group :test do + gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + gem 'dotenv', '~> 3.0' + gem 'rails', '~> 7.2' + gem 'rake', '~> 13.0' + gem 'rspec', '~> 3.6' + gem 'rubocop', '~> 1.0' + gem 'rubocop-performance', '~> 1.5' + gem 'rubocop-rspec', '~> 2.6' + gem 'rubocop-rake', '~> 0.6' + gem 'simplecov', '~> 0.22' + gem 'simplecov-lcov', '~> 0.8' + gem 'webmock', '~> 3.14' +end \ No newline at end of file diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb index 7933391..5a7e6f7 100644 --- a/spec/dummy/config/application.rb +++ b/spec/dummy/config/application.rb @@ -34,8 +34,10 @@ class Application < Rails::Application if Rails.gem_version < Gem::Version.new('7.0') config.load_defaults 6.1 - else + elsif Rails.gem_version < Gem::Version.new('8.0') config.load_defaults 7.0 + else + config.load_defaults 8.0 end end end From aa30397794c1c95e392a7be62264a1412b675002 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 1 Nov 2024 22:19:07 +0200 Subject: [PATCH 42/49] test with rails 7.1 --- .github/workflows/ci.yml | 5 +++++ gemfiles/Gemfile-rails-7-1 | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 gemfiles/Gemfile-rails-7-1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c88e6ff..c7ae716 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,6 +13,7 @@ jobs: gemfile: - Gemfile - gemfiles/Gemfile-rails-6-1 + - gemfiles/Gemfile-rails-7-1 - gemfiles/Gemfile-rails-7-2 ruby: - '3.0' @@ -20,6 +21,10 @@ jobs: - 3.2 - 3.3 exclude: + - gemfile: gemfiles/Gemfile-rails-7-2 + ruby: '3.0' + - gemfile: Gemfile + ruby: 3.1 - gemfile: Gemfile ruby: '3.0' - gemfile: Gemfile diff --git a/gemfiles/Gemfile-rails-7-1 b/gemfiles/Gemfile-rails-7-1 new file mode 100644 index 0000000..910cb59 --- /dev/null +++ b/gemfiles/Gemfile-rails-7-1 @@ -0,0 +1,18 @@ +source "https://rubygems.org" + +gemspec path: ".." + +group :test do + gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] + gem 'dotenv', '~> 3.0' + gem 'rails', '~> 7.1', '< 7.2' + gem 'rake', '~> 13.0' + gem 'rspec', '~> 3.6' + gem 'rubocop', '~> 1.0' + gem 'rubocop-performance', '~> 1.5' + gem 'rubocop-rspec', '~> 2.6' + gem 'rubocop-rake', '~> 0.6' + gem 'simplecov', '~> 0.22' + gem 'simplecov-lcov', '~> 0.8' + gem 'webmock', '~> 3.14' +end \ No newline at end of file From 94037d56b75ce7f0062377815ad25578f6c1f0b8 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Tue, 12 Nov 2024 15:57:04 +0200 Subject: [PATCH 43/49] v7.1.0 --- CHANGELOG.md | 3 ++- Gemfile | 2 +- LICENSE => LICENSE.md | 0 lib/lokalise_rails/version.rb | 2 +- lokalise_rails.gemspec | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) rename LICENSE => LICENSE.md (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a4bab8..9fb9734 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,9 @@ # Changelog -## Unreleased +## 7.1.0 (12-Nov-2024) * Test with Rails 8 +* Various updates ## 7.0.1 (10-May-2024) diff --git a/Gemfile b/Gemfile index 4831009..d1f2870 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gemspec group :test do gem 'dotenv', '~> 3.0' - gem 'rails', '8.0.0.rc2' + gem 'rails', '8.0.0' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' diff --git a/LICENSE b/LICENSE.md similarity index 100% rename from LICENSE rename to LICENSE.md diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 7618574..9c0e6d9 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '7.0.1' + VERSION = '7.1.0' end diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index 8530b8f..c261675 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.platform = Gem::Platform::RUBY spec.required_ruby_version = '>= 3.0' - spec.files = Dir['README.md', 'LICENSE', + spec.files = Dir['README.md', 'LICENSE.md', 'CHANGELOG.md', 'lib/**/*.rb', 'lib/**/*.rake', 'lokalise_rails.gemspec', '.github/*.md', From 8896540a1e40d3ff4976829795f02acd5622b66c Mon Sep 17 00:00:00 2001 From: "Elijah S. Krukowski" Date: Tue, 12 Nov 2024 15:57:35 +0200 Subject: [PATCH 44/49] Update README.md [skip ci] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f5b4a67..6c961d7 100644 --- a/README.md +++ b/README.md @@ -195,4 +195,4 @@ end ## License -Copyright (c) [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE). +Copyright (c) [Ilya Krukowski](http://bodrovis.tech). License type is [MIT](https://github.com/bodrovis/lokalise_rails/blob/master/LICENSE.md). From 2d79a0900ede45eff2d33eda18f3b233904b685e Mon Sep 17 00:00:00 2001 From: bodrovis Date: Fri, 29 Nov 2024 21:17:14 +0200 Subject: [PATCH 45/49] v8.0.0 --- CHANGELOG.md | 12 ++++++++++++ README.md | 4 ++-- lib/generators/templates/lokalise_rails_config.rb | 2 +- lib/lokalise_rails/version.rb | 2 +- lokalise_rails.gemspec | 2 +- spec/lib/lokalise_rails/global_config_spec.rb | 6 +++--- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9fb9734..758de92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## 8.0.0 (29-Nov-2024) + +* **Breaking change**: rename the `timeouts` config option 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. + +```ruby +additional_client_opts: { + open_timeout: 100, + timeout: 500, + api_host: 'http://example.com/api' +} +``` + ## 7.1.0 (12-Nov-2024) * Test with Rails 8 diff --git a/README.md b/README.md index 6c961d7..30c2518 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ exporter.export! ### Example: Multiple translation paths -Creating custom import/export script can come in really handy if you have a non-standard setup, for instance, your translation files are stored in multiple directories (not only in the default `./config/locales`. To overcome this problem, create a custom Rake task and provide as many importers/exporters as needed: +Creating custom import/export script can come in really handy if you have a non-standard setup, for instance, your translation files are stored in multiple directories (not only in the default `./config/locales`). To overcome this problem, create a custom Rake task and provide as many importers/exporters as needed: ```ruby require 'rake' @@ -146,7 +146,7 @@ LokaliseRails::GlobalConfig.config do |c| c.branch = 'develop' # Provide request timeouts for the Lokalise API client: - c.timeouts = {open_timeout: 5, timeout: 5} + c.additional_client_opts = {open_timeout: 5, timeout: 5} # Provide maximum number of retries for file exporting: c.max_retries_export = 5 diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index b371bbf..1d7672a 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -13,7 +13,7 @@ # c.branch = '' # Provide request timeouts for the Lokalise API client: - # c.timeouts = {open_timeout: nil, timeout: nil} + # c.additional_client_opts = {open_timeout: nil, timeout: nil} # Provide maximum number of retries for file exporting: # c.max_retries_export = 5 diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index 9c0e6d9..aac805b 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '7.1.0' + VERSION = '8.0.0' end diff --git a/lokalise_rails.gemspec b/lokalise_rails.gemspec index c261675..cd08b44 100644 --- a/lokalise_rails.gemspec +++ b/lokalise_rails.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.extra_rdoc_files = ['README.md'] spec.require_paths = ['lib'] - spec.add_dependency 'lokalise_manager', '~> 5.0' + spec.add_dependency 'lokalise_manager', '~> 6.0' spec.add_dependency 'zeitwerk', '~> 2.4' spec.metadata = { diff --git a/spec/lib/lokalise_rails/global_config_spec.rb b/spec/lib/lokalise_rails/global_config_spec.rb index 14b1810..adab4c8 100644 --- a/spec/lib/lokalise_rails/global_config_spec.rb +++ b/spec/lib/lokalise_rails/global_config_spec.rb @@ -81,12 +81,12 @@ end it 'is possible to set timeouts' do - allow(fake_class).to receive(:timeouts=).with(duck_type(:each)) - fake_class.timeouts = { + allow(fake_class).to receive(:additional_client_opts=).with(duck_type(:each)) + fake_class.additional_client_opts = { open_timeout: 100, timeout: 500 } - expect(fake_class).to have_received(:timeouts=) + expect(fake_class).to have_received(:additional_client_opts=) end it 'is possible to set import_safe_mode' do From 845b3600eacb2a6213f6c94775ea81c1be504d67 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 19 Feb 2025 16:42:56 +0200 Subject: [PATCH 46/49] test with async import --- .github/workflows/ci.yml | 1 + .rubocop.yml | 4 +- Gemfile | 2 +- .../templates/lokalise_rails_config.rb | 3 + spec/lib/tasks/import_task_spec.rb | 70 +++++++++++++++++-- 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c7ae716..8368826 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,7 @@ jobs: - 3.1 - 3.2 - 3.3 + - 3.4 exclude: - gemfile: gemfiles/Gemfile-rails-7-2 ruby: '3.0' diff --git a/.rubocop.yml b/.rubocop.yml index 422ad1c..e8d785e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,4 @@ -require: +plugins: - rubocop-performance - rubocop-rspec - rubocop-rake @@ -70,7 +70,7 @@ RSpec/MultipleExpectations: Max: 30 RSpec/ExampleLength: - Max: 35 + Max: 65 RSpec/MultipleMemoizedHelpers: Max: 10 diff --git a/Gemfile b/Gemfile index d1f2870..fbf7ff9 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ gemspec group :test do gem 'dotenv', '~> 3.0' - gem 'rails', '8.0.0' + gem 'rails', '~> 8.0' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' gem 'rubocop', '~> 1.0' diff --git a/lib/generators/templates/lokalise_rails_config.rb b/lib/generators/templates/lokalise_rails_config.rb index 1d7672a..8004993 100644 --- a/lib/generators/templates/lokalise_rails_config.rb +++ b/lib/generators/templates/lokalise_rails_config.rb @@ -34,6 +34,9 @@ # Safe mode for imports is disabled by default: # c.import_safe_mode = false + # Run imports asynchronously + # c.import_async = false + # Additional export options (only filename, contents, and lang_iso params are provided by default) # c.export_opts = {} diff --git a/spec/lib/tasks/import_task_spec.rb b/spec/lib/tasks/import_task_spec.rb index 8a68d1f..c068ab9 100644 --- a/spec/lib/tasks/import_task_spec.rb +++ b/spec/lib/tasks/import_task_spec.rb @@ -30,11 +30,13 @@ end describe 'import' do - it 'is callable' do - allow_project_id global_config, ENV.fetch('LOKALISE_PROJECT_ID', nil) do + let(:project_id) { ENV.fetch('LOKALISE_PROJECT_ID', nil) } + + it 'runs successfully' do + allow_project_id global_config, project_id do fake_bundle = "#{Dir.getwd}/spec/fixtures/trans.zip" - stub_request(:post, 'https://api.lokalise.com/api2/projects/672198945b7d72fc048021.15940510/files/download'). + stub_request(:post, "https://api.lokalise.com/api2/projects/#{project_id}/files/download"). with( body: JSON.dump({ format: 'ruby_yaml', @@ -48,7 +50,7 @@ to_return( status: 200, body: JSON.dump({ - project_id: '672198945b7d72fc048021.15940510', + project_id: project_id, bundle_url: fake_bundle }) ) @@ -63,6 +65,66 @@ end end + it 'runs successfully in async mode' do + process_id = '1efed57f-2720-6212-abd2-3e03040b6ae5' + + allow(global_config).to receive(:import_async).and_return(true) + + allow_project_id global_config, project_id do + fake_bundle = "#{Dir.getwd}/spec/fixtures/trans.zip" + + stub_request(:post, "https://api.lokalise.com/api2/projects/#{project_id}/files/async-download"). + with( + body: JSON.dump({ + format: 'ruby_yaml', + placeholder_format: 'icu', + yaml_include_root: true, + original_filenames: true, + directory_prefix: '', + indentation: '2sp' + }) + ). + to_return( + status: 200, + body: JSON.dump({ + process_id: process_id + }) + ) + + stub_request(:get, "https://api.lokalise.com/api2/projects/#{project_id}/processes/#{process_id}"). + to_return( + status: 200, + body: JSON.dump({ + process: { + process_id: '1efed57f-2720-6212-abd2-3e03040b6ae5', + type: 'async-export', + status: 'finished', + message: '', + created_by: 20_181, + created_by_email: 'bodrovis@protonmail.com', + created_at: '2023-05-16 12:00:49 (Etc/UTC)', + created_at_timestamp: 1_684_238_449, + details: { + file_size_kb: 1, + total_number_of_keys: 4, + download_url: fake_bundle + } + } + }) + ) + + expect { Rake::Task['lokalise_rails:import'].execute }.to output(/complete!/).to_stdout + + expect(count_translations).to eq(4) + + expect_file_exist loc_path, 'en/nested/main_en.yml' + expect_file_exist loc_path, 'en/nested/deep/secondary_en.yml' + expect_file_exist loc_path, 'ru/main_ru.yml' + end + + expect(global_config).to have_received(:import_async) + end + it 're-raises export errors' do allow_project_id global_config, 'fake' do stub_request(:post, 'https://api.lokalise.com/api2/projects/fake/files/download'). From caf2604bb94c7625af4a9bfaf075f67e433c099a Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 19 Feb 2025 16:46:06 +0200 Subject: [PATCH 47/49] fix tests --- spec/dummy/config/boot.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 7f0cc88..5dc95ab 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -2,4 +2,5 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +require "logger" # Fix for Rails 6 $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__) From 269dbfae03e3cf7f76f04c9f341b91e6b9727ec6 Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 19 Feb 2025 16:48:43 +0200 Subject: [PATCH 48/49] fix tests --- gemfiles/Gemfile-rails-6-1 | 1 + 1 file changed, 1 insertion(+) diff --git a/gemfiles/Gemfile-rails-6-1 b/gemfiles/Gemfile-rails-6-1 index 1a2608f..11cc4e7 100644 --- a/gemfiles/Gemfile-rails-6-1 +++ b/gemfiles/Gemfile-rails-6-1 @@ -5,6 +5,7 @@ gemspec path: ".." group :test do gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby] gem 'dotenv', '~> 2.5' + gem 'mutex_m', '~> 0.3.0' gem 'rails', '~> 6.1' gem 'rake', '~> 13.0' gem 'rspec', '~> 3.6' From c99b580ef4db37d2c8cdd0e93f6c461917c88aaf Mon Sep 17 00:00:00 2001 From: bodrovis Date: Wed, 19 Feb 2025 16:59:12 +0200 Subject: [PATCH 49/49] v8.0.1 --- CHANGELOG.md | 4 +++ .../lokalise_rails/install_generator.rb | 14 +++------ lib/lokalise_rails.rb | 21 +++++++------ lib/lokalise_rails/global_config.rb | 13 ++++---- lib/lokalise_rails/railtie.rb | 16 +++++----- lib/lokalise_rails/utils.rb | 23 +++++++------- lib/lokalise_rails/version.rb | 2 +- lib/tasks/lokalise_rails_tasks.rake | 30 ++++++++++--------- spec/dummy/config/boot.rb | 2 +- 9 files changed, 62 insertions(+), 63 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 758de92..aac5428 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 8.0.1 (19-Feb-2025) + +* Minor code tweaks, use latest `lokalise_manager` that now enables asynchronous imports + ## 8.0.0 (29-Nov-2024) * **Breaking change**: rename the `timeouts` config option 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. diff --git a/lib/generators/lokalise_rails/install_generator.rb b/lib/generators/lokalise_rails/install_generator.rb index c60481f..b183369 100644 --- a/lib/generators/lokalise_rails/install_generator.rb +++ b/lib/generators/lokalise_rails/install_generator.rb @@ -4,21 +4,15 @@ module LokaliseRails module Generators - # Generator that sets up the LokaliseRails configuration in a Rails application. - # It copies a predefined configuration template into the appropriate directory within the Rails application, - # making it easier for users to configure and use LokaliseRails. + # Installs the LokaliseRails configuration file in a Rails application. class InstallGenerator < Rails::Generators::Base - # Sets the directory containing the template files relative to this file's location. source_root File.expand_path('../templates', __dir__) - # Description of the generator's purpose, which is displayed in the Rails generators list. - desc 'Creates a LokaliseRails config file in your Rails application.' + # Adds a configuration file for LokaliseRails to the Rails application. + desc 'Creates a config/lokalise_rails.rb file for LokaliseRails.' - # The primary method of this generator, responsible for copying the LokaliseRails configuration template - # from the gem to the Rails application's config directory. This is where users can customize - # their Lokalise settings. + # Copies the configuration template to the application's config directory. def copy_config - # Copies the configuration template to the Rails application's config directory. template 'lokalise_rails_config.rb', "#{Rails.root}/config/lokalise_rails.rb" end end diff --git a/lib/lokalise_rails.rb b/lib/lokalise_rails.rb index 1862fb8..6a2776c 100644 --- a/lib/lokalise_rails.rb +++ b/lib/lokalise_rails.rb @@ -3,19 +3,22 @@ require 'zeitwerk' require 'lokalise_manager' -# Configure Zeitwerk loader specific for gem environments. This loader is set up to ignore certain files -# that should not be autoloaded, such as Rails-specific files or templates which are not part of the main load path. +# Configure Zeitwerk for managing gem autoloading. loader = Zeitwerk::Loader.for_gem -loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" # Ignore the Railtie in non-Rails environments -loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" # Ignore the generator templates -loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" # Ignore installation generator scripts + +# Ignore files that should not be autoloaded. +loader.ignore "#{__dir__}/lokalise_rails/railtie.rb" # Exclude Railtie when not in a Rails app +loader.ignore "#{__dir__}/generators/templates/lokalise_rails_config.rb" # Ignore generator templates +loader.ignore "#{__dir__}/generators/lokalise_rails/install_generator.rb" # Ignore installation generator + loader.setup -# Main module for the LokaliseRails gem. This module serves as the namespace for all components -# related to the LokaliseRails integration. It provides a structured way to manage translations -# through the Lokalise platform within Ruby on Rails applications. +# Main module for LokaliseRails. +# +# Serves as the namespace for all components of the LokaliseRails gem, +# providing tools for managing translations in Ruby on Rails applications. module LokaliseRails end -# Require the Railtie only if Rails is defined to integrate with Rails without manual configuration. +# Load Railtie if running within a Rails application. require_relative 'lokalise_rails/railtie' if defined?(Rails) diff --git a/lib/lokalise_rails/global_config.rb b/lib/lokalise_rails/global_config.rb index 6e31159..81a2024 100644 --- a/lib/lokalise_rails/global_config.rb +++ b/lib/lokalise_rails/global_config.rb @@ -1,17 +1,16 @@ # frozen_string_literal: true module LokaliseRails - # Inherits from LokaliseManager::GlobalConfig to provide a global configuration specific to the LokaliseRails gem. - # This class is primarily used to manage configuration settings that affect how the LokaliseRails gem operates - # within a Ruby on Rails application, particularly in managing locale paths. + # Extends `LokaliseManager::GlobalConfig` to provide a global configuration + # specific to the LokaliseRails gem in a Rails application. class GlobalConfig < LokaliseManager::GlobalConfig class << self - # Provides the path to the locales directory where translation files are stored. If not set explicitly, - # it defaults to the `config/locales` directory within the root of the application using this gem. + # Returns the path to the directory where translation files are stored. # - # @return [String] the path to the locales directory + # Defaults to `config/locales` under the Rails application root if not explicitly set. + # + # @return [String] Absolute path to the locales directory. def locales_path - # If @locales_path is not set, it defaults to a path under the application's root directory. @locales_path || "#{LokaliseRails::Utils.root}/config/locales" end end diff --git a/lib/lokalise_rails/railtie.rb b/lib/lokalise_rails/railtie.rb index 51a9be0..ad4578c 100644 --- a/lib/lokalise_rails/railtie.rb +++ b/lib/lokalise_rails/railtie.rb @@ -1,18 +1,16 @@ # frozen_string_literal: true module LokaliseRails - # The Railtie class in Rails is used to extend Rails' functionality within an application, or in this case, - # a gem. This Railtie is specifically used to add custom Rake tasks from the - # LokaliseRails gem into the Rails application. + # Extends Rails via Railtie to integrate LokaliseRails functionalities. # - # It leverages Rails' Railtie architecture to ensure the Rake - # tasks are loaded when the application boots up and Rake is invoked. + # This Railtie ensures that custom Rake tasks from the LokaliseRails gem + # are automatically available within a Rails application. class Railtie < Rails::Railtie - # Register Rake tasks that are defined within this gem. This block is called by Rails during the initialization - # process and ensures that all Rake tasks specific to LokaliseRails are available to the application. + # Registers custom Rake tasks for LokaliseRails. + # + # This ensures that the tasks are loaded when the Rails application boots + # and Rake is invoked. rake_tasks do - # Loads the Rake tasks from a file located relative to this file. Ensure this file exists and contains - # valid Rake task definitions specifically tailored for Lokalise integration. load 'tasks/lokalise_rails_tasks.rake' end end diff --git a/lib/lokalise_rails/utils.rb b/lib/lokalise_rails/utils.rb index f870798..9cae999 100644 --- a/lib/lokalise_rails/utils.rb +++ b/lib/lokalise_rails/utils.rb @@ -3,31 +3,30 @@ require 'pathname' module LokaliseRails - # Util methods + # Utility methods for LokaliseRails module Utils class << self # Retrieves the root directory of the current project. - # It attempts to find the Rails root directory if Rails is loaded. - # If Rails is not present, it defaults to the current working directory of the process. # - # @return [Pathname] A Pathname object pointing to the root directory of the project. + # If Rails is available, it returns `Rails.root`. Otherwise, it defaults + # to the current working directory. + # + # @return [Pathname] Pathname object pointing to the project root. def root - # Uses Pathname to create a robust path object from the rails_root or the current working directory. Pathname.new(rails_root || Dir.getwd) end - # Attempts to determine the root directory of a Rails - # project by checking the presence of Rails and its root method. - # If Rails is older and does not have the root method, it falls back to the RAILS_ROOT constant if defined. + # Determines the root directory of a Rails project. + # + # - Uses `Rails.root` if available. + # - Falls back to `RAILS_ROOT` for older Rails versions. + # - Returns `nil` if Rails is not present. # - # @return [String, nil] the path to the root directory if Rails is defined, or nil if it cannot be determined. + # @return [String, nil] Path to the root directory or `nil` if not found. def rails_root - # First, check if Rails.root is defined and return its path if available. return ::Rails.root.to_s if defined?(::Rails.root) && ::Rails.root - # Fallback to the RAILS_ROOT constant from older Rails versions. return RAILS_ROOT.to_s if defined?(RAILS_ROOT) - # Returns nil if none of the above are defined, indicating Rails is not present. nil end end diff --git a/lib/lokalise_rails/version.rb b/lib/lokalise_rails/version.rb index aac805b..f6de3ba 100644 --- a/lib/lokalise_rails/version.rb +++ b/lib/lokalise_rails/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module LokaliseRails - VERSION = '8.0.0' + VERSION = '8.0.1' end diff --git a/lib/tasks/lokalise_rails_tasks.rake b/lib/tasks/lokalise_rails_tasks.rake index 0d7e492..3b67743 100644 --- a/lib/tasks/lokalise_rails_tasks.rake +++ b/lib/tasks/lokalise_rails_tasks.rake @@ -2,33 +2,35 @@ require 'rake' require 'lokalise_rails' -# Loads the configuration settings from the lokalise_rails configuration file within the Rails project. -require "#{LokaliseRails::Utils.root}/config/lokalise_rails" +require "#{LokaliseRails::Utils.root}/config/lokalise_rails" # Loads configuration settings for LokaliseRails -# Namespace for Rake tasks related to the LokaliseRails gem. -# These tasks facilitate the synchronization of localization files between the Rails project and the Lokalise platform. +# Rake tasks for syncing translation files between a Rails project and Lokalise. namespace :lokalise_rails do - # Imports translation files from Lokalise and integrates them into the current Rails project. - # This task utilizes the LokaliseManager to handle the import process according to the configuration specified - # in the GlobalConfig class. - desc 'Imports translation files from Lokalise to the current Rails project' + # Imports translations from Lokalise into the current Rails project. + # + # Uses LokaliseManager to fetch translations based on the configuration + # defined in `LokaliseRails::GlobalConfig`. + # + # @raise [StandardError] Prints an error message and aborts if the import fails. + desc 'Import translations from Lokalise into the Rails project' task :import do importer = LokaliseManager.importer({}, LokaliseRails::GlobalConfig) importer.import! rescue StandardError => e - # Aborts the task and prints the error message. - # Ensures that any exceptions raised during import are handled gracefully. abort "Import failed: #{e.message}" end - # Exports translation files from the current Rails project to Lokalise. - # Similar to the import task, it leverages the LokaliseManager and uses the GlobalConfig for configuration settings. - desc 'Exports translation files from the current Rails project to Lokalise' + # Exports translations from the Rails project to Lokalise. + # + # Uses LokaliseManager to push localization files based on the configuration + # in `LokaliseRails::GlobalConfig`. + # + # @raise [StandardError] Prints an error message and aborts if the export fails. + desc 'Export translations from the Rails project to Lokalise' task :export do exporter = LokaliseManager.exporter({}, LokaliseRails::GlobalConfig) exporter.export! rescue StandardError => e - # Aborts the task and prints the error message. Provides clear feedback on why the export failed. abort "Export failed: #{e.message}" end end diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb index 5dc95ab..0ae2ae1 100644 --- a/spec/dummy/config/boot.rb +++ b/spec/dummy/config/boot.rb @@ -2,5 +2,5 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__) require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) -require "logger" # Fix for Rails 6 +require 'logger' # Fix for Rails 6 $LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)