From 383db5d48a1b5df8192cc8beca80d8687e88345d Mon Sep 17 00:00:00 2001 From: Tom Brouwer Date: Tue, 6 Feb 2024 16:52:10 +0100 Subject: [PATCH] 20321 Fix linter errors Introduced by previous commits, but never tested before Closes bookingexperts/support#20321 --- lib/i18n/tasks/translators/base_translator.rb | 2 +- lib/i18n/tasks/translators/deepl_translator.rb | 4 ++-- spec/deepl_translate_spec.rb | 13 +++++++++---- spec/interpolations_spec.rb | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/i18n/tasks/translators/base_translator.rb b/lib/i18n/tasks/translators/base_translator.rb index dd5ccd29..dbb5728d 100644 --- a/lib/i18n/tasks/translators/base_translator.rb +++ b/lib/i18n/tasks/translators/base_translator.rb @@ -104,7 +104,7 @@ def parse_value(untranslated, each_translated, opts) end end - INTERPOLATION_KEY_RE = /%\{[^\}]+\}|\{\{.*?\}\}|\{%.*?%\}/.freeze + INTERPOLATION_KEY_RE = /%\{[^}]+\}|\{\{.*?\}\}|\{%.*?%\}/.freeze UNTRANSLATABLE_STRING = 'X__' # @param [String] value diff --git a/lib/i18n/tasks/translators/deepl_translator.rb b/lib/i18n/tasks/translators/deepl_translator.rb index 1d587b02..5399b9ef 100644 --- a/lib/i18n/tasks/translators/deepl_translator.rb +++ b/lib/i18n/tasks/translators/deepl_translator.rb @@ -24,7 +24,7 @@ def initialize(*) def translate_values(list, from:, to:, **options) results = [] - if ( glossary = glossary_for(from, to) ) + if (glossary = glossary_for(from, to)) options.merge!({ glossary_id: glossary.id }) end @@ -102,7 +102,7 @@ def to_deepl_target_locale(locale) def glossary_for(source, target) DeepL.glossaries.list.select do |glossary| glossary.source_lang == source && glossary.target_lang == target - end.sort_by(&:entry_count).last + end.max_by(&:entry_count) end def configure_api_key! diff --git a/spec/deepl_translate_spec.rb b/spec/deepl_translate_spec.rb index 0e4ec128..79494a68 100644 --- a/spec/deepl_translate_spec.rb +++ b/spec/deepl_translate_spec.rb @@ -5,15 +5,20 @@ require 'deepl' RSpec.describe 'DeepL Translation' do - nil_value_test = ['nil-value-key', nil, nil] + nil_value_test = ['nil-value-key', nil, nil] text_test = [ 'key', - "Hello, %{user} O'Neill! How are you? {{ Check out this Liquid tag, it should not be translated }} {% That applies to this Liquid tag as well %}", - "¡Hola, %{user} O'Neill! ¿Qué tal estás? {{ Check out this Liquid tag, it should not be translated }} {% That applies to this Liquid tag as well %}" + "Hello, %{user} O'Neill! How are you? {{ Check out this Liquid tag, it should not be translated }} \ + {% That applies to this Liquid tag as well %}", + "¡Hola, %{user} O'Neill! ¿Qué tal estás? {{ Check out this Liquid tag, it should not be translated }} \ + {% That applies to this Liquid tag as well %}" ] - html_test_plrl = ['html-key.html.one', 'Hello %{count} {{ count }} {% count %}', 'Hola %{count} {{ count }} {% count %}'] + html_test_plrl = [ + 'html-key.html.one', 'Hello %{count} {{ count }} {% count %}', + 'Hola %{count} {{ count }} {% count %}' + ] array_test = ['array-key', ['Hello.', nil, '', 'Goodbye.'], ['Hola.', nil, '', 'Adiós.']] array_hash_test = ['array-hash-key', [{ 'hash_key1' => 'How are you?' }, { 'hash_key2' => nil }, { 'hash_key3' => 'Well.' }], diff --git a/spec/interpolations_spec.rb b/spec/interpolations_spec.rb index 6f4d9186..37f9b851 100644 --- a/spec/interpolations_spec.rb +++ b/spec/interpolations_spec.rb @@ -25,7 +25,7 @@ TestCodebase.teardown end - context 'ruby string interpolations' do + context 'when using ruby string interpolations' do let(:base_keys) { { 'a' => 'hello %{world}', 'b' => 'foo', 'c' => { 'd' => 'hello %{name}' }, 'e' => 'ok' } } let(:test_keys) { { 'a' => 'hello', 'b' => 'foo %{bar}', 'c' => { 'd' => 'hola %{amigo}' }, 'e' => 'ok' } } @@ -40,7 +40,7 @@ end end - context 'liquid tags' do + context 'when using liquid tags' do let(:base_keys) do { a: 'hello {{ world }}',