diff --git a/.ruby-version b/.ruby-version
index 2c9b4ef4..a4dd9dba 100644
--- a/.ruby-version
+++ b/.ruby-version
@@ -1 +1 @@
-2.7.3
+2.7.4
diff --git a/Appraisals b/Appraisals
index a21df362..01263a2a 100644
--- a/Appraisals
+++ b/Appraisals
@@ -16,6 +16,7 @@ appraise 'rails-5.2' do
gem 'rails-controller-testing'
gem 'minitest'
gem 'm', '~> 1.5.0'
+ gem 'google-cloud-translate', '~> 1.2.4'
end
appraise 'rails-6.0' do
@@ -36,11 +37,12 @@ appraise 'rails-6.0' do
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.3'
+ gem 'rails', '~> 6.1.4.1'
gem 'devise'
gem 'pg', '~> 1.2.3'
gem 'redis'
@@ -56,4 +58,5 @@ appraise 'rails-6.1' do
gem 'rails-controller-testing'
gem 'minitest'
gem 'm', '~> 1.5.0'
+ gem 'google-cloud-translate', '~> 2.1.2'
end
diff --git a/README.md b/README.md
index c34d1121..6552dcfa 100644
--- a/README.md
+++ b/README.md
@@ -135,6 +135,10 @@ Lit::CloudTranslation.provider = Lit::CloudTranslation::Providers::Google
```
gem 'google-cloud-translate', '~> 1.2.4'
```
+...we also support V2 of Google Cloud Translate gem, should you need it:
+```
+gem 'google-cloud-translate', '~> 2.1.2'
+```
To use translation via Google, you need to obtain a [service account key](https://cloud.google.com/iam/docs/creating-managing-service-account-keys) containing all the credentials required by the API.
diff --git a/gemfiles/rails_5.2.gemfile b/gemfiles/rails_5.2.gemfile
index 6c74eb96..39387ba9 100644
--- a/gemfiles/rails_5.2.gemfile
+++ b/gemfiles/rails_5.2.gemfile
@@ -18,5 +18,6 @@ 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
index bc53f3a0..53786888 100644
--- a/gemfiles/rails_5.2.gemfile.lock
+++ b/gemfiles/rails_5.2.gemfile.lock
@@ -11,43 +11,43 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- actioncable (5.2.5)
- actionpack (= 5.2.5)
+ actioncable (5.2.6)
+ actionpack (= 5.2.6)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
- actionmailer (5.2.5)
- actionpack (= 5.2.5)
- actionview (= 5.2.5)
- activejob (= 5.2.5)
+ 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.5)
- actionview (= 5.2.5)
- activesupport (= 5.2.5)
+ 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.5)
- activesupport (= 5.2.5)
+ 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.5)
- activesupport (= 5.2.5)
+ activejob (5.2.6)
+ activesupport (= 5.2.6)
globalid (>= 0.3.6)
- activemodel (5.2.5)
- activesupport (= 5.2.5)
- activerecord (5.2.5)
- activemodel (= 5.2.5)
- activesupport (= 5.2.5)
+ 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.5)
- actionpack (= 5.2.5)
- activerecord (= 5.2.5)
+ activestorage (5.2.6)
+ actionpack (= 5.2.6)
+ activerecord (= 5.2.6)
marcel (~> 1.0.0)
- activesupport (5.2.5)
+ activesupport (5.2.6)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
@@ -78,7 +78,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
- concurrent-ruby (1.1.8)
+ concurrent-ruby (1.1.9)
crack (0.4.5)
rexml
crass (1.0.6)
@@ -100,8 +100,8 @@ GEM
faraday (0.17.4)
multipart-post (>= 1.2, < 3)
ffi (1.15.0)
- globalid (0.4.2)
- activesupport (>= 4.2.0)
+ globalid (1.0.0)
+ activesupport (>= 5.0)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
@@ -120,14 +120,14 @@ GEM
os (>= 0.9, < 2.0)
signet (~> 0.7)
hashdiff (1.0.1)
- i18n (1.8.10)
+ 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.9.1)
+ loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
m (1.5.1)
@@ -135,13 +135,14 @@ GEM
rake (>= 0.9.2.2)
mail (2.7.1)
mini_mime (>= 0.1.1)
- marcel (1.0.1)
+ marcel (1.0.2)
memoist (0.16.2)
method_source (1.0.0)
- mini_mime (1.1.0)
+ mini_mime (1.1.2)
+ mini_portile2 (2.6.1)
minispec-metadata (2.0.0)
minitest
- minitest (5.14.4)
+ minitest (5.15.0)
minitest-vcr (1.4.0)
minispec-metadata (~> 2.0)
minitest (>= 4.7.5)
@@ -149,10 +150,13 @@ GEM
mocha (1.12.0)
multi_json (1.15.0)
multipart-post (2.1.1)
- nio4r (2.5.7)
- nokogiri (1.11.3-x86_64-darwin)
+ 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.11.3-x86_64-linux)
+ nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
os (1.1.1)
@@ -166,22 +170,22 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
- racc (1.5.2)
+ racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
- rails (5.2.5)
- actioncable (= 5.2.5)
- actionmailer (= 5.2.5)
- actionpack (= 5.2.5)
- actionview (= 5.2.5)
- activejob (= 5.2.5)
- activemodel (= 5.2.5)
- activerecord (= 5.2.5)
- activestorage (= 5.2.5)
- activesupport (= 5.2.5)
+ 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.5)
+ railties (= 5.2.6)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
@@ -190,15 +194,15 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
- rails-html-sanitizer (1.3.0)
+ rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
- railties (5.2.5)
- actionpack (= 5.2.5)
- activesupport (= 5.2.5)
+ 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.3)
+ rake (13.0.6)
redis (4.2.5)
regexp_parser (2.1.1)
responders (3.0.1)
@@ -223,9 +227,9 @@ GEM
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
- sprockets-rails (3.2.2)
- actionpack (>= 4.0)
- activesupport (>= 4.0)
+ sprockets-rails (3.4.2)
+ actionpack (>= 5.2)
+ activesupport (>= 5.2)
sprockets (>= 3.0.0)
test_declarative (0.0.6)
thor (1.1.0)
@@ -240,13 +244,14 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
- websocket-driver (0.7.3)
+ 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
@@ -275,4 +280,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
- 2.2.16
+ 2.2.25
diff --git a/gemfiles/rails_6.0.gemfile b/gemfiles/rails_6.0.gemfile
index 0e611e80..12c20b47 100644
--- a/gemfiles/rails_6.0.gemfile
+++ b/gemfiles/rails_6.0.gemfile
@@ -18,5 +18,6 @@ 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
index dae48fe1..ea6de705 100644
--- a/gemfiles/rails_6.0.gemfile.lock
+++ b/gemfiles/rails_6.0.gemfile.lock
@@ -11,56 +11,56 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- actioncable (6.0.3.6)
- actionpack (= 6.0.3.6)
+ actioncable (6.0.4.4)
+ actionpack (= 6.0.4.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
- actionmailbox (6.0.3.6)
- actionpack (= 6.0.3.6)
- activejob (= 6.0.3.6)
- activerecord (= 6.0.3.6)
- activestorage (= 6.0.3.6)
- activesupport (= 6.0.3.6)
+ 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.3.6)
- actionpack (= 6.0.3.6)
- actionview (= 6.0.3.6)
- activejob (= 6.0.3.6)
+ 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.3.6)
- actionview (= 6.0.3.6)
- activesupport (= 6.0.3.6)
+ 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.3.6)
- actionpack (= 6.0.3.6)
- activerecord (= 6.0.3.6)
- activestorage (= 6.0.3.6)
- activesupport (= 6.0.3.6)
+ 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.3.6)
- activesupport (= 6.0.3.6)
+ 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.3.6)
- activesupport (= 6.0.3.6)
+ activejob (6.0.4.4)
+ activesupport (= 6.0.4.4)
globalid (>= 0.3.6)
- activemodel (6.0.3.6)
- activesupport (= 6.0.3.6)
- activerecord (6.0.3.6)
- activemodel (= 6.0.3.6)
- activesupport (= 6.0.3.6)
- activestorage (6.0.3.6)
- actionpack (= 6.0.3.6)
- activejob (= 6.0.3.6)
- activerecord (= 6.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.3.6)
+ activesupport (6.0.4.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2)
minitest (~> 5.1)
@@ -91,7 +91,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
- concurrent-ruby (1.1.8)
+ concurrent-ruby (1.1.9)
crack (0.4.5)
rexml
crass (1.0.6)
@@ -113,8 +113,8 @@ GEM
faraday (0.17.4)
multipart-post (>= 1.2, < 3)
ffi (1.15.0)
- globalid (0.4.2)
- activesupport (>= 4.2.0)
+ globalid (1.0.0)
+ activesupport (>= 5.0)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
@@ -133,14 +133,14 @@ GEM
os (>= 0.9, < 2.0)
signet (~> 0.7)
hashdiff (1.0.1)
- i18n (1.8.10)
+ 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.9.1)
+ loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
m (1.5.1)
@@ -148,13 +148,14 @@ GEM
rake (>= 0.9.2.2)
mail (2.7.1)
mini_mime (>= 0.1.1)
- marcel (1.0.1)
+ marcel (1.0.2)
memoist (0.16.2)
method_source (1.0.0)
- mini_mime (1.1.0)
+ mini_mime (1.1.2)
+ mini_portile2 (2.6.1)
minispec-metadata (2.0.0)
minitest
- minitest (5.14.4)
+ minitest (5.15.0)
minitest-vcr (1.4.0)
minispec-metadata (~> 2.0)
minitest (>= 4.7.5)
@@ -162,10 +163,13 @@ GEM
mocha (1.12.0)
multi_json (1.15.0)
multipart-post (2.1.1)
- nio4r (2.5.7)
- nokogiri (1.11.3-x86_64-darwin)
+ 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.11.3-x86_64-linux)
+ nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
os (1.1.1)
@@ -179,24 +183,24 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
- racc (1.5.2)
+ racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
- rails (6.0.3.6)
- actioncable (= 6.0.3.6)
- actionmailbox (= 6.0.3.6)
- actionmailer (= 6.0.3.6)
- actionpack (= 6.0.3.6)
- actiontext (= 6.0.3.6)
- actionview (= 6.0.3.6)
- activejob (= 6.0.3.6)
- activemodel (= 6.0.3.6)
- activerecord (= 6.0.3.6)
- activestorage (= 6.0.3.6)
- activesupport (= 6.0.3.6)
+ 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.3.6)
+ railties (= 6.0.4.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
@@ -205,15 +209,15 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
- rails-html-sanitizer (1.3.0)
+ rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
- railties (6.0.3.6)
- actionpack (= 6.0.3.6)
- activesupport (= 6.0.3.6)
+ 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.3)
+ rake (13.0.6)
redis (4.2.5)
regexp_parser (2.1.1)
responders (3.0.1)
@@ -238,9 +242,9 @@ GEM
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
- sprockets-rails (3.2.2)
- actionpack (>= 4.0)
- activesupport (>= 4.0)
+ sprockets-rails (3.4.2)
+ actionpack (>= 5.2)
+ activesupport (>= 5.2)
sprockets (>= 3.0.0)
test_declarative (0.0.6)
thor (1.1.0)
@@ -255,14 +259,15 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
- websocket-driver (0.7.3)
+ websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
- zeitwerk (2.4.2)
+ zeitwerk (2.5.1)
PLATFORMS
+ ruby
x86_64-darwin-20
x86_64-linux
@@ -291,4 +296,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
- 2.2.16
+ 2.2.25
diff --git a/gemfiles/rails_6.1.gemfile b/gemfiles/rails_6.1.gemfile
index 9f3e50cc..81a097c8 100644
--- a/gemfiles/rails_6.1.gemfile
+++ b/gemfiles/rails_6.1.gemfile
@@ -2,7 +2,7 @@
source "https://rubygems.org"
-gem "rails", "~> 6.1.3"
+gem "rails", "~> 6.1.4.1"
gem "devise"
gem "pg", "~> 1.2.3"
gem "redis"
@@ -18,5 +18,6 @@ gem "pry-rails"
gem "rails-controller-testing"
gem "minitest"
gem "m", "~> 1.5.0"
+gem "google-cloud-translate", "~> 2.1.2"
gemspec path: "../"
diff --git a/gemfiles/rails_6.1.gemfile.lock b/gemfiles/rails_6.1.gemfile.lock
index ea7dfa3b..0e04d695 100644
--- a/gemfiles/rails_6.1.gemfile.lock
+++ b/gemfiles/rails_6.1.gemfile.lock
@@ -11,60 +11,60 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- actioncable (6.1.3.1)
- actionpack (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ actioncable (6.1.4.4)
+ actionpack (= 6.1.4.4)
+ activesupport (= 6.1.4.4)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
- actionmailbox (6.1.3.1)
- actionpack (= 6.1.3.1)
- activejob (= 6.1.3.1)
- activerecord (= 6.1.3.1)
- activestorage (= 6.1.3.1)
- activesupport (= 6.1.3.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)
mail (>= 2.7.1)
- actionmailer (6.1.3.1)
- actionpack (= 6.1.3.1)
- actionview (= 6.1.3.1)
- activejob (= 6.1.3.1)
- activesupport (= 6.1.3.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)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
- actionpack (6.1.3.1)
- actionview (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ actionpack (6.1.4.4)
+ actionview (= 6.1.4.4)
+ activesupport (= 6.1.4.4)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
- actiontext (6.1.3.1)
- actionpack (= 6.1.3.1)
- activerecord (= 6.1.3.1)
- activestorage (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ 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)
nokogiri (>= 1.8.5)
- actionview (6.1.3.1)
- activesupport (= 6.1.3.1)
+ actionview (6.1.4.4)
+ activesupport (= 6.1.4.4)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
- activejob (6.1.3.1)
- activesupport (= 6.1.3.1)
+ activejob (6.1.4.4)
+ activesupport (= 6.1.4.4)
globalid (>= 0.3.6)
- activemodel (6.1.3.1)
- activesupport (= 6.1.3.1)
- activerecord (6.1.3.1)
- activemodel (= 6.1.3.1)
- activesupport (= 6.1.3.1)
- activestorage (6.1.3.1)
- actionpack (= 6.1.3.1)
- activejob (= 6.1.3.1)
- activerecord (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ 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)
- mini_mime (~> 1.0.2)
- activesupport (6.1.3.1)
+ mini_mime (>= 1.1.0)
+ activesupport (6.1.4.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
@@ -95,7 +95,7 @@ GEM
coffee-script-source
execjs
coffee-script-source (1.12.2)
- concurrent-ruby (1.1.8)
+ concurrent-ruby (1.1.9)
crack (0.4.5)
rexml
crass (1.0.6)
@@ -114,37 +114,81 @@ GEM
emoji_flag (0.1.1)
erubi (1.10.0)
execjs (2.7.0)
- faraday (0.17.4)
+ 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)
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.0)
- globalid (0.4.2)
- activesupport (>= 4.2.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-errors (1.2.0)
+ google-cloud-translate (2.1.2)
+ faraday (>= 0.17.3, < 2.0)
google-cloud-core (~> 1.2)
- googleauth (~> 0.6.2)
- googleauth (0.6.7)
- faraday (~> 0.12)
+ 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)
+ 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)
+ 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)
jwt (>= 1.4, < 3.0)
memoist (~> 0.16)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
- signet (~> 0.7)
+ 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.10)
+ 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.9.1)
+ jwt (2.3.0)
+ loofah (2.13.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
m (1.5.1)
@@ -152,13 +196,14 @@ GEM
rake (>= 0.9.2.2)
mail (2.7.1)
mini_mime (>= 0.1.1)
- marcel (1.0.1)
+ marcel (1.0.2)
memoist (0.16.2)
method_source (1.0.0)
- mini_mime (1.0.3)
+ mini_mime (1.1.2)
+ mini_portile2 (2.6.1)
minispec-metadata (2.0.0)
minitest
- minitest (5.14.4)
+ minitest (5.15.0)
minitest-vcr (1.4.0)
minispec-metadata (~> 2.0)
minitest (>= 4.7.5)
@@ -166,10 +211,13 @@ GEM
mocha (1.12.0)
multi_json (1.15.0)
multipart-post (2.1.1)
- nio4r (2.5.7)
- nokogiri (1.11.3-x86_64-darwin)
+ 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.11.3-x86_64-linux)
+ nokogiri (1.12.5-x86_64-linux)
racc (~> 1.4)
orm_adapter (0.5.0)
os (1.1.1)
@@ -183,24 +231,24 @@ GEM
pry-rails (0.3.9)
pry (>= 0.10.4)
public_suffix (4.0.6)
- racc (1.5.2)
+ racc (1.6.0)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
- rails (6.1.3.1)
- actioncable (= 6.1.3.1)
- actionmailbox (= 6.1.3.1)
- actionmailer (= 6.1.3.1)
- actionpack (= 6.1.3.1)
- actiontext (= 6.1.3.1)
- actionview (= 6.1.3.1)
- activejob (= 6.1.3.1)
- activemodel (= 6.1.3.1)
- activerecord (= 6.1.3.1)
- activestorage (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ 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)
bundler (>= 1.15.0)
- railties (= 6.1.3.1)
+ railties (= 6.1.4.4)
sprockets-rails (>= 2.0.0)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
@@ -209,21 +257,23 @@ GEM
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
- rails-html-sanitizer (1.3.0)
+ rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
- railties (6.1.3.1)
- actionpack (= 6.1.3.1)
- activesupport (= 6.1.3.1)
+ railties (6.1.4.4)
+ actionpack (= 6.1.4.4)
+ activesupport (= 6.1.4.4)
method_source
- rake (>= 0.8.7)
+ rake (>= 0.13)
thor (~> 1.0)
- rake (13.0.3)
+ 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)
+ rly (0.2.3)
+ ruby2_keywords (0.0.5)
sass-rails (6.0.0)
sassc-rails (~> 2.1, >= 2.1.1)
sassc (2.4.0)
@@ -242,9 +292,9 @@ GEM
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
- sprockets-rails (3.2.2)
- actionpack (>= 4.0)
- activesupport (>= 4.0)
+ sprockets-rails (3.4.2)
+ actionpack (>= 5.2)
+ activesupport (>= 5.2)
sprockets (>= 3.0.0)
test_declarative (0.0.6)
thor (1.1.0)
@@ -258,14 +308,15 @@ GEM
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
- websocket-driver (0.7.3)
+ websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
- zeitwerk (2.4.2)
+ zeitwerk (2.5.1)
PLATFORMS
+ ruby
x86_64-darwin-20
x86_64-linux
@@ -275,7 +326,7 @@ DEPENDENCIES
coffee-rails
database_cleaner
devise
- google-cloud-translate (~> 1.2.4)
+ google-cloud-translate (~> 2.1.2)
jquery-rails
lit!
m (~> 1.5.0)
@@ -285,7 +336,7 @@ DEPENDENCIES
pg (~> 1.2.3)
pry-byebug (~> 3.9.0)
pry-rails
- rails (~> 6.1.3)
+ rails (~> 6.1.4.1)
rails-controller-testing
redis
sass-rails
@@ -294,4 +345,4 @@ DEPENDENCIES
webmock
BUNDLED WITH
- 2.2.16
+ 2.2.25
diff --git a/lib/lit/cloud_translation/providers/google.rb b/lib/lit/cloud_translation/providers/google.rb
index 75bfa3e6..c5f56209 100644
--- a/lib/lit/cloud_translation/providers/google.rb
+++ b/lib/lit/cloud_translation/providers/google.rb
@@ -45,13 +45,10 @@ module Lit::CloudTranslation::Providers
# end
class Google < Base
def translate(text:, from: nil, to:, **opts)
- @client ||=
- ::Google::Cloud::Translate.new(project_id: config.keyfile_hash['project_id'],
- credentials: config.keyfile_hash)
- result = @client.translate(sanitize_text(text), from: from, to: to, **opts)
+ result = client.translate(sanitize_text(text), from: from, to: to, **opts)
unsanitize_text(
case result
- when ::Google::Cloud::Translate::Translation then result.text
+ when translation_class then result.text
when Array then result.map(&:text)
end
)
@@ -67,6 +64,27 @@ def translate(text:, from: nil, to:, **opts)
private
+ def client
+ @client ||= begin
+ args = {
+ project_id: config.keyfile_hash['project_id'], credentials: config.keyfile_hash,
+ version: :v2
+ }
+ if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0')
+ args = args.tap { |hs| hs.delete(:version) }
+ end
+ ::Google::Cloud::Translate.new(**args)
+ end
+ end
+
+ def translation_class
+ if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0')
+ ::Google::Cloud::Translate::Translation
+ else
+ ::Google::Cloud::Translate::V2::Translation
+ end
+ end
+
def default_config
if ENV['GOOGLE_TRANSLATE_API_KEYFILE'].blank?
env_keys = ENV.keys.grep(/\AGOOGLE_TRANSLATE_API_/)
@@ -93,7 +111,7 @@ def require_config!
def sanitize_text(text_or_array)
case text_or_array
when String
- text_or_array.gsub(/%{(.+?)}/, '__LIT__\1__LIT__
')
+ text_or_array.gsub(/%{(.+?)}/, '__LIT__\1__LIT__
').gsub(/\r\n/, '0
')
when Array
text_or_array.map { |s| sanitize_text(s) }
when nil
@@ -106,7 +124,7 @@ def sanitize_text(text_or_array)
def unsanitize_text(text_or_array)
case text_or_array
when String
- text_or_array.gsub(/__LIT__(.+?)__LIT__<\/code>/, '%{\1}')
+ text_or_array.gsub(%r{0
}, "\r\n").gsub(%r{__LIT__(.+?)__LIT__
}, '%{\1}')
when Array
text_or_array.map { |s| unsanitize_text(s) }
else
diff --git a/lib/lit/i18n_backend.rb b/lib/lit/i18n_backend.rb
index 646dc830..3863c365 100644
--- a/lib/lit/i18n_backend.rb
+++ b/lib/lit/i18n_backend.rb
@@ -16,9 +16,22 @@ def initialize(cache)
I18n.const_set(:RESERVED_KEYS, reserved_keys.freeze)
end
+ ## DOC
+ ## Translation flow starts with Rails-provided ActionView::Helpers::TranslationHelper `translate` method
+ ## In that method any calls to `I18n.translate` are catched by this method below (because Lit acts as I18 backend)
+ ## Any calls in Lit to `super` go straight to I18n
def translate(locale, key, options = {})
options[:lit_default_copy] = options[:default].dup if can_dup_default(options)
content = super(locale, key, options)
+
+ if on_rails_6_1_or_higher?
+ @untranslated_key = key if key.present? && options[:default].instance_of?(Object)
+
+ if key.nil? && options[:lit_default_copy].present?
+ update_default_localization(locale, content, options)
+ end
+ end
+
if Lit.all_translations_are_html_safe && content.respond_to?(:html_safe)
content.html_safe
else
@@ -54,6 +67,17 @@ def store_translations(locale, data, options = {})
private
+ def on_rails_6_1_or_higher?
+ "#{::Rails::VERSION::MAJOR}#{::Rails::VERSION::MINOR}".to_i == 61 ||
+ ::Rails::VERSION::MAJOR >= 7
+ end
+
+ def update_default_localization(locale, content, options)
+ parts = I18n.normalize_keys(locale, @untranslated_key, options[:scope], options[:separator])
+ key_with_locale = parts.join('.')
+ @cache.update_locale(key_with_locale, content, content.is_a?(Array))
+ end
+
def can_dup_default(options = {})
return false unless options.key?(:default)
return true if options[:default].is_a?(String)
diff --git a/lit.gemspec b/lit.gemspec
index 149997f4..b7222470 100644
--- a/lit.gemspec
+++ b/lit.gemspec
@@ -25,7 +25,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'appraisal', '~> 2.4.0'
s.add_development_dependency 'devise', '~> 4.7.1'
- s.add_development_dependency 'google-cloud-translate', '~> 1.2.4'
s.add_development_dependency 'minitest', '~> 5.11.3'
s.add_development_dependency 'minitest-vcr', '~> 1.4.0'
s.add_development_dependency 'pry-byebug', '~> 3.9.0'
diff --git a/test/cassettes/Lit_CloudTranslation_Providers_Google/edge_cases/when_text_contains_newline_characters/translation_comes_back_preserving_those_characters.yml b/test/cassettes/Lit_CloudTranslation_Providers_Google/edge_cases/when_text_contains_newline_characters/translation_comes_back_preserving_those_characters.yml
new file mode 100644
index 00000000..18aa9b7b
--- /dev/null
+++ b/test/cassettes/Lit_CloudTranslation_Providers_Google/edge_cases/when_text_contains_newline_characters/translation_comes_back_preserving_those_characters.yml
@@ -0,0 +1,109 @@
+---
+http_interactions:
+- request:
+ method: post
+ uri: https://oauth2.googleapis.com/token
+ body:
+ encoding: ASCII-8BIT
+ string: grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJleGFsdGVkLXBhdHRlcm4tMTIxNjExQGFwcHNwb3QuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImF1ZCI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiZXhwIjoxNjM2MDQ2MzIwLCJpYXQiOjE2MzYwNDYyMDAsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9jbG91ZC1wbGF0Zm9ybSJ9.azvrcE91ueMmJzcobWywCNv0VXpSskaa4UVqlX1S_FEe5x2hIVFJKdwQJB8bbbTC0AZH2ESiLOugkcq-KyohYOp2CgnE6qMxk7gV1V-J-bl7u_8tZUt4LFWrLx1sSIGMRY6IUztMnXhzfrjjWSSeGBe_YZ1ZAikRz5UO07i2JLH57VdPAmd2Tm7WuTVF8N8wMVeTalyPkgeE-l2evWEbluuT0vr8RDKrNDDiw5oUkWiGPRyeXrWj0QN-UAlVGGqznSlcWvAIA6_bj0pgxBoVrgVJqS9nGSmtDdXs-NrbkIqPluda7GGf8cA9w0TE2CNWhn8eImOAarNbmQ6_DJLMrA
+ headers:
+ User-Agent:
+ - Faraday v1.8.0
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Content-Type:
+ - application/json; charset=UTF-8
+ Vary:
+ - Origin
+ - Referer
+ - X-Origin
+ Date:
+ - Thu, 04 Nov 2021 17:17:40 GMT
+ Server:
+ - scaffolding on HTTPServer2
+ Cache-Control:
+ - private
+ X-Xss-Protection:
+ - '0'
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Content-Type-Options:
+ - nosniff
+ Alt-Svc:
+ - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443";
+ ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
+ Transfer-Encoding:
+ - chunked
+ body:
+ encoding: ASCII-8BIT
+ string: '{"access_token":"ya29.c.b0AXv0zTMfbtXXtlziux7wPsrgIlOj6ZtTJqxj8xnP4rvVUlqIdj_JzqB-k2n3DvYO_wWcstPD3TCWaXYSTfw42E5EAhzJ2hqr1afs_U4ws14VczdYjLvjGn0m-cjkwqq4Dbr8KF8-nEeQQKrAYNZ6OVs6qLlr_ESGmQ9yQks4r2EWtyNiiPxMPVPGdL-L-REGrnK3HYIgK0TUPhL2hTS3kI7YaqG3fE8......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","expires_in":3599,"token_type":"Bearer"}'
+ http_version:
+ recorded_at: Thu, 04 Nov 2021 17:17:40 GMT
+- request:
+ method: post
+ uri: https://translation.googleapis.com/language/translate/v2
+ body:
+ encoding: UTF-8
+ string: '{"q":["Some longer paragraph text\u003ccode\u003e0\u003c/code\u003eOne
+ line below"],"target":"pl"}'
+ headers:
+ User-Agent:
+ - gcloud-ruby/2.1.2
+ Google-Cloud-Resource-Prefix:
+ - projects/
+ Content-Type:
+ - application/json
+ X-Goog-Api-Client:
+ - gl-ruby/2.7.4 gccl/2.1.2
+ Authorization:
+ - Bearer ya29.c.b0AXv0zTMfbtXXtlziux7wPsrgIlOj6ZtTJqxj8xnP4rvVUlqIdj_JzqB-k2n3DvYO_wWcstPD3TCWaXYSTfw42E5EAhzJ2hqr1afs_U4ws14VczdYjLvjGn0m-cjkwqq4Dbr8KF8-nEeQQKrAYNZ6OVs6qLlr_ESGmQ9yQks4r2EWtyNiiPxMPVPGdL-L-REGrnK3HYIgK0TUPhL2hTS3kI7YaqG3fE8......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
+ Cache-Control:
+ - no-store
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Content-Type:
+ - application/json; charset=UTF-8
+ Vary:
+ - Origin
+ - Referer
+ - X-Origin
+ Date:
+ - Thu, 04 Nov 2021 17:17:40 GMT
+ Server:
+ - ESF
+ Cache-Control:
+ - private
+ X-Xss-Protection:
+ - '0'
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Content-Type-Options:
+ - nosniff
+ Alt-Svc:
+ - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443";
+ ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
+ Transfer-Encoding:
+ - chunked
+ body:
+ encoding: ASCII-8BIT
+ string: !binary |-
+ ewogICJkYXRhIjogewogICAgInRyYW5zbGF0aW9ucyI6IFsKICAgICAgewogICAgICAgICJ0cmFuc2xhdGVkVGV4dCI6ICJUcm9jaMSZIGTFgnXFvHN6ZWdvIHRla3N0dSBha2FwaXR1IFx1MDAzY2NvZGVcdTAwM2UwXHUwMDNjL2NvZGVcdTAwM2UgSmVkZW4gd2llcnN6IHBvbmnFvGVqIiwKICAgICAgICAiZGV0ZWN0ZWRTb3VyY2VMYW5ndWFnZSI6ICJlbiIKICAgICAgfQogICAgXQogIH0KfQo=
+ http_version:
+ recorded_at: Thu, 04 Nov 2021 17:17:40 GMT
+recorded_with: VCR 4.0.0
diff --git a/test/cassettes/Lit_CloudTranslation_Providers_Google/when_only_to_language_is_given/when_array_containing_nil_values_is_given/translates_array_to_target_language_converting_nil_to_.yml b/test/cassettes/Lit_CloudTranslation_Providers_Google/when_only_to_language_is_given/when_array_containing_nil_values_is_given/translates_array_to_target_language_converting_nil_to_.yml
index ae51b1cd..912b231c 100644
--- a/test/cassettes/Lit_CloudTranslation_Providers_Google/when_only_to_language_is_given/when_array_containing_nil_values_is_given/translates_array_to_target_language_converting_nil_to_.yml
+++ b/test/cassettes/Lit_CloudTranslation_Providers_Google/when_only_to_language_is_given/when_array_containing_nil_values_is_given/translates_array_to_target_language_converting_nil_to_.yml
@@ -75,6 +75,54 @@ http_interactions:
]
}
}
- http_version:
+ http_version:
recorded_at: Thu, 10 Jan 2019 13:47:15 GMT
+- request:
+ method: post
+ uri: https://oauth2.googleapis.com/token
+ body:
+ encoding: ASCII-8BIT
+ string: grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=eyJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJleGFsdGVkLXBhdHRlcm4tMTIxNjExQGFwcHNwb3QuZ3NlcnZpY2VhY2NvdW50LmNvbSIsImF1ZCI6Imh0dHBzOi8vb2F1dGgyLmdvb2dsZWFwaXMuY29tL3Rva2VuIiwiZXhwIjoxNjM2MDM5MDQzLCJpYXQiOjE2MzYwMzg5MjMsInNjb3BlIjoiaHR0cHM6Ly93d3cuZ29vZ2xlYXBpcy5jb20vYXV0aC9jbG91ZC1wbGF0Zm9ybSJ9.OwbPGHd8oxHD_nIVtwpvfCKfjcGyceE4SZK47KS5bcV2Iu4yUPkqhDoT73NIsG5uQ82c96FgBviJH8NNFGjyZH_tpuo2e6G2hdrf_IDmtQ7ioxHkSHtW6TqyiYrOWIBzC0hk4lMSEdKn-NvthIYdARNoJLI90Tdq2U3QoXnvDhd9_HASquRibRel0n6emQt_zsrHqdggv2U3XWYdHrY4tMDXieXno64IrXjDm7-k7EBsvFEGh8iX-aEtZG8t0zW3V_9_IxDvYYFuUd34csy3Ip_m1zqSc32GNbrJrldsgxpAmf_aFvOG3TdTNUl8azr1xEYIN-98BygRS9LvSvqXEA
+ headers:
+ User-Agent:
+ - Faraday v1.8.0
+ Content-Type:
+ - application/x-www-form-urlencoded
+ Accept-Encoding:
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
+ Accept:
+ - "*/*"
+ response:
+ status:
+ code: 200
+ message: OK
+ headers:
+ Content-Type:
+ - application/json; charset=UTF-8
+ Vary:
+ - Origin
+ - Referer
+ - X-Origin
+ Date:
+ - Thu, 04 Nov 2021 15:16:23 GMT
+ Server:
+ - scaffolding on HTTPServer2
+ Cache-Control:
+ - private
+ X-Xss-Protection:
+ - '0'
+ X-Frame-Options:
+ - SAMEORIGIN
+ X-Content-Type-Options:
+ - nosniff
+ Alt-Svc:
+ - h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443";
+ ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"
+ Transfer-Encoding:
+ - chunked
+ body:
+ encoding: ASCII-8BIT
+ string: '{"access_token":"ya29.c.b0AXv0zTN_sVlwkky1PMVvD1Avyp7mvjPEO46NmyAv0vtWKkX2kwmGZXEmGJUHojrCv7q-q8ffZYsoXa43rrRWiwoO_c4ksboA2WefVcX2wo4ee4EC8q1Zp6_y6jXS1JXE-yBoEZ29mMWsODFhJZmXLnXIIvXwOF7MhdAQq4mP4geqKr7Y_e8PbHduPhWohqkSC1iW6TMY-wFsdDu4EwkxzxbShn2tTt4......................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................","expires_in":3599,"token_type":"Bearer"}'
+ http_version:
+ recorded_at: Thu, 04 Nov 2021 15:16:23 GMT
recorded_with: VCR 4.0.0
diff --git a/test/lib/raw_import_task_test.rb b/test/lib/raw_import_task_test.rb
index 801ac6e5..190de887 100644
--- a/test/lib/raw_import_task_test.rb
+++ b/test/lib/raw_import_task_test.rb
@@ -1,4 +1,5 @@
require 'test_helper'
+require 'rake'
class RawImportTaskTest < ActiveSupport::TestCase
def setup
diff --git a/test/unit/lit/cloud_translation/providers/google_test.rb b/test/unit/lit/cloud_translation/providers/google_test.rb
index 07aae45a..7efe9ed8 100644
--- a/test/unit/lit/cloud_translation/providers/google_test.rb
+++ b/test/unit/lit/cloud_translation/providers/google_test.rb
@@ -24,17 +24,24 @@
'client_x509_cert_url' => 'https://www.googleapis.com/robot/v1/metadata/x509/redacted@redacted.iam.gserviceaccount.com' }
# rubocop:enable Metrics/LineLength
)
- Google::Cloud::Translate::Credentials.stubs(:new).returns(OpenStruct.new)
+ Google::Auth::Credentials.stubs(:new).returns(OpenStruct.new)
end
cloud_provider_examples(Lit::CloudTranslation::Providers::Google)
+ def gtranslate_api_class
+ if Gem.loaded_specs['google-cloud-translate'].version < Gem::Version.create('2.0')
+ ::Google::Cloud::Translate::Api
+ else
+ ::Google::Cloud::Translate::V2::Api
+ end
+ end
+
describe 'errors' do
describe 'when credentials error occurs' do
before do
- ::Google::Cloud::Translate::Api
- .any_instance
- .stubs(:translate)
+ gtranslate_api_class
+ .any_instance.stubs(:translate)
.raises(Signet::AuthorizationError, 'Credentials error')
end
@@ -47,9 +54,8 @@
describe 'when translation error occurs' do
before do
- ::Google::Cloud::Translate::Api
- .any_instance
- .stubs(:translate)
+ gtranslate_api_class
+ .any_instance.stubs(:translate)
.raises(::Google::Cloud::InternalError, 'Google failure')
end
@@ -60,4 +66,16 @@
end
end
end
+
+ describe 'edge cases' do
+ describe 'when text contains newline characters' do
+ let(:text) { "Some longer paragraph text\r\nOne line below" }
+
+ it 'translation comes back preserving those characters' do
+ result = Lit::CloudTranslation::Providers::Google.translate(text: text, to: 'pl')
+ assert result.include?("\r\n")
+ assert result.include?("tekstu akapitu \r\n Jeden wiersz")
+ end
+ end
+ end
end