From f14945c155e819ec9c36c6789b69bea5f7e9b3c5 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 3 May 2024 15:02:46 +1000 Subject: [PATCH 1/2] More realistic test env for translations Most production servers don't use the source locale `en`. Even if the default language is English, they use a local variant like `en_AU` or `en_GB` to customise some of the translations. However the environment is configured, the app should always fallback to `en` if no other translation is available. --- .env | 4 ++-- spec/base_spec_helper.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.env b/.env index 3182c16226..5cdc06d8bd 100644 --- a/.env +++ b/.env @@ -10,10 +10,10 @@ TIMEZONE="Melbourne" DEFAULT_COUNTRY_CODE="AU" # Locale for translation. -LOCALE="en" +LOCALE="en_AU" # For multilingual - ENV doesn't have array so pass it as string with commas -AVAILABLE_LOCALES="en,es" +AVAILABLE_LOCALES="en_AU,es" # Spree zone. CHECKOUT_ZONE="Australia" diff --git a/spec/base_spec_helper.rb b/spec/base_spec_helper.rb index 6a307e9c3c..fcb68b76d6 100644 --- a/spec/base_spec_helper.rb +++ b/spec/base_spec_helper.rb @@ -141,7 +141,7 @@ RSpec.configure do |config| # Reset locale for all specs. config.around(:each) do |example| - I18n.with_locale(:en) { example.run } + I18n.with_locale(:en_AU) { example.run } end # Reset all feature toggles to prevent leaking. From 968456e5e04e77257e2c13e0aa04c0e764524cee Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 23 May 2024 15:10:24 +1000 Subject: [PATCH 2/2] Create special locale for test environment So hopefully we'll notice if our fallback mechanism fails. --- .env.development | 5 +++++ .env.test | 3 +++ config/locales/en_TEST.yml | 12 ++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 config/locales/en_TEST.yml diff --git a/.env.development b/.env.development index 1605f8ffba..68640acf21 100644 --- a/.env.development +++ b/.env.development @@ -5,6 +5,11 @@ # # cp .env.development .env.local +# Locale for translation. Using a locale other than `en` tests the +# successful fallback to `en`. You will also see up-to-date text used +# in production +LOCALE="en_AU" + VERBOSE_QUERY_LOGS=true SECRET_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" diff --git a/.env.test b/.env.test index 09881648aa..c0097a0416 100644 --- a/.env.test +++ b/.env.test @@ -1,6 +1,9 @@ # ENV vars for the test environment # Override locally with `.env.test.local` +# Locale for translation. +LOCALE="en_TEST" + OFN_REDIS_JOBS_URL="redis://localhost:6379/2" SECRET_TOKEN="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" diff --git a/config/locales/en_TEST.yml b/config/locales/en_TEST.yml new file mode 100644 index 0000000000..6aa6e4e7ec --- /dev/null +++ b/config/locales/en_TEST.yml @@ -0,0 +1,12 @@ +# Test language file +# --------------------- +# +# All production environments set their own locale. The source locale `en.yml` +# is used as a fallback but no server is using it directly. +# +# Using this test locale reflects that setup more realistically and means that +# we include fallback translations in our tests. +# +en: + # Overridden here due to a bug in spree i18n (Issue #870, and issue #1800) + language_name: "English" # Localised name of this language