FEATURE: Show available interpolation keys when overriding translations (#22220)

This is the first of a number of PRs aimed at helping admins manage their translation overrides. It simply adds a list of available interpolation keys below the input field when editing an override.

It also includes custom interpolation key.
This commit is contained in:
Ted Johansson
2023-06-28 19:03:04 +08:00
committed by GitHub
parent 7791bb1276
commit 6fc62586a2
8 changed files with 93 additions and 8 deletions

View File

@ -156,8 +156,12 @@ class Admin::SiteTextsController < Admin::AdminController
end
def record_for(key:, value: nil, locale:)
en_key = TranslationOverride.transform_pluralized_key(key)
value ||= I18n.with_locale(locale) { I18n.t(key) }
{ id: key, value: value, locale: locale }
interpolation_keys =
I18nInterpolationKeysFinder.find(I18n.overrides_disabled { I18n.t(en_key, locale: :en) })
custom_keys = TranslationOverride.custom_interpolation_keys(en_key)
{ id: key, value: value, locale: locale, interpolation_keys: interpolation_keys + custom_keys }
end
PLURALIZED_REGEX = /(.*)\.(zero|one|two|few|many|other)\z/