Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unescaped interpolated reserved key in help text and handle escaped interpolations in inconsistent interpolations check #553

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ en:
data_format: 'Data format: %{valid_text}.'
keep_order: Keep the order of the keys
key_pattern: Filter by key pattern (e.g. 'common.*')
key_pattern_to_rename: Full key (pattern) to rename. Required
locale: :i18n_tasks.common.locale
locale_to_translate_from: Locale to translate from
locales_filter: 'Locale(s) to process. Special: base'
missing_types: 'Filter by types: %{valid}'
new_key_name: New name, interpolates original name as %{key}. Required
nostdin: Do not read from stdin
out_format: 'Output format: %{valid_text}'
pattern_router: 'Use pattern router: keys moved per config data.write'
Expand All @@ -30,8 +28,8 @@ en:
the config setting if set.
translation_backend: Translation backend (google or deepl)
value: >-
Value. Interpolates: %{value}, %{human_key}, %{key}, %{default}, %{value_or_human_key},
%{value_or_default_or_human_key}
Value. Interpolates: %%{value}, %%{human_key}, %%{key}, %%{default}, %%{value_or_human_key},
%%{value_or_default_or_human_key}
desc:
add_missing: add missing keys to locale data, optionally match a pattern
check_consistent_interpolations: verify that all translations use correct interpolation variables
Expand Down
6 changes: 2 additions & 4 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,20 @@ ru:
data_format: 'Формат данных: %{valid_text}.'
keep_order: Keep the order of the keys
key_pattern: Маска ключа (например, common.*)
key_pattern_to_rename: Полный ключ (шаблон) для переименования. Необходимый параметр.
locale: 'Язык. По умолчанию: base'
locale_to_translate_from: 'Язык, с которого переводить (по умолчанию: base)'
locales_filter: >-
Список языков для обработки, разделенный запятыми (,). По умолчанию: все. Специальное
значение: base.
missing_types: 'Типы недостающих переводов: %{valid}. По умолчанию: все'
new_key_name: Новое имя, интерполирует оригинальное название как %{key}. Необходимый параметр.
nostdin: Не читать дерево из стандартного ввода
out_format: 'Формат вывода: %{valid_text}.'
pattern_router: 'Использовать pattern_router: ключи распределятся по файлам согласно data.write'
strict: Не угадывать динамические использования ключей, например `t("category.#{category.key}")`
translation_backend: Движок перевода (google или deepl)
value: >-
Значение, интерполируется с %{value}, %{human_key}, %{key}, %{default}, %{value_or_human_key},
%{value_or_default_or_human_key}
Значение, интерполируется с %%{value}, %%{human_key}, %%{key}, %%{default}, %%{value_or_human_key},
%%{value_or_default_or_human_key}
desc:
add_missing: добавить недостающие ключи к переводам
check_consistent_interpolations: убедитесь, что во всех переводах используются правильные
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/command/options/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module Common
arg :value,
'-v',
'--value VALUE',
t('i18n_tasks.cmd.args.desc.value')
t('i18n_tasks.cmd.args.desc.value', dummy: 'value') # Dummy value is workaround for https://github.com/ruby-i18n/i18n/issues/689
Bilka2 marked this conversation as resolved.
Show resolved Hide resolved

arg :config,
'-c',
Expand Down
2 changes: 1 addition & 1 deletion lib/i18n/tasks/interpolations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Interpolations
class << self
attr_accessor :variable_regex
end
@variable_regex = /%{[^}]+}/.freeze
@variable_regex = /(?<!%)%{[^}]+}/.freeze

def inconsistent_interpolations(locales: nil, base_locale: nil) # rubocop:disable Metrics/AbcSize
locales ||= self.locales
Expand Down
10 changes: 8 additions & 2 deletions spec/interpolations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
RSpec.describe 'Interpolations' do
let!(:task) { I18n::Tasks::BaseTask.new }

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' } }
let(:base_keys) do
{ 'a' => 'hello %{world}', 'b' => 'foo', 'c' => { 'd' => 'hello %{name}' }, 'e' => 'ok', 'f' => '%%{escaped}',
'g' => 'okay' }
end
let(:test_keys) do
{ 'a' => 'hello', 'b' => 'foo %{bar}', 'c' => { 'd' => 'hola %{amigo}' }, 'e' => 'ok', 'f' => 'okay',
'g' => '%%{ignored}' }
end

around do |ex|
TestCodebase.setup(
Expand Down