From 2f0e2d80bc5646ae00b641a7af562bad08884331 Mon Sep 17 00:00:00 2001 From: Bartosz Gaj Date: Fri, 23 Dec 2022 15:06:06 +0100 Subject: [PATCH 01/13] Rails 7.0 only --- .ruby-version | 2 +- Appraisals | 50 +-- CHANGELOG.md | 1 + README.md | 2 +- ...e_controller.rb => base_lit_controller.rb} | 3 +- .../lit/api/v1/locales_controller.rb | 4 +- .../api/v1/localization_keys_controller.rb | 4 +- .../lit/api/v1/localizations_controller.rb | 2 +- app/models/lit/localization.rb | 2 +- app/services/synchronize_source_service.rb | 2 +- .../_localizations_list.html.erb | 2 +- .../_previous_versions_rows.html.erb | 2 +- app/views/lit/localizations/edit.js.erb | 2 +- .../localizations/previous_versions.js.erb | 2 +- app/views/lit/localizations/update.js.erb | 2 +- app/views/lit/sources/index.html.erb | 2 +- app/views/lit/sources/show.html.erb | 2 +- gemfiles/rails_5.2.gemfile | 23 -- gemfiles/rails_5.2.gemfile.lock | 283 ----------------- gemfiles/rails_6.0.gemfile | 23 -- gemfiles/rails_6.0.gemfile.lock | 299 ------------------ .../{rails_6.1.gemfile => rails_7.0.gemfile} | 4 +- ....1.gemfile.lock => rails_7.0.gemfile.lock} | 242 +++++++------- lib/lit/cache.rb | 2 +- lib/lit/i18n_backend.rb | 2 +- test/dummy/config/application.rb | 4 - test/dummy/config/environments/development.rb | 5 - test/dummy/config/environments/test.rb | 8 - test/dummy/config/initializers/lit.rb | 4 +- .../dummy/config/initializers/secret_token.rb | 7 +- .../api/v1/localizations_controller_test.rb | 4 +- ...incomming_localizations_controller_test.rb | 2 +- .../functional/lit/locales_controller_test.rb | 14 + .../functional/lit/sources_controller_test.rb | 2 +- test/integration/lit/projects_test.rb | 6 +- test/unit/lit/incomming_localization_test.rb | 2 +- test/unit/lit/source_test.rb | 2 +- 37 files changed, 175 insertions(+), 849 deletions(-) rename app/controllers/lit/api/v1/{base_controller.rb => base_lit_controller.rb} (74%) delete mode 100644 gemfiles/rails_5.2.gemfile delete mode 100644 gemfiles/rails_5.2.gemfile.lock delete mode 100644 gemfiles/rails_6.0.gemfile delete mode 100644 gemfiles/rails_6.0.gemfile.lock rename gemfiles/{rails_6.1.gemfile => rails_7.0.gemfile} (88%) rename gemfiles/{rails_6.1.gemfile.lock => rails_7.0.gemfile.lock} (64%) diff --git a/.ruby-version b/.ruby-version index a4dd9dba..b0f2dcb3 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.4 +3.0.4 diff --git a/Appraisals b/Appraisals index 01263a2a..a9d4cba9 100644 --- a/Appraisals +++ b/Appraisals @@ -1,49 +1,7 @@ -appraise 'rails-5.2' do +appraise 'rails-7.0' do source 'https://rubygems.org' - gem 'rails', '~> 5.2.0' - gem 'devise' - gem 'pg', '~> 1.2.3' - gem 'redis' - gem 'capybara' - gem 'database_cleaner' - gem 'test_declarative' - gem 'mocha' - gem 'webmock' - gem 'sass-rails' - gem 'jquery-rails' - gem 'coffee-rails' - gem 'pry-rails' - gem 'rails-controller-testing' - gem 'minitest' - gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 1.2.4' -end - -appraise 'rails-6.0' do - source 'https://rubygems.org' - gem 'rails', '~> 6.0.3' - gem 'devise' - gem 'pg', '~> 1.2.3' - gem 'redis' - gem 'capybara' - gem 'database_cleaner' - gem 'test_declarative' - gem 'mocha' - gem 'webmock' - gem 'sass-rails' - gem 'jquery-rails' - gem 'coffee-rails' - gem 'pry-rails' - gem 'rails-controller-testing' - gem 'minitest' - gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 1.2.4' -end - -appraise 'rails-6.1' do - source 'https://rubygems.org' - gem 'rails', '~> 6.1.4.1' - gem 'devise' + gem 'rails', '~> 7.0.4' + gem 'devise', '~> 4.8.1' gem 'pg', '~> 1.2.3' gem 'redis' gem 'capybara' @@ -59,4 +17,4 @@ appraise 'rails-6.1' do gem 'minitest' gem 'm', '~> 1.5.0' gem 'google-cloud-translate', '~> 2.1.2' -end +end \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 86e86ab4..73c33ad7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +- Support for Rails 7.0 ## [WIP] - Efforts to use Vanilla JS and remove jQuery [WIP] diff --git a/README.md b/README.md index 6552dcfa..b9db3148 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,7 @@ Lit.store_request_keys = true 1. `gem install bundler && bundle install` - ensure Bundler and all required gems are installed 2. `bundle exec appraisal install` - install gems from appraisal's gemfiles 3. `cp test/dummy/config/database.yml.sample test/dummy/config/database.yml` - move a database.yml in place (remember to fill your DB credentials in it) -4. `RAILS_ENV=test bundle exec appraisal rails-5.2 rake db:setup` - setup lit DB (see test/config/database.yml); do it +4. `RAILS_ENV=test bundle exec appraisal rails-7.0 rake db:setup` - setup lit DB (see test/config/database.yml); do it only once, it does not matter which Rails version you use for `appraisal` 5. `bundle exec appraisal rake` - run the tests! diff --git a/app/controllers/lit/api/v1/base_controller.rb b/app/controllers/lit/api/v1/base_lit_controller.rb similarity index 74% rename from app/controllers/lit/api/v1/base_controller.rb rename to app/controllers/lit/api/v1/base_lit_controller.rb index 212b7993..d557783c 100644 --- a/app/controllers/lit/api/v1/base_controller.rb +++ b/app/controllers/lit/api/v1/base_lit_controller.rb @@ -1,9 +1,8 @@ module Lit module Api module V1 - class BaseController < ActionController::Base + class BaseLitController < ActionController::Base layout nil - respond_to :json if ::Rails::VERSION::MAJOR < 5 before_action :authenticate_requests! private diff --git a/app/controllers/lit/api/v1/locales_controller.rb b/app/controllers/lit/api/v1/locales_controller.rb index bddb2917..6473763f 100644 --- a/app/controllers/lit/api/v1/locales_controller.rb +++ b/app/controllers/lit/api/v1/locales_controller.rb @@ -1,9 +1,9 @@ -require_dependency 'lit/api/v1/base_controller' +require_dependency 'lit/api/v1/base_lit_controller' module Lit module Api module V1 - class LocalesController < Api::V1::BaseController + class LocalesController < Api::V1::BaseLitController def index @locales = Locale.all render json: @locales.as_json(root: false, only: %i[id locale]) diff --git a/app/controllers/lit/api/v1/localization_keys_controller.rb b/app/controllers/lit/api/v1/localization_keys_controller.rb index bea8b422..20edf2ba 100644 --- a/app/controllers/lit/api/v1/localization_keys_controller.rb +++ b/app/controllers/lit/api/v1/localization_keys_controller.rb @@ -1,7 +1,7 @@ -require_dependency 'lit/api/v1/base_controller' +require_dependency 'lit/api/v1/base_lit_controller' module Lit - class Api::V1::LocalizationKeysController < Api::V1::BaseController + class Api::V1::LocalizationKeysController < Api::V1::BaseLitController def index @localization_keys = fetch_localization_keys render json: @localization_keys.as_json( diff --git a/app/controllers/lit/api/v1/localizations_controller.rb b/app/controllers/lit/api/v1/localizations_controller.rb index c121449a..f35a379e 100644 --- a/app/controllers/lit/api/v1/localizations_controller.rb +++ b/app/controllers/lit/api/v1/localizations_controller.rb @@ -1,5 +1,5 @@ module Lit - class Api::V1::LocalizationsController < Api::V1::BaseController + class Api::V1::LocalizationsController < Api::V1::BaseLitController def index @localizations = fetch_localizations render json: diff --git a/app/models/lit/localization.rb b/app/models/lit/localization.rb index e1659fd4..d44e84f5 100644 --- a/app/models/lit/localization.rb +++ b/app/models/lit/localization.rb @@ -63,7 +63,7 @@ def locale_str end def last_change - updated_at.to_s(:db) + updated_at.to_fs(:db) end def update_default_value(value) diff --git a/app/services/synchronize_source_service.rb b/app/services/synchronize_source_service.rb index 8a12faff..42cc7b2b 100644 --- a/app/services/synchronize_source_service.rb +++ b/app/services/synchronize_source_service.rb @@ -11,7 +11,7 @@ def execute private def synchronize_localizations - after_date = @source.last_updated_at&.to_s(:db) + after_date = @source.last_updated_at&.to_fs(:db) result = interactor.send_request Lit::Source::LOCALIZATIONS_PATH, after: after_date return unless result&.is_a?(Array) result.each { |loc| synchronize_localization loc } diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index 8c245b37..f8b2a391 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -46,7 +46,7 @@ <% if localization %> - <%= draw_icon 'clock-o', title: "Last updated at #{localization.updated_at.to_s(:db)}" %> + <%= draw_icon 'clock-o', title: "Last updated at #{localization.updated_at.to_fs(:db)}" %> <%= link_to lit.previous_versions_localization_key_localization_path(lk, localization, format: :js), class: "js-show_prev_versions #{'hidden' unless versions?(localization)}", remote: true do %> <%= draw_icon 'random', title: I18n.t('lit.common.previous_versions', default: 'Previous versions') %> <% end %> diff --git a/app/views/lit/localizations/_previous_versions_rows.html.erb b/app/views/lit/localizations/_previous_versions_rows.html.erb index 8128dc08..8c2bfb48 100644 --- a/app/views/lit/localizations/_previous_versions_rows.html.erb +++ b/app/views/lit/localizations/_previous_versions_rows.html.erb @@ -7,7 +7,7 @@ <% @versions.each do |v| %> - <%= render :partial=>"/lit/localization_keys/localization_row", formats: ['html'], :locals=>{:localization=>v.translated_value} %> + <%= render :partial=>"/lit/localization_keys/localization_row", :locals=>{:localization=>v.translated_value} %> <%= I18n.l v.created_at, format: :long %> diff --git a/app/views/lit/localizations/edit.js.erb b/app/views/lit/localizations/edit.js.erb index 37ed6b6d..292e79d3 100644 --- a/app/views/lit/localizations/edit.js.erb +++ b/app/views/lit/localizations/edit.js.erb @@ -1,6 +1,6 @@ var $row = $('td.localization_row[data-id="<%= @localization.id %>"]'); $row.data('editing', 1); -$row.html("<%= ejs render(partial: 'form', formats: ['html']) %>"); +$row.html("<%= ejs render(partial: 'form') %>"); $row.find('textarea').focus(); <% if @localization.full_key.ends_with?('_html') -%> $row.find('.wysiwyg_switch').click(); diff --git a/app/views/lit/localizations/previous_versions.js.erb b/app/views/lit/localizations/previous_versions.js.erb index 5e8e37f3..6d8fcd8f 100644 --- a/app/views/lit/localizations/previous_versions.js.erb +++ b/app/views/lit/localizations/previous_versions.js.erb @@ -1,3 +1,3 @@ var row = $('.localization_versions_row[data-id="<%= @localization.id %>"]'); row.removeClass('hidden'); -row.children('td').html("<%= j render(:partial=>'previous_versions_rows', formats: ['html'], :locals=>{:localization=>@localization, :versions=>@versions}) %>"); +row.children('td').html("<%= j render(:partial=>'previous_versions_rows', :locals=>{:localization=>@localization, :versions=>@versions}) %>"); diff --git a/app/views/lit/localizations/update.js.erb b/app/views/lit/localizations/update.js.erb index ddebae21..fe8e867c 100644 --- a/app/views/lit/localizations/update.js.erb +++ b/app/views/lit/localizations/update.js.erb @@ -1,6 +1,6 @@ var $row = $('td.localization_row[data-id="<%= @localization.id %>"]'); $row.data('editing', 0); -$row.html("<%= ejs render(:partial=>"/lit/localization_keys/localization_row", formats: ['html'], :locals=>{:localization=>@localization.translated_value }) %>"); +$row.html("<%= ejs render(:partial=>"/lit/localization_keys/localization_row", :locals=>{:localization=>@localization.translated_value }) %>"); $row.siblings().find('.js-show_prev_versions').removeClass('hidden'); $('a.change_completed_<%= @localization.id %> input[type=checkbox]').prop("checked", true); diff --git a/app/views/lit/sources/index.html.erb b/app/views/lit/sources/index.html.erb index 851b884f..fe201738 100644 --- a/app/views/lit/sources/index.html.erb +++ b/app/views/lit/sources/index.html.erb @@ -11,7 +11,7 @@ <% @sources.each do |source| %> <%= link_to source.identifier, lit.source_path(source) %> - <%= source.last_updated_at.to_s(:db) unless source.last_updated_at.nil? %> + <%= source.last_updated_at.to_fs(:db) unless source.last_updated_at.nil? %> <%= source.last_change %> <%= link_to lit.source_incomming_localizations_path(source), :title=>t('lit.common.browse_incomming', :default=>"Browse incomming localizations") do %> diff --git a/app/views/lit/sources/show.html.erb b/app/views/lit/sources/show.html.erb index 359226ea..ce57f2f0 100644 --- a/app/views/lit/sources/show.html.erb +++ b/app/views/lit/sources/show.html.erb @@ -10,7 +10,7 @@ <%= @source.api_key %>
Last updated at: -<%= @source.last_updated_at.to_s(:db) unless @source.last_updated_at.nil? %> +<%= @source.last_updated_at.to_fs(:db) unless @source.last_updated_at.nil? %> <%= link_to '(touch!)', touch_source_path(@source), :method => :put, :data => { :confirm => 'Are you sure?' } %>
diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile deleted file mode 100644 index 39387ba9..00000000 --- a/gemfiles/rails_5.2.gemfile +++ /dev/null @@ -1,23 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 5.2.0" -gem "devise" -gem "pg", "~> 1.2.3" -gem "redis" -gem "capybara" -gem "database_cleaner" -gem "test_declarative" -gem "mocha" -gem "webmock" -gem "sass-rails" -gem "jquery-rails" -gem "coffee-rails" -gem "pry-rails" -gem "rails-controller-testing" -gem "minitest" -gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 1.2.4" - -gemspec path: "../" diff --git a/gemfiles/rails_5.2.gemfile.lock b/gemfiles/rails_5.2.gemfile.lock deleted file mode 100644 index 10012374..00000000 --- a/gemfiles/rails_5.2.gemfile.lock +++ /dev/null @@ -1,283 +0,0 @@ -PATH - remote: .. - specs: - lit (1.1.6) - coffee-rails - emoji_flag - jquery-rails - rails (>= 5.2.0) - sass-rails - -GEM - remote: https://rubygems.org/ - specs: - actioncable (5.2.6) - actionpack (= 5.2.6) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailer (5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (5.2.6) - actionview (= 5.2.6) - activesupport (= 5.2.6) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.2) - actionview (5.2.6) - activesupport (= 5.2.6) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.0.3) - activejob (5.2.6) - activesupport (= 5.2.6) - globalid (>= 0.3.6) - activemodel (5.2.6) - activesupport (= 5.2.6) - activerecord (5.2.6) - activemodel (= 5.2.6) - activesupport (= 5.2.6) - arel (>= 9.0) - activestorage (5.2.6) - actionpack (= 5.2.6) - activerecord (= 5.2.6) - marcel (~> 1.0.0) - activesupport (5.2.6) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) - bundler - rake - thor (>= 0.14.0) - arel (9.0.0) - bcrypt (3.1.16) - builder (3.2.4) - byebug (11.1.3) - capybara (3.35.3) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - coderay (1.1.3) - coffee-rails (5.0.0) - coffee-script (>= 2.2.0) - railties (>= 5.2.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) - crack (0.4.5) - rexml - crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) - faraday (0.17.4) - multipart-post (>= 1.2, < 3) - ffi (1.15.0) - globalid (1.0.0) - activesupport (>= 5.0) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.1.0) - google-cloud-translate (1.2.4) - faraday (~> 0.13) - google-cloud-core (~> 1.2) - googleauth (~> 0.6.2) - googleauth (0.6.7) - faraday (~> 0.12) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.7) - hashdiff (1.0.1) - i18n (1.8.11) - concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jwt (2.2.2) - loofah (2.13.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - m (1.5.1) - method_source (>= 0.6.7) - rake (>= 0.9.2.2) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - memoist (0.16.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minispec-metadata (2.0.0) - minitest - minitest (5.15.0) - minitest-vcr (1.4.0) - minispec-metadata (~> 2.0) - minitest (>= 4.7.5) - vcr (>= 2.9) - mocha (1.12.0) - multi_json (1.15.0) - multipart-post (2.1.1) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) - racc (~> 1.4) - orm_adapter (0.5.0) - os (1.1.1) - pg (1.2.3) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (5.2.6) - actioncable (= 5.2.6) - actionmailer (= 5.2.6) - actionpack (= 5.2.6) - actionview (= 5.2.6) - activejob (= 5.2.6) - activemodel (= 5.2.6) - activerecord (= 5.2.6) - activestorage (= 5.2.6) - activesupport (= 5.2.6) - bundler (>= 1.3.0) - railties (= 5.2.6) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (5.2.6) - actionpack (= 5.2.6) - activesupport (= 5.2.6) - method_source - rake (>= 0.8.7) - thor (>= 0.19.0, < 2.0) - rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test_declarative (0.0.6) - thor (1.1.0) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) - vcr (4.0.0) - warden (1.2.9) - rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) - -PLATFORMS - ruby - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - appraisal (~> 2.4.0) - capybara - coffee-rails - database_cleaner - devise - google-cloud-translate (~> 1.2.4) - jquery-rails - lit! - m (~> 1.5.0) - minitest - minitest-vcr (~> 1.4.0) - mocha - pg (~> 1.2.3) - pry-byebug (~> 3.9.0) - pry-rails - rails (~> 5.2.0) - rails-controller-testing - redis - sass-rails - test_declarative - vcr (~> 4.0.0) - webmock - -BUNDLED WITH - 2.2.25 diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile deleted file mode 100644 index 12c20b47..00000000 --- a/gemfiles/rails_6.0.gemfile +++ /dev/null @@ -1,23 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rails", "~> 6.0.3" -gem "devise" -gem "pg", "~> 1.2.3" -gem "redis" -gem "capybara" -gem "database_cleaner" -gem "test_declarative" -gem "mocha" -gem "webmock" -gem "sass-rails" -gem "jquery-rails" -gem "coffee-rails" -gem "pry-rails" -gem "rails-controller-testing" -gem "minitest" -gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 1.2.4" - -gemspec path: "../" diff --git a/gemfiles/rails_6.0.gemfile.lock b/gemfiles/rails_6.0.gemfile.lock deleted file mode 100644 index c6b575f9..00000000 --- a/gemfiles/rails_6.0.gemfile.lock +++ /dev/null @@ -1,299 +0,0 @@ -PATH - remote: .. - specs: - lit (1.1.6) - coffee-rails - emoji_flag - jquery-rails - rails (>= 5.2.0) - sass-rails - -GEM - remote: https://rubygems.org/ - specs: - actioncable (6.0.4.4) - actionpack (= 6.0.4.4) - nio4r (~> 2.0) - websocket-driver (>= 0.6.1) - actionmailbox (6.0.4.4) - actionpack (= 6.0.4.4) - activejob (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - mail (>= 2.7.1) - actionmailer (6.0.4.4) - actionpack (= 6.0.4.4) - actionview (= 6.0.4.4) - activejob (= 6.0.4.4) - mail (~> 2.5, >= 2.5.4) - rails-dom-testing (~> 2.0) - actionpack (6.0.4.4) - actionview (= 6.0.4.4) - activesupport (= 6.0.4.4) - rack (~> 2.0, >= 2.0.8) - rack-test (>= 0.6.3) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.0.4.4) - actionpack (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - nokogiri (>= 1.8.5) - actionview (6.0.4.4) - activesupport (= 6.0.4.4) - builder (~> 3.1) - erubi (~> 1.4) - rails-dom-testing (~> 2.0) - rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.0.4.4) - activesupport (= 6.0.4.4) - globalid (>= 0.3.6) - activemodel (6.0.4.4) - activesupport (= 6.0.4.4) - activerecord (6.0.4.4) - activemodel (= 6.0.4.4) - activesupport (= 6.0.4.4) - activestorage (6.0.4.4) - actionpack (= 6.0.4.4) - activejob (= 6.0.4.4) - activerecord (= 6.0.4.4) - marcel (~> 1.0.0) - activesupport (6.0.4.4) - concurrent-ruby (~> 1.0, >= 1.0.2) - i18n (>= 0.7, < 2) - minitest (~> 5.1) - tzinfo (~> 1.1) - zeitwerk (~> 2.2, >= 2.2.2) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) - bundler - rake - thor (>= 0.14.0) - bcrypt (3.1.16) - builder (3.2.4) - byebug (11.1.3) - capybara (3.35.3) - addressable - mini_mime (>= 0.1.3) - nokogiri (~> 1.8) - rack (>= 1.6.0) - rack-test (>= 0.6.3) - regexp_parser (>= 1.5, < 3.0) - xpath (~> 3.2) - coderay (1.1.3) - coffee-rails (5.0.0) - coffee-script (>= 2.2.0) - railties (>= 5.2.0) - coffee-script (2.4.1) - coffee-script-source - execjs - coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) - crack (0.4.5) - rexml - crass (1.0.6) - database_cleaner (2.0.1) - database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) - activerecord (>= 5.a) - database_cleaner-core (~> 2.0.0) - database_cleaner-core (2.0.1) - devise (4.7.3) - bcrypt (~> 3.0) - orm_adapter (~> 0.1) - railties (>= 4.1.0) - responders - warden (~> 1.2.3) - emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) - faraday (0.17.4) - multipart-post (>= 1.2, < 3) - ffi (1.15.0) - globalid (1.0.0) - activesupport (>= 5.0) - google-cloud-core (1.6.0) - google-cloud-env (~> 1.0) - google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.1.0) - google-cloud-translate (1.2.4) - faraday (~> 0.13) - google-cloud-core (~> 1.2) - googleauth (~> 0.6.2) - googleauth (0.6.7) - faraday (~> 0.12) - jwt (>= 1.4, < 3.0) - memoist (~> 0.16) - multi_json (~> 1.11) - os (>= 0.9, < 2.0) - signet (~> 0.7) - hashdiff (1.0.1) - i18n (1.8.11) - concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) - rails-dom-testing (>= 1, < 3) - railties (>= 4.2.0) - thor (>= 0.14, < 2.0) - jwt (2.2.2) - loofah (2.13.0) - crass (~> 1.0.2) - nokogiri (>= 1.5.9) - m (1.5.1) - method_source (>= 0.6.7) - rake (>= 0.9.2.2) - mail (2.7.1) - mini_mime (>= 0.1.1) - marcel (1.0.2) - memoist (0.16.2) - method_source (1.0.0) - mini_mime (1.1.2) - mini_portile2 (2.6.1) - minispec-metadata (2.0.0) - minitest - minitest (5.15.0) - minitest-vcr (1.4.0) - minispec-metadata (~> 2.0) - minitest (>= 4.7.5) - vcr (>= 2.9) - mocha (1.12.0) - multi_json (1.15.0) - multipart-post (2.1.1) - nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) - racc (~> 1.4) - orm_adapter (0.5.0) - os (1.1.1) - pg (1.2.3) - pry (0.13.1) - coderay (~> 1.1) - method_source (~> 1.0) - pry-byebug (3.9.0) - byebug (~> 11.0) - pry (~> 0.13.0) - pry-rails (0.3.9) - pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.0.4.4) - actioncable (= 6.0.4.4) - actionmailbox (= 6.0.4.4) - actionmailer (= 6.0.4.4) - actionpack (= 6.0.4.4) - actiontext (= 6.0.4.4) - actionview (= 6.0.4.4) - activejob (= 6.0.4.4) - activemodel (= 6.0.4.4) - activerecord (= 6.0.4.4) - activestorage (= 6.0.4.4) - activesupport (= 6.0.4.4) - bundler (>= 1.3.0) - railties (= 6.0.4.4) - sprockets-rails (>= 2.0.0) - rails-controller-testing (1.0.5) - actionpack (>= 5.0.1.rc1) - actionview (>= 5.0.1.rc1) - activesupport (>= 5.0.1.rc1) - rails-dom-testing (2.0.3) - activesupport (>= 4.2.0) - nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.0.4.4) - actionpack (= 6.0.4.4) - activesupport (= 6.0.4.4) - method_source - rake (>= 0.8.7) - thor (>= 0.20.3, < 2.0) - rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) - responders (3.0.1) - actionpack (>= 5.0) - railties (>= 5.0) - rexml (3.2.5) - sass-rails (6.0.0) - sassc-rails (~> 2.1, >= 2.1.1) - sassc (2.4.0) - ffi (~> 1.9) - sassc-rails (2.1.2) - railties (>= 4.0.0) - sassc (>= 2.0) - sprockets (> 3.0) - sprockets-rails - tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) - jwt (>= 1.5, < 3.0) - multi_json (~> 1.10) - sprockets (4.0.2) - concurrent-ruby (~> 1.0) - rack (> 1, < 3) - sprockets-rails (3.4.2) - actionpack (>= 5.2) - activesupport (>= 5.2) - sprockets (>= 3.0.0) - test_declarative (0.0.6) - thor (1.1.0) - thread_safe (0.3.6) - tilt (2.0.10) - tzinfo (1.2.9) - thread_safe (~> 0.1) - vcr (4.0.0) - warden (1.2.9) - rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) - crack (>= 0.3.2) - hashdiff (>= 0.4.0, < 2.0.0) - websocket-driver (0.7.5) - websocket-extensions (>= 0.1.0) - websocket-extensions (0.1.5) - xpath (3.2.0) - nokogiri (~> 1.8) - zeitwerk (2.5.1) - -PLATFORMS - ruby - x86_64-darwin-20 - x86_64-linux - -DEPENDENCIES - appraisal (~> 2.4.0) - capybara - coffee-rails - database_cleaner - devise - google-cloud-translate (~> 1.2.4) - jquery-rails - lit! - m (~> 1.5.0) - minitest - minitest-vcr (~> 1.4.0) - mocha - pg (~> 1.2.3) - pry-byebug (~> 3.9.0) - pry-rails - rails (~> 6.0.3) - rails-controller-testing - redis - sass-rails - test_declarative - vcr (~> 4.0.0) - webmock - -BUNDLED WITH - 2.2.25 diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_7.0.gemfile similarity index 88% rename from gemfiles/rails_6.1.gemfile rename to gemfiles/rails_7.0.gemfile index 81a097c8..b13f7ba0 100644 --- a/gemfiles/rails_6.1.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -2,8 +2,8 @@ source "https://rubygems.org" -gem "rails", "~> 6.1.4.1" -gem "devise" +gem "rails", "~> 7.0.4" +gem "devise", "~> 4.8.1" gem "pg", "~> 1.2.3" gem "redis" gem "capybara" diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock similarity index 64% rename from gemfiles/rails_6.1.gemfile.lock rename to gemfiles/rails_7.0.gemfile.lock index f4be92b0..a6069207 100644 --- a/gemfiles/rails_6.1.gemfile.lock +++ b/gemfiles/rails_7.0.gemfile.lock @@ -11,72 +11,78 @@ PATH GEM remote: https://rubygems.org/ specs: - actioncable (6.1.4.4) - actionpack (= 6.1.4.4) - activesupport (= 6.1.4.4) + actioncable (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) nio4r (~> 2.0) websocket-driver (>= 0.6.1) - actionmailbox (6.1.4.4) - actionpack (= 6.1.4.4) - activejob (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) + actionmailbox (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) mail (>= 2.7.1) - actionmailer (6.1.4.4) - actionpack (= 6.1.4.4) - actionview (= 6.1.4.4) - activejob (= 6.1.4.4) - activesupport (= 6.1.4.4) + net-imap + net-pop + net-smtp + actionmailer (7.0.4) + actionpack (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activesupport (= 7.0.4) mail (~> 2.5, >= 2.5.4) + net-imap + net-pop + net-smtp rails-dom-testing (~> 2.0) - actionpack (6.1.4.4) - actionview (= 6.1.4.4) - activesupport (= 6.1.4.4) - rack (~> 2.0, >= 2.0.9) + actionpack (7.0.4) + actionview (= 7.0.4) + activesupport (= 7.0.4) + rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) - actiontext (6.1.4.4) - actionpack (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) + actiontext (7.0.4) + actionpack (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) + globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (6.1.4.4) - activesupport (= 6.1.4.4) + actionview (7.0.4) + activesupport (= 7.0.4) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) - activejob (6.1.4.4) - activesupport (= 6.1.4.4) + activejob (7.0.4) + activesupport (= 7.0.4) globalid (>= 0.3.6) - activemodel (6.1.4.4) - activesupport (= 6.1.4.4) - activerecord (6.1.4.4) - activemodel (= 6.1.4.4) - activesupport (= 6.1.4.4) - activestorage (6.1.4.4) - actionpack (= 6.1.4.4) - activejob (= 6.1.4.4) - activerecord (= 6.1.4.4) - activesupport (= 6.1.4.4) - marcel (~> 1.0.0) + activemodel (7.0.4) + activesupport (= 7.0.4) + activerecord (7.0.4) + activemodel (= 7.0.4) + activesupport (= 7.0.4) + activestorage (7.0.4) + actionpack (= 7.0.4) + activejob (= 7.0.4) + activerecord (= 7.0.4) + activesupport (= 7.0.4) + marcel (~> 1.0) mini_mime (>= 1.1.0) - activesupport (6.1.4.4) + activesupport (7.0.4) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) - zeitwerk (~> 2.3) - addressable (2.7.0) - public_suffix (>= 2.0.2, < 5.0) - appraisal (2.4.0) + addressable (2.8.1) + public_suffix (>= 2.0.2, < 6.0) + appraisal (2.4.1) bundler rake thor (>= 0.14.0) - bcrypt (3.1.16) + bcrypt (3.1.18) builder (3.2.4) byebug (11.1.3) capybara (3.35.3) @@ -95,7 +101,7 @@ GEM coffee-script-source execjs coffee-script-source (1.12.2) - concurrent-ruby (1.1.9) + concurrent-ruby (1.1.10) crack (0.4.5) rexml crass (1.0.6) @@ -105,15 +111,16 @@ GEM activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) - devise (4.7.3) + date (3.3.3) + devise (4.8.1) bcrypt (~> 3.0) orm_adapter (~> 0.1) railties (>= 4.1.0) responders warden (~> 1.2.3) emoji_flag (0.1.1) - erubi (1.10.0) - execjs (2.7.0) + erubi (1.12.0) + execjs (2.8.1) faraday (1.8.0) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) @@ -133,15 +140,15 @@ GEM faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) - ffi (1.15.0) + ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) google-cloud-core (1.6.0) google-cloud-env (~> 1.0) google-cloud-errors (~> 1.0) - google-cloud-env (1.5.0) - faraday (>= 0.17.3, < 2.0) - google-cloud-errors (1.2.0) + google-cloud-env (1.6.0) + faraday (>= 0.17.3, < 3.0) + google-cloud-errors (1.3.0) google-cloud-translate (2.1.2) faraday (>= 0.17.3, < 2.0) google-cloud-core (~> 1.2) @@ -155,8 +162,6 @@ GEM googleauth (~> 0.9) grpc (~> 1.24) rly (~> 0.2.3) - google-protobuf (3.17.3) - google-protobuf (3.17.3-universal-darwin) google-protobuf (3.17.3-x86_64-linux) googleapis-common-protos (1.3.12) google-protobuf (~> 3.14) @@ -171,56 +176,56 @@ GEM multi_json (~> 1.11) os (>= 0.9, < 2.0) signet (~> 0.15) - grpc (1.41.0) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) - grpc (1.41.0-universal-darwin) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) grpc (1.41.0-x86_64-linux) google-protobuf (~> 3.17) googleapis-common-protos-types (~> 1.0) hashdiff (1.0.1) - i18n (1.8.11) + i18n (1.12.0) concurrent-ruby (~> 1.0) - jquery-rails (4.4.0) + jquery-rails (4.5.1) rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jwt (2.3.0) - loofah (2.13.0) + jwt (2.5.0) + loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) m (1.5.1) method_source (>= 0.6.7) rake (>= 0.9.2.2) - mail (2.7.1) + mail (2.8.0) mini_mime (>= 0.1.1) + net-imap + net-pop + net-smtp marcel (1.0.2) memoist (0.16.2) method_source (1.0.0) mini_mime (1.1.2) - mini_portile2 (2.6.1) minispec-metadata (2.0.0) minitest - minitest (5.15.0) + minitest (5.16.3) minitest-vcr (1.4.0) minispec-metadata (~> 2.0) minitest (>= 4.7.5) vcr (>= 2.9) - mocha (1.12.0) + mocha (1.16.1) multi_json (1.15.0) - multipart-post (2.1.1) + multipart-post (2.2.3) + net-imap (0.3.4) + date + net-protocol + net-pop (0.1.2) + net-protocol + net-protocol (0.2.1) + timeout + net-smtp (0.3.3) + net-protocol nio4r (2.5.8) - nokogiri (1.12.5) - mini_portile2 (~> 2.6.1) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-darwin) - racc (~> 1.4) - nokogiri (1.12.5-x86_64-linux) + nokogiri (1.13.10-x86_64-linux) racc (~> 1.4) orm_adapter (0.5.0) - os (1.1.1) + os (1.1.4) pg (1.2.3) pry (0.13.1) coderay (~> 1.1) @@ -230,26 +235,25 @@ GEM pry (~> 0.13.0) pry-rails (0.3.9) pry (>= 0.10.4) - public_suffix (4.0.6) - racc (1.6.0) - rack (2.2.3) - rack-test (1.1.0) - rack (>= 1.0, < 3) - rails (6.1.4.4) - actioncable (= 6.1.4.4) - actionmailbox (= 6.1.4.4) - actionmailer (= 6.1.4.4) - actionpack (= 6.1.4.4) - actiontext (= 6.1.4.4) - actionview (= 6.1.4.4) - activejob (= 6.1.4.4) - activemodel (= 6.1.4.4) - activerecord (= 6.1.4.4) - activestorage (= 6.1.4.4) - activesupport (= 6.1.4.4) + public_suffix (5.0.1) + racc (1.6.2) + rack (2.2.4) + rack-test (2.0.2) + rack (>= 1.3) + rails (7.0.4) + actioncable (= 7.0.4) + actionmailbox (= 7.0.4) + actionmailer (= 7.0.4) + actionpack (= 7.0.4) + actiontext (= 7.0.4) + actionview (= 7.0.4) + activejob (= 7.0.4) + activemodel (= 7.0.4) + activerecord (= 7.0.4) + activestorage (= 7.0.4) + activesupport (= 7.0.4) bundler (>= 1.15.0) - railties (= 6.1.4.4) - sprockets-rails (>= 2.0.0) + railties (= 7.0.4) rails-controller-testing (1.0.5) actionpack (>= 5.0.1.rc1) actionview (>= 5.0.1.rc1) @@ -257,17 +261,18 @@ GEM rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) - rails-html-sanitizer (1.4.2) - loofah (~> 2.3) - railties (6.1.4.4) - actionpack (= 6.1.4.4) - activesupport (= 6.1.4.4) + rails-html-sanitizer (1.4.4) + loofah (~> 2.19, >= 2.19.1) + railties (7.0.4) + actionpack (= 7.0.4) + activesupport (= 7.0.4) method_source - rake (>= 0.13) + rake (>= 12.2) thor (~> 1.0) + zeitwerk (~> 2.5) rake (13.0.6) - redis (4.2.5) - regexp_parser (2.1.1) + redis (4.8.0) + regexp_parser (2.6.1) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) @@ -284,28 +289,29 @@ GEM sprockets (> 3.0) sprockets-rails tilt - signet (0.15.0) - addressable (~> 2.3) - faraday (>= 0.17.3, < 2.0) + signet (0.17.0) + addressable (~> 2.8) + faraday (>= 0.17.5, < 3.a) jwt (>= 1.5, < 3.0) multi_json (~> 1.10) - sprockets (4.0.2) + sprockets (4.2.0) concurrent-ruby (~> 1.0) - rack (> 1, < 3) + rack (>= 2.2.4, < 4) sprockets-rails (3.4.2) actionpack (>= 5.2) activesupport (>= 5.2) sprockets (>= 3.0.0) test_declarative (0.0.6) - thor (1.1.0) - tilt (2.0.10) - tzinfo (2.0.4) + thor (1.2.1) + tilt (2.0.11) + timeout (0.3.1) + tzinfo (2.0.5) concurrent-ruby (~> 1.0) vcr (4.0.0) warden (1.2.9) rack (>= 2.0.9) - webmock (3.12.2) - addressable (>= 2.3.6) + webmock (3.18.1) + addressable (>= 2.8.0) crack (>= 0.3.2) hashdiff (>= 0.4.0, < 2.0.0) websocket-driver (0.7.5) @@ -313,11 +319,9 @@ GEM websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.5.1) + zeitwerk (2.6.6) PLATFORMS - ruby - x86_64-darwin-20 x86_64-linux DEPENDENCIES @@ -325,7 +329,7 @@ DEPENDENCIES capybara coffee-rails database_cleaner - devise + devise (~> 4.8.1) google-cloud-translate (~> 2.1.2) jquery-rails lit! @@ -336,7 +340,7 @@ DEPENDENCIES pg (~> 1.2.3) pry-byebug (~> 3.9.0) pry-rails - rails (~> 6.1.4.1) + rails (~> 7.0.4) rails-controller-testing redis sass-rails @@ -345,4 +349,4 @@ DEPENDENCIES webmock BUNDLED WITH - 2.2.25 + 2.2.33 diff --git a/lib/lit/cache.rb b/lib/lit/cache.rb index ed1cb9d0..37a43f31 100644 --- a/lib/lit/cache.rb +++ b/lib/lit/cache.rb @@ -177,7 +177,7 @@ def stop_hits_counter end def restore_hits_counter - @hits_counter_working = true + @hits_counter_working = Lit.hits_counter_enabled end def localization_cache diff --git a/lib/lit/i18n_backend.rb b/lib/lit/i18n_backend.rb index a3e310b8..d8231aa9 100644 --- a/lib/lit/i18n_backend.rb +++ b/lib/lit/i18n_backend.rb @@ -26,7 +26,7 @@ def translate(locale, key, options = {}) content = super(locale, key, options) if on_rails_6_1_or_higher? - @untranslated_key = key if key.present? && options[:default].instance_of?(Object) + @untranslated_key = key if key.present? && options[:default].instance_of?(Integer) if key.nil? && options[:lit_default_copy].present? update_default_localization(locale, options) diff --git a/test/dummy/config/application.rb b/test/dummy/config/application.rb index 4060b394..de14eae4 100644 --- a/test/dummy/config/application.rb +++ b/test/dummy/config/application.rb @@ -43,10 +43,6 @@ class Application < Rails::Application # like if you have constraints or database-specific column types # config.active_record.schema_format = :sql - if ::Rails::VERSION::MAJOR == 4 - config.active_record.raise_in_transactional_callbacks = true - end - # Enable the asset pipeline config.assets.enabled = true diff --git a/test/dummy/config/environments/development.rb b/test/dummy/config/environments/development.rb index 9fedb0dc..19920c4a 100644 --- a/test/dummy/config/environments/development.rb +++ b/test/dummy/config/environments/development.rb @@ -22,11 +22,6 @@ # Only use best-standards-support built into browsers config.action_dispatch.best_standards_support = :builtin - if ::Rails::VERSION::MAJOR < 4 - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - end - # Do not compress assets config.assets.compress = false diff --git a/test/dummy/config/environments/test.rb b/test/dummy/config/environments/test.rb index 46b501c7..0d72d664 100644 --- a/test/dummy/config/environments/test.rb +++ b/test/dummy/config/environments/test.rb @@ -22,11 +22,6 @@ config.static_cache_control = 'public, max-age=3600' end - if ::Rails::VERSION::MAJOR < 4 - # Log error messages when you accidentally call methods on nil - config.whiny_nils = true - end - # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false @@ -43,9 +38,6 @@ config.action_mailer.delivery_method = :test if ::Rails::VERSION::MAJOR < 4 - # Raise exception on mass assignment protection for Active Record models - config.active_record.mass_assignment_sanitizer = :strict - else config.i18n.enforce_available_locales = false end diff --git a/test/dummy/config/initializers/lit.rb b/test/dummy/config/initializers/lit.rb index 4083236d..48093b63 100644 --- a/test/dummy/config/initializers/lit.rb +++ b/test/dummy/config/initializers/lit.rb @@ -6,4 +6,6 @@ Lit.api_enabled = true Lit.api_key = 'ala' Lit.all_translations_are_html_safe = true -Lit.init +Rails.application.config.after_initialize do + Lit.init +end diff --git a/test/dummy/config/initializers/secret_token.rb b/test/dummy/config/initializers/secret_token.rb index 3ec79366..1413917e 100644 --- a/test/dummy/config/initializers/secret_token.rb +++ b/test/dummy/config/initializers/secret_token.rb @@ -4,8 +4,5 @@ # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. -if ::Rails::VERSION::MAJOR < 4 - Dummy::Application.config.secret_token = '362b82703c06793883c00b35de475258c908cc0eadb14390268f1f17e40a60a53af28751de4cababe25abf13b11138051c8311dcdb802f8b581e60e1c24f70af' -else - Dummy::Application.config.secret_key_base = '362b82703c06793883c00b35de475258c908cc0eadb14390268f1f17e40a60a53af28751de4cababe25abf13b11138051c8311dcdb802f8b581e60e1c24f70af' -end + +Dummy::Application.config.secret_key_base = '362b82703c06793883c00b35de475258c908cc0eadb14390268f1f17e40a60a53af28751de4cababe25abf13b11138051c8311dcdb802f8b581e60e1c24f70af' diff --git a/test/functional/lit/api/v1/localizations_controller_test.rb b/test/functional/lit/api/v1/localizations_controller_test.rb index 44ae7143..5c890a46 100644 --- a/test/functional/lit/api/v1/localizations_controller_test.rb +++ b/test/functional/lit/api/v1/localizations_controller_test.rb @@ -33,7 +33,7 @@ def teardown l.translated_value = 'test' l.is_changed = true l.save - get :index, params: { format: :json, after: 2.seconds.ago.to_s(:db) } + get :index, params: { format: :json, after: 2.seconds.ago.to_fs(:db) } assert_response :success assert_equal 1, assigns(:localizations).count assert response.body =~ /#{l.value}/ @@ -48,7 +48,7 @@ def teardown get :last_change, format: :json assert_response :success assert_equal l, assigns(:localization) - assert response.body =~ /#{l.updated_at.to_s(:db)}/ + assert response.body =~ /#{l.updated_at.to_fs(:db)}/ end end diff --git a/test/functional/lit/incomming_localizations_controller_test.rb b/test/functional/lit/incomming_localizations_controller_test.rb index 7186554d..5c40ed0d 100644 --- a/test/functional/lit/incomming_localizations_controller_test.rb +++ b/test/functional/lit/incomming_localizations_controller_test.rb @@ -8,7 +8,7 @@ def setup Lit.authentication_function = nil @routes = Lit::Engine.routes stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) + to_return(body: { last_change: 1.hour.ago.to_fs(:db) }.to_json) @source = lit_sources(:test) end diff --git a/test/functional/lit/locales_controller_test.rb b/test/functional/lit/locales_controller_test.rb index 586e7b86..806469ba 100644 --- a/test/functional/lit/locales_controller_test.rb +++ b/test/functional/lit/locales_controller_test.rb @@ -9,6 +9,20 @@ class LocalesControllerTest < ActionController::TestCase @locale = Locale.first_or_create(locale: 'en') end + test 'should restore hits counter status to true' do + Lit.hits_counter_enabled = true + get :index + assert_response :success + assert Lit.init.cache.instance_variable_get(:@hits_counter_working) + end + + test 'should restore hits counter status to false' do + Lit.hits_counter_enabled = false + get :index + assert_response :success + assert_equal Lit.init.cache.instance_variable_get(:@hits_counter_working), false + end + test 'should get index' do get :index assert_response :success diff --git a/test/functional/lit/sources_controller_test.rb b/test/functional/lit/sources_controller_test.rb index 96df2bd5..127b7d0d 100644 --- a/test/functional/lit/sources_controller_test.rb +++ b/test/functional/lit/sources_controller_test.rb @@ -8,7 +8,7 @@ class SourcesControllerTest < ActionController::TestCase Lit.authentication_function = nil @routes = Lit::Engine.routes stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) + to_return(body: { last_change: 1.hour.ago.to_fs(:db) }.to_json) @source = lit_sources(:test) end diff --git a/test/integration/lit/projects_test.rb b/test/integration/lit/projects_test.rb index d88aef34..629a9856 100644 --- a/test/integration/lit/projects_test.rb +++ b/test/integration/lit/projects_test.rb @@ -30,11 +30,7 @@ class ProjectsTest < ActionDispatch::IntegrationTest test 'should have error message humanized' do Lit.humanize_key = true - if ::Rails::VERSION::MAJOR < 5 - post '/en/projects', project: { name: '' } - else - post '/en/projects', params: { project: { name: '' } } - end + post '/en/projects', params: { project: { name: '' } } locale = Lit::Locale.where('locale=?', 'en').first localization_key = Lit::LocalizationKey.find_by_localization_key! 'activerecord.errors.models.project.attributes.name.blank' localization = localization_key.localizations.where(locale_id: locale.id).first diff --git a/test/unit/lit/incomming_localization_test.rb b/test/unit/lit/incomming_localization_test.rb index 9b978d87..99479e6a 100644 --- a/test/unit/lit/incomming_localization_test.rb +++ b/test/unit/lit/incomming_localization_test.rb @@ -5,7 +5,7 @@ class IncommingLocalizationTest < ActiveSupport::TestCase def setup DatabaseCleaner.clean_with :truncation stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json').to_return( - body: { last_change: 1.hour.ago.to_s(:db) }.to_json, + body: { last_change: 1.hour.ago.to_fs(:db) }.to_json, ) @source = Lit::Source.create url: 'http://testhost.com/lit', api_key: 'test', identifier: 'test' end diff --git a/test/unit/lit/source_test.rb b/test/unit/lit/source_test.rb index a7205451..b64a252a 100644 --- a/test/unit/lit/source_test.rb +++ b/test/unit/lit/source_test.rb @@ -5,7 +5,7 @@ class SourceTest < ActiveSupport::TestCase fixtures 'lit/sources' def setup stub_request(:get, 'http://testhost.com/lit/api/v1/last_change.json'). - to_return(body: { last_change: 1.hour.ago.to_s(:db) }.to_json) + to_return(body: { last_change: 1.hour.ago.to_fs(:db) }.to_json) stub_request(:get, 'http://testhost.nope/lit/api/v1/last_change.json'). to_return(body: 'Nothing to be found around here', status: 404) end From e5233bf6ff830d1eeb9e11d85c03de2525f29468 Mon Sep 17 00:00:00 2001 From: Bartosz Gaj Date: Fri, 23 Dec 2022 16:25:35 +0100 Subject: [PATCH 02/13] Rails 7.0 collection to json --- app/controllers/lit/api/v1/locales_controller.rb | 2 +- app/controllers/lit/api/v1/localization_keys_controller.rb | 2 +- app/controllers/lit/api/v1/localizations_controller.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/lit/api/v1/locales_controller.rb b/app/controllers/lit/api/v1/locales_controller.rb index 6473763f..8a78abee 100644 --- a/app/controllers/lit/api/v1/locales_controller.rb +++ b/app/controllers/lit/api/v1/locales_controller.rb @@ -6,7 +6,7 @@ module V1 class LocalesController < Api::V1::BaseLitController def index @locales = Locale.all - render json: @locales.as_json(root: false, only: %i[id locale]) + render json: @locales.as_json(root: false, only: %i[id locale]).to_json end end end diff --git a/app/controllers/lit/api/v1/localization_keys_controller.rb b/app/controllers/lit/api/v1/localization_keys_controller.rb index 20edf2ba..fb4ce729 100644 --- a/app/controllers/lit/api/v1/localization_keys_controller.rb +++ b/app/controllers/lit/api/v1/localization_keys_controller.rb @@ -6,7 +6,7 @@ def index @localization_keys = fetch_localization_keys render json: @localization_keys.as_json( root: false, only: %i[id localization_key is_deleted] - ) + ).to_json end private diff --git a/app/controllers/lit/api/v1/localizations_controller.rb b/app/controllers/lit/api/v1/localizations_controller.rb index f35a379e..5abc9df4 100644 --- a/app/controllers/lit/api/v1/localizations_controller.rb +++ b/app/controllers/lit/api/v1/localizations_controller.rb @@ -7,7 +7,7 @@ def index root: false, only: %i[id localization_key_id locale_id], methods: %i[value localization_key_str locale_str localization_key_is_deleted], - ) + ).to_json end def last_change From 738038ac6e97876371eebfa6def9c6fc9bb5904f Mon Sep 17 00:00:00 2001 From: Bartosz Gaj Date: Wed, 22 Feb 2023 16:16:31 +0100 Subject: [PATCH 03/13] create all locales when accept first incoming localization --- .ruby-version | 2 +- Appraisals | 2 +- app/models/lit/incomming_localization.rb | 15 +++++ gemfiles/rails_7.0.gemfile | 2 +- gemfiles/rails_7.0.gemfile.lock | 70 +++++++----------------- test/test_helper.rb | 3 +- 6 files changed, 40 insertions(+), 54 deletions(-) diff --git a/.ruby-version b/.ruby-version index b0f2dcb3..ef538c28 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.0.4 +3.1.2 diff --git a/Appraisals b/Appraisals index a9d4cba9..d9454a9c 100644 --- a/Appraisals +++ b/Appraisals @@ -16,5 +16,5 @@ appraise 'rails-7.0' do gem 'rails-controller-testing' gem 'minitest' gem 'm', '~> 1.5.0' - gem 'google-cloud-translate', '~> 2.1.2' + gem "google-cloud-translate", "1.2.4" end \ No newline at end of file diff --git a/app/models/lit/incomming_localization.rb b/app/models/lit/incomming_localization.rb index e244fb46..d2418b3b 100644 --- a/app/models/lit/incomming_localization.rb +++ b/app/models/lit/incomming_localization.rb @@ -76,6 +76,8 @@ def assign_new_localization_key end def assign_new_localization + create_other_localizations if localization_key.localizations.blank? + self.localization = Lit::Localization .where(localization_key_id: localization_key.id) @@ -86,6 +88,19 @@ def assign_new_localization localization.save! end + def create_other_localizations + ::Lit::Locale.where.not(id: locale.id).pluck(:id).each do |locale_id| + localization = + Lit::Localization + .where(localization_key_id: localization_key.id) + .where(locale_id: locale_id) + .first_or_initialize + localization.translated_value = translated_value + localization.save! + Lit.init.cache.update_cache localization.full_key, localization.translation + end + end + def update_cache Lit.init.cache.update_cache localization.full_key, localization.translation end diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index b13f7ba0..88eeca50 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -18,6 +18,6 @@ gem "pry-rails" gem "rails-controller-testing" gem "minitest" gem "m", "~> 1.5.0" -gem "google-cloud-translate", "~> 2.1.2" +gem "google-cloud-translate", "1.2.4" gemspec path: "../" diff --git a/gemfiles/rails_7.0.gemfile.lock b/gemfiles/rails_7.0.gemfile.lock index a6069207..4f71053a 100644 --- a/gemfiles/rails_7.0.gemfile.lock +++ b/gemfiles/rails_7.0.gemfile.lock @@ -85,8 +85,9 @@ GEM bcrypt (3.1.18) builder (3.2.4) byebug (11.1.3) - capybara (3.35.3) + capybara (3.38.0) addressable + matrix mini_mime (>= 0.1.3) nokogiri (~> 1.8) rack (>= 1.6.0) @@ -102,12 +103,13 @@ GEM execjs coffee-script-source (1.12.2) concurrent-ruby (1.1.10) + connection_pool (2.3.0) crack (0.4.5) rexml crass (1.0.6) database_cleaner (2.0.1) database_cleaner-active_record (~> 2.0.0) - database_cleaner-active_record (2.0.0) + database_cleaner-active_record (2.0.1) activerecord (>= 5.a) database_cleaner-core (~> 2.0.0) database_cleaner-core (2.0.1) @@ -121,25 +123,8 @@ GEM emoji_flag (0.1.1) erubi (1.12.0) execjs (2.8.1) - faraday (1.8.0) - faraday-em_http (~> 1.0) - faraday-em_synchrony (~> 1.0) - faraday-excon (~> 1.1) - faraday-httpclient (~> 1.0.1) - faraday-net_http (~> 1.0) - faraday-net_http_persistent (~> 1.1) - faraday-patron (~> 1.0) - faraday-rack (~> 1.0) + faraday (0.17.6) multipart-post (>= 1.2, < 3) - ruby2_keywords (>= 0.0.4) - faraday-em_http (1.0.0) - faraday-em_synchrony (1.0.0) - faraday-excon (1.1.0) - faraday-httpclient (1.0.1) - faraday-net_http (1.0.1) - faraday-net_http_persistent (1.2.0) - faraday-patron (1.0.0) - faraday-rack (1.0.0) ffi (1.15.5) globalid (1.0.0) activesupport (>= 5.0) @@ -149,36 +134,17 @@ GEM google-cloud-env (1.6.0) faraday (>= 0.17.3, < 3.0) google-cloud-errors (1.3.0) - google-cloud-translate (2.1.2) - faraday (>= 0.17.3, < 2.0) + google-cloud-translate (1.2.4) + faraday (~> 0.13) google-cloud-core (~> 1.2) - google-gax (~> 1.8) - googleapis-common-protos (>= 1.3.9, < 2.0) - googleapis-common-protos-types (>= 1.0.4, < 2.0) - google-gax (1.8.2) - google-protobuf (~> 3.9) - googleapis-common-protos (>= 1.3.9, < 2.0) - googleapis-common-protos-types (>= 1.0.4, < 2.0) - googleauth (~> 0.9) - grpc (~> 1.24) - rly (~> 0.2.3) - google-protobuf (3.17.3-x86_64-linux) - googleapis-common-protos (1.3.12) - google-protobuf (~> 3.14) - googleapis-common-protos-types (~> 1.2) - grpc (~> 1.27) - googleapis-common-protos-types (1.3.0) - google-protobuf (~> 3.14) - googleauth (0.17.1) - faraday (>= 0.17.3, < 2.0) + googleauth (~> 0.6.2) + googleauth (0.6.7) + faraday (~> 0.12) jwt (>= 1.4, < 3.0) memoist (~> 0.16) multi_json (~> 1.11) os (>= 0.9, < 2.0) - signet (~> 0.15) - grpc (1.41.0-x86_64-linux) - google-protobuf (~> 3.17) - googleapis-common-protos-types (~> 1.0) + signet (~> 0.7) hashdiff (1.0.1) i18n (1.12.0) concurrent-ruby (~> 1.0) @@ -186,7 +152,7 @@ GEM rails-dom-testing (>= 1, < 3) railties (>= 4.2.0) thor (>= 0.14, < 2.0) - jwt (2.5.0) + jwt (2.7.0) loofah (2.19.1) crass (~> 1.0.2) nokogiri (>= 1.5.9) @@ -199,6 +165,7 @@ GEM net-pop net-smtp marcel (1.0.2) + matrix (0.4.2) memoist (0.16.2) method_source (1.0.0) mini_mime (1.1.2) @@ -209,7 +176,8 @@ GEM minispec-metadata (~> 2.0) minitest (>= 4.7.5) vcr (>= 2.9) - mocha (1.16.1) + mocha (2.0.2) + ruby2_keywords (>= 0.0.5) multi_json (1.15.0) multipart-post (2.2.3) net-imap (0.3.4) @@ -271,13 +239,15 @@ GEM thor (~> 1.0) zeitwerk (~> 2.5) rake (13.0.6) - redis (4.8.0) + redis (5.0.5) + redis-client (>= 0.9.0) + redis-client (0.11.2) + connection_pool regexp_parser (2.6.1) responders (3.0.1) actionpack (>= 5.0) railties (>= 5.0) rexml (3.2.5) - rly (0.2.3) ruby2_keywords (0.0.5) sass-rails (6.0.0) sassc-rails (~> 2.1, >= 2.1.1) @@ -330,7 +300,7 @@ DEPENDENCIES coffee-rails database_cleaner devise (~> 4.8.1) - google-cloud-translate (~> 2.1.2) + google-cloud-translate (= 1.2.4) jquery-rails lit! m (~> 1.5.0) diff --git a/test/test_helper.rb b/test/test_helper.rb index 0a9009a4..8ad19dd2 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -12,7 +12,8 @@ require 'capybara/rails' require 'database_cleaner' require 'test_declarative' -require 'mocha/setup' +require 'minitest/unit' +require 'mocha/minitest' require 'webmock' require 'vcr' require 'minitest-vcr' From 443cb9e1b68a90370c308ccb836e10e99bb887cf Mon Sep 17 00:00:00 2001 From: Bartosz Gaj Date: Wed, 22 Feb 2023 21:42:57 +0100 Subject: [PATCH 04/13] fix redis url --- lib/lit/adapters/redis_storage.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lit/adapters/redis_storage.rb b/lib/lit/adapters/redis_storage.rb index 530381e5..0df2679e 100644 --- a/lib/lit/adapters/redis_storage.rb +++ b/lib/lit/adapters/redis_storage.rb @@ -5,7 +5,7 @@ module Lit extend self def redis $redis ||= nil - $redis = Redis.new(url: determine_redis_provider) unless $redis + $redis = Redis.new(url: determine_redis_provider, ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }) unless $redis $redis end From d901774fd80287914cf389793f412876cbd567d8 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Wed, 22 Feb 2023 14:18:23 +0100 Subject: [PATCH 05/13] Add DeepL cloud translator service --- .../providers/deepl_translator.rb | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lib/lit/cloud_translation/providers/deepl_translator.rb diff --git a/lib/lit/cloud_translation/providers/deepl_translator.rb b/lib/lit/cloud_translation/providers/deepl_translator.rb new file mode 100644 index 00000000..79028d6b --- /dev/null +++ b/lib/lit/cloud_translation/providers/deepl_translator.rb @@ -0,0 +1,52 @@ +# frozen_string_literal: true + +require_relative 'base' +require 'deepl' + +module Lit::CloudTranslation::Providers + # DeepL Translate API provider for Lit translation suggestions. + # + # Configuration: + # + # require 'lit/cloud_translation/providers/deepl_translator' + # + # Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::DeeplTranslator + # + # Lit::CloudTranslation.configure do |config| + # config.api_key = 'the_api_key' + # end + class DeeplTranslator < Base + def translate(text:, from: nil, to:, **opts) + configure_api_key + + res = ::DeepL.translate(text, to_deepl_source_locale(from), to_deepl_target_locale(to), opts) + if res.is_a?(DeepL::Resources::Text) + res.text + else + res.map(&:text) + end + end + + private + + # Convert 'es-ES' to 'ES', en-us to EN + def to_deepl_source_locale(locale) + locale.to_s.split('-', 2).first.upcase + end + + # Convert 'es-ES' to 'ES' but warn about locales requiring a specific variant + def to_deepl_target_locale(locale) + loc, sub = locale.to_s.split('-') + loc.upcase + end + + def configure_api_key + base_config = config + ::DeepL.configure do |config| + config.auth_key = base_config.api_key + config.host = 'https://api.deepl.com' + config.version = 'v1' + end + end + end +end From a142ac0dd4e6d2676c48d800a6432caa101a8307 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Wed, 1 Mar 2023 13:38:38 +0100 Subject: [PATCH 06/13] Add DeepL cloud translation API documentation to readme --- README.md | 18 ++++++++++++++++++ gemfiles/rails_7.0.gemfile | 1 + 2 files changed, 19 insertions(+) diff --git a/README.md b/README.md index b9db3148..1a09c8be 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,24 @@ Currently, Google and Yandex translation providers are supported, but extending Configure your translation provider using one of routines described below. When a translation provider is configured, each localization in Lit web UI will have a "Translate using _Provider Name_" button next to it, which by default translates to the localization's language from the localization currently saved for the app's `I18n.default_locale`. Next to the button, there is a dropdown that allows translating from the key's localization in a language different than the default one. +#### DeepL Cloud Translation API + +Insert this into your Lit initializer: +``` +require 'lit/cloud_translation/providers/deepl_translator' + +Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::DeeplTranslator +Lit::CloudTranslation.configure do |config| + config.api_key = HashWithIndifferentAccess.new(Rails.application.credentials.config[:deepl_api]) +end +``` + +...and make sure you have this in your Gemfile: + +``` +gem "deepl-rb", require: "deepl" +``` + #### Google Cloud Translation API Insert this into your Lit initializer: diff --git a/gemfiles/rails_7.0.gemfile b/gemfiles/rails_7.0.gemfile index 88eeca50..9a85b20d 100644 --- a/gemfiles/rails_7.0.gemfile +++ b/gemfiles/rails_7.0.gemfile @@ -19,5 +19,6 @@ gem "rails-controller-testing" gem "minitest" gem "m", "~> 1.5.0" gem "google-cloud-translate", "1.2.4" +gem "deepl-rb", require: "deepl" gemspec path: "../" From 87dceac9e5ea7add1a7b53eb320ef8787354fa18 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Thu, 2 Mar 2023 11:49:41 +0100 Subject: [PATCH 07/13] Bugfix in import upsert --- lib/lit/import.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/lit/import.rb b/lib/lit/import.rb index 612a7729..a738d5fd 100644 --- a/lib/lit/import.rb +++ b/lib/lit/import.rb @@ -141,8 +141,12 @@ def upsert(locale, key, value) # rubocop:disable Metrics/MethodLength existing_translation = Lit::Localization.joins(:locale, :localization_key) .find_by('localization_key = ? and locale = ?', key, locale) - - return unless existing_translation + + unless existing_translation + locale = Lit::Locale.find_or_create_by locale: locale + l_k = Lit::LocalizationKey.create localization_key: key + existing_translation = Lit::Localization.create locale: locale, localization_key: l_k, translated_value: value + end if @raw existing_translation.update(default_value: value) From 094fdeb5d447e13e4c00be59d94e13c67e4d1cfc Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Thu, 2 Mar 2023 13:09:16 +0100 Subject: [PATCH 08/13] Bugfix in import upsert --- lib/lit/import.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lit/import.rb b/lib/lit/import.rb index a738d5fd..dbb2965e 100644 --- a/lib/lit/import.rb +++ b/lib/lit/import.rb @@ -144,8 +144,8 @@ def upsert(locale, key, value) # rubocop:disable Metrics/MethodLength unless existing_translation locale = Lit::Locale.find_or_create_by locale: locale - l_k = Lit::LocalizationKey.create localization_key: key - existing_translation = Lit::Localization.create locale: locale, localization_key: l_k, translated_value: value + lkey = Lit::LocalizationKey.find_or_create_by localization_key: key + existing_translation = Lit::Localization.create locale: locale, localization_key: lkey, translated_value: value end if @raw From 871858816f91c7552ebf251e3047019a3b3642f6 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Thu, 2 Mar 2023 13:11:08 +0100 Subject: [PATCH 09/13] Correct example of warm_up_keys cli --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1a09c8be..ed8fefc0 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ $ rake lit:import FILE=stuff.csv LOCALES=en,pl SKIP_NIL=1 Additionally, there is the `lit:warm_up_keys` task (temporarily aliased as `lit:raw_import` for compatibility) which serves a different purpose: rather than for actual import of translations, it is intended to pre-load into database translations from a specific locale's YAML file **when the application is first deployed to a server and not all translation keys are present in the database yet**. This task also takes the `SKIP_NIL` option in a similar way as the import task. ```bash -$ rake lit:warm_up_keys FILES=config/locales/en.yml LOCALES=en +$ rake lit:warm_up_keys FILES=en.yml LOCALE=en ``` In this case, when the `config/locales/en.yml` contains a translation for `foo` which doesn't have a key in the DB yet, it will be created, but if it already exists in the DB with a translation, it won't be overridden. From 2b03646f4e785e4a1692e5f0d235baa3b0d78f84 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Thu, 2 Mar 2023 15:37:32 +0100 Subject: [PATCH 10/13] Remove EmojiFlag which is not supported by rails 7 + auto accept incoming localizations --- app/services/synchronize_source_service.rb | 4 +++- app/views/lit/dashboard/index.html.erb | 2 +- app/views/lit/incomming_localizations/index.html.erb | 2 +- app/views/lit/localization_keys/_localizations_list.html.erb | 1 - lib/lit/loader.rb | 1 - lit.gemspec | 1 - 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/services/synchronize_source_service.rb b/app/services/synchronize_source_service.rb index 42cc7b2b..1f96d202 100644 --- a/app/services/synchronize_source_service.rb +++ b/app/services/synchronize_source_service.rb @@ -1,6 +1,7 @@ class SynchronizeSourceService - def initialize(source) + def initialize(source, auto_accept = false) @source = source + @auto_accept = auto_accept end def execute @@ -29,6 +30,7 @@ def synchronize_localization(loc) return if inc_loc.duplicated?(loc['value']) inc_loc.save! + inc_loc.accept if @auto_accept end def find_incomming_localization(localization) diff --git a/app/views/lit/dashboard/index.html.erb b/app/views/lit/dashboard/index.html.erb index f9dcd4d4..6225ca9d 100644 --- a/app/views/lit/dashboard/index.html.erb +++ b/app/views/lit/dashboard/index.html.erb @@ -1,5 +1,5 @@ All localization keys <%= Lit::LocalizationKey.active.count(:id) %>
<% @locales.each do |l| %> - <%= EmojiFlag.new(l.locale) %> <%= I18n.t("lit.locale_to_languages.#{l.locale}", :default=>l.locale) %>: "><%= l.translated_percentage %>%
+ <%= I18n.t("lit.locale_to_languages.#{l.locale}", :default=>l.locale) %>: "><%= l.translated_percentage %>%
<% end %> diff --git a/app/views/lit/incomming_localizations/index.html.erb b/app/views/lit/incomming_localizations/index.html.erb index 3925d582..6eae52aa 100644 --- a/app/views/lit/incomming_localizations/index.html.erb +++ b/app/views/lit/incomming_localizations/index.html.erb @@ -25,7 +25,7 @@ <% @incomming_localizations.each do |il| %> - <%= image_tag EmojiFlag.new(il.locale_str) %> + <%= il.locale_str %> <%= il.full_key %> diff --git a/app/views/lit/localization_keys/_localizations_list.html.erb b/app/views/lit/localization_keys/_localizations_list.html.erb index f8b2a391..930bac22 100644 --- a/app/views/lit/localization_keys/_localizations_list.html.erb +++ b/app/views/lit/localization_keys/_localizations_list.html.erb @@ -56,7 +56,6 @@ <%= render partial: 'localization_row', locals: {localization: Lit.init.cache["#{locale}.#{lk.localization_key}"]} %> - <%= EmojiFlag.new(locale) %> <%= locale %> <% unless lk.is_deleted? %> diff --git a/lib/lit/loader.rb b/lib/lit/loader.rb index 5f77d79d..6452b831 100644 --- a/lib/lit/loader.rb +++ b/lib/lit/loader.rb @@ -4,7 +4,6 @@ require 'lit/export' require 'lit/import' require 'lit/cloud_translation' -require 'emoji_flag' module Lit class Loader diff --git a/lit.gemspec b/lit.gemspec index b7222470..2bf1c434 100644 --- a/lit.gemspec +++ b/lit.gemspec @@ -21,7 +21,6 @@ Gem::Specification.new do |s| s.add_dependency 'jquery-rails' s.add_dependency 'coffee-rails' s.add_dependency 'sass-rails' - s.add_dependency 'emoji_flag' s.add_development_dependency 'appraisal', '~> 2.4.0' s.add_development_dependency 'devise', '~> 4.7.1' From 3a6c9c41a451eaa09b4abdbd012d0a800b6b7349 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Wed, 8 Mar 2023 13:31:20 +0100 Subject: [PATCH 11/13] Fixes loading assets from localhost:3000 + ignore tags for i18n variables --- app/views/layouts/lit/application.html.erb | 13 +++---------- .../providers/deepl_translator.rb | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/views/layouts/lit/application.html.erb b/app/views/layouts/lit/application.html.erb index 9b226ca9..e0a69b63 100644 --- a/app/views/layouts/lit/application.html.erb +++ b/app/views/layouts/lit/application.html.erb @@ -5,9 +5,9 @@ - <%= stylesheet_link_tag '//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css', media: 'all' %> - <%= stylesheet_link_tag '//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', media: 'all' %> - <%= stylesheet_link_tag '//netdna.bootstrapcdn.com/bootswatch/3.0.3/yeti/bootstrap.min.css', media: 'all' %> + <%= stylesheet_link_tag 'https://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css', media: 'all' %> + <%= stylesheet_link_tag 'https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css', media: 'all' %> + <%= stylesheet_link_tag 'https://netdna.bootstrapcdn.com/bootswatch/3.0.3/yeti/bootstrap.min.css', media: 'all' %> <%= stylesheet_link_tag 'lit/application', media: 'all' %> <%= javascript_include_tag 'lit/application' %> <%= csrf_meta_tags %> @@ -33,13 +33,6 @@ <% end %> - diff --git a/lib/lit/cloud_translation/providers/deepl_translator.rb b/lib/lit/cloud_translation/providers/deepl_translator.rb index 79028d6b..51552d47 100644 --- a/lib/lit/cloud_translation/providers/deepl_translator.rb +++ b/lib/lit/cloud_translation/providers/deepl_translator.rb @@ -19,16 +19,22 @@ class DeeplTranslator < Base def translate(text:, from: nil, to:, **opts) configure_api_key - res = ::DeepL.translate(text, to_deepl_source_locale(from), to_deepl_target_locale(to), opts) - if res.is_a?(DeepL::Resources::Text) - res.text - else - res.map(&:text) - end + opts.merge!(ignore_tags: "i18n", tag_handling: :xml) + + res = ::DeepL.translate(convert_ignore_tags(text), to_deepl_source_locale(from), to_deepl_target_locale(to), opts) + revert_ignore_tags(res.text) if res.is_a?(DeepL::Resources::Text) end private + def convert_ignore_tags(text) + text.gsub(/%{(\w+)}/) { "#{Regexp.last_match[1]}" } + end + + def revert_ignore_tags(text) + text.gsub(/(\w+)<\/i18n>/) { "%{#{Regexp.last_match[1]}}" } + end + # Convert 'es-ES' to 'ES', en-us to EN def to_deepl_source_locale(locale) locale.to_s.split('-', 2).first.upcase From 035c832e1d54633ecff9bd10d56711ccfa3b9af3 Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Mon, 13 Mar 2023 11:31:48 +0100 Subject: [PATCH 12/13] Add JS alert for showing validation errors --- app/models/lit/localization.rb | 27 +++++++++++++++++++++++ app/views/lit/localizations/update.js.erb | 10 ++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/app/models/lit/localization.rb b/app/models/lit/localization.rb index d44e84f5..b3dc66c6 100644 --- a/app/models/lit/localization.rb +++ b/app/models/lit/localization.rb @@ -23,6 +23,8 @@ class Localization < Lit::Base ## VALIDATIONS validates :locale, :localization_key, presence: true + validate :correct_interpolation_keys + ## ACCESSORS attr_accessor :full_key_str @@ -87,5 +89,30 @@ def create_version translated_value = translated_value_was || default_value localization_versions.new(translated_value: translated_value) end + + def correct_interpolation_keys + return if locale_str == "en" + + english_translation = find_english_translation + return unless english_translation + + english_interpolation_keys = interpolation_keys(english_translation.translation) + interpolation_keys = interpolation_keys(self.translated_value) + if interpolation_keys != english_interpolation_keys + errors.add(:base, "Interpolation keys do not match: please do not touch variables such as: %{example}.") + end + end + + def find_english_translation + self.class.joins(:locale, :localization_key).find_by(localization_key: { localization_key: self.localization_key_str }, locale: { locale: "en" }) + end + + def interpolation_keys(text) + return [] unless text + + keys = [] + text % Hash.new { |_, k| keys << k ; 0 } + keys + end end end diff --git a/app/views/lit/localizations/update.js.erb b/app/views/lit/localizations/update.js.erb index fe8e867c..349c4799 100644 --- a/app/views/lit/localizations/update.js.erb +++ b/app/views/lit/localizations/update.js.erb @@ -1,6 +1,10 @@ var $row = $('td.localization_row[data-id="<%= @localization.id %>"]'); $row.data('editing', 0); -$row.html("<%= ejs render(:partial=>"/lit/localization_keys/localization_row", :locals=>{:localization=>@localization.translated_value }) %>"); -$row.siblings().find('.js-show_prev_versions').removeClass('hidden'); -$('a.change_completed_<%= @localization.id %> input[type=checkbox]').prop("checked", true); +<% if @localization.errors.any? %> + alert('<%= @localization.errors.full_messages.to_sentence %>'); +<% else %> + $row.html("<%= ejs render(:partial=>"/lit/localization_keys/localization_row", :locals=>{:localization=>@localization.translated_value }) %>"); + $row.siblings().find('.js-show_prev_versions').removeClass('hidden'); + $('a.change_completed_<%= @localization.id %> input[type=checkbox]').prop("checked", true); +<% end %> From b77016774f31955c4e4f7eb55916988b2d1e450b Mon Sep 17 00:00:00 2001 From: Ralf Claassens Date: Mon, 13 Mar 2023 12:40:12 +0100 Subject: [PATCH 13/13] Cleanup translations --- config/locales/activerecord.en.yml | 26 ++++++++++++++++++++++++++ config/locales/activerecord.es.yml | 26 ++++++++++++++++++++++++++ config/locales/activerecord.fr.yml | 26 ++++++++++++++++++++++++++ config/locales/activerecord.nl.yml | 26 ++++++++++++++++++++++++++ config/locales/en.yml | 23 +++++++++++++++++++++++ config/locales/es.yml | 23 +++++++++++++++++++++++ config/locales/fr.yml | 23 +++++++++++++++++++++++ config/locales/nl.yml | 23 +++++++++++++++++++++++ 8 files changed, 196 insertions(+) create mode 100644 config/locales/activerecord.en.yml create mode 100644 config/locales/activerecord.es.yml create mode 100644 config/locales/activerecord.fr.yml create mode 100644 config/locales/activerecord.nl.yml create mode 100644 config/locales/en.yml create mode 100644 config/locales/es.yml create mode 100644 config/locales/fr.yml create mode 100644 config/locales/nl.yml diff --git a/config/locales/activerecord.en.yml b/config/locales/activerecord.en.yml new file mode 100644 index 00000000..f438e055 --- /dev/null +++ b/config/locales/activerecord.en.yml @@ -0,0 +1,26 @@ +--- +en: + errors: + attributes: + localization: + required: mandatory + localization_key: + required: mandatory + activerecord: + attributes: + lit/incomming_localization: + localization: Localization + localization_key: Localization key + errors: + models: + lit/incomming_localization: + attributes: + localization: + format: "%{attribute} %{message}" + required: + localization_key: + format: "%{attribute} %{message}" + required: + required: + models: + lit/incomming_localization: Incomming localization diff --git a/config/locales/activerecord.es.yml b/config/locales/activerecord.es.yml new file mode 100644 index 00000000..523c662d --- /dev/null +++ b/config/locales/activerecord.es.yml @@ -0,0 +1,26 @@ +--- +es: + errors: + attributes: + localization: + required: mandatory + localization_key: + required: mandatory + activerecord: + attributes: + lit/incomming_localization: + localization: Localization + localization_key: Localization key + errors: + models: + lit/incomming_localization: + attributes: + localization: + format: "%{attribute} %{message}" + required: + localization_key: + format: "%{attribute} %{message}" + required: + required: + models: + lit/incomming_localization: Incomming localization diff --git a/config/locales/activerecord.fr.yml b/config/locales/activerecord.fr.yml new file mode 100644 index 00000000..85843a8a --- /dev/null +++ b/config/locales/activerecord.fr.yml @@ -0,0 +1,26 @@ +--- +fr: + errors: + attributes: + localization: + required: mandatory + localization_key: + required: mandatory + activerecord: + attributes: + lit/incomming_localization: + localization: Localization + localization_key: Localization key + errors: + models: + lit/incomming_localization: + attributes: + localization: + format: "%{attribute} %{message}" + required: + localization_key: + format: "%{attribute} %{message}" + required: + required: + models: + lit/incomming_localization: Incomming localization diff --git a/config/locales/activerecord.nl.yml b/config/locales/activerecord.nl.yml new file mode 100644 index 00000000..e6349046 --- /dev/null +++ b/config/locales/activerecord.nl.yml @@ -0,0 +1,26 @@ +--- +nl: + errors: + attributes: + localization: + required: mandatory + localization_key: + required: mandatory + activerecord: + attributes: + lit/incomming_localization: + localization: Localization + localization_key: Localization key + errors: + models: + lit/incomming_localization: + attributes: + localization: + format: "%{attribute} %{message}" + required: + localization_key: + format: "%{attribute} %{message}" + required: + required: + models: + lit/incomming_localization: Incomming localization diff --git a/config/locales/en.yml b/config/locales/en.yml new file mode 100644 index 00000000..6705952c --- /dev/null +++ b/config/locales/en.yml @@ -0,0 +1,23 @@ +en: + order_by: Order by + lit: + common: + browse_incomming: Browse incomming localizations + delete: Delete + edit: Edit + previous_versions: Previous versions + show: Show + synchronize: Synchronize + touch: Touch (update) last_updated_at + you_sure: Are you sure? + not_translated_header: Not translated localization keys + order_options: + created_at_asc: Created at asc + created_at_desc: Created at desc + localization_key_asc: Localization key asc + localization_key_desc: Localization key desc + updated_at_asc: Updated at asc + updated_at_desc: Updated at desc + lit/incomming_localization: + localization: Localization + localization_key: Localization key diff --git a/config/locales/es.yml b/config/locales/es.yml new file mode 100644 index 00000000..6705952c --- /dev/null +++ b/config/locales/es.yml @@ -0,0 +1,23 @@ +en: + order_by: Order by + lit: + common: + browse_incomming: Browse incomming localizations + delete: Delete + edit: Edit + previous_versions: Previous versions + show: Show + synchronize: Synchronize + touch: Touch (update) last_updated_at + you_sure: Are you sure? + not_translated_header: Not translated localization keys + order_options: + created_at_asc: Created at asc + created_at_desc: Created at desc + localization_key_asc: Localization key asc + localization_key_desc: Localization key desc + updated_at_asc: Updated at asc + updated_at_desc: Updated at desc + lit/incomming_localization: + localization: Localization + localization_key: Localization key diff --git a/config/locales/fr.yml b/config/locales/fr.yml new file mode 100644 index 00000000..6705952c --- /dev/null +++ b/config/locales/fr.yml @@ -0,0 +1,23 @@ +en: + order_by: Order by + lit: + common: + browse_incomming: Browse incomming localizations + delete: Delete + edit: Edit + previous_versions: Previous versions + show: Show + synchronize: Synchronize + touch: Touch (update) last_updated_at + you_sure: Are you sure? + not_translated_header: Not translated localization keys + order_options: + created_at_asc: Created at asc + created_at_desc: Created at desc + localization_key_asc: Localization key asc + localization_key_desc: Localization key desc + updated_at_asc: Updated at asc + updated_at_desc: Updated at desc + lit/incomming_localization: + localization: Localization + localization_key: Localization key diff --git a/config/locales/nl.yml b/config/locales/nl.yml new file mode 100644 index 00000000..6705952c --- /dev/null +++ b/config/locales/nl.yml @@ -0,0 +1,23 @@ +en: + order_by: Order by + lit: + common: + browse_incomming: Browse incomming localizations + delete: Delete + edit: Edit + previous_versions: Previous versions + show: Show + synchronize: Synchronize + touch: Touch (update) last_updated_at + you_sure: Are you sure? + not_translated_header: Not translated localization keys + order_options: + created_at_asc: Created at asc + created_at_desc: Created at desc + localization_key_asc: Localization key asc + localization_key_desc: Localization key desc + updated_at_asc: Updated at asc + updated_at_desc: Updated at desc + lit/incomming_localization: + localization: Localization + localization_key: Localization key