FIX: Translation overrides from fallback locale didn't work on client

Discourse sent only translation overrides for the current language to the client instead of sending overrides from fallback locales as well. This especially impacted en_GB -> en since most overrides would be done in English instead of English (UK).

This also adds lots of tests for previously untested code.

There's a small caveat: The client currently doesn't handle fallback locales for MessageFormat strings. That is why overrides for those strings always have a higher priority than regular translations. So, as an example, the lookup order for MessageFormat strings in German is:
1. override for de
2. override for en
3. value from de
4. value from en
This commit is contained in:
Gerhard Schlager
2021-12-16 21:53:50 +01:00
committed by Gerhard Schlager
parent 4cd5158974
commit 769388b8ba
6 changed files with 223 additions and 65 deletions

View File

@@ -183,7 +183,7 @@ class Admin::SiteTextsController < Admin::AdminController
def find_translations(query, overridden, locale)
translations = Hash.new { |hash, key| hash[key] = {} }
search_results = I18n.with_locale(locale) do
I18n.search(query, overridden: overridden)
I18n.search(query, only_overridden: overridden)
end
search_results.each do |key, value|