Skip to content

Default to English the language switcher

What does this MR do and why?

Default to English the language switcher

Instead of crashing the language switcher componte when the cookie doesn't contain a preferred_language, now it defaults to English. Defensive programming.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Apply this patch
diff --git a/app/assets/javascripts/pages/devise/unlocks/show/index.js b/app/assets/javascripts/pages/devise/unlocks/show/index.js
new file mode 100644
index 000000000000..036c9374d3b3
--- /dev/null
+++ b/app/assets/javascripts/pages/devise/unlocks/show/index.js
@@ -0,0 +1,3 @@
+import { initLanguageSwitcher } from '~/language_switcher';
+
+initLanguageSwitcher();

Before

  1. On an incognito, go to a /users/unlock?token=asdf
  2. Delete the preferred_language value from the cookie, if any.
  3. Reload window
  4. No language switcher should be visible (bottom-right of the footer)
  5. Console error
index.js:13 TypeError: Cannot read properties of undefined (reading 'value')
index.js:13 TypeError: Cannot read properties of undefined (reading 'text')

After

  1. On an incognito, go to a /users/unlock?token=asdf
  2. Delete the preferred_language value from the cookie, if any.
  3. Reload window
  4. The language switcher should be visible:

image

Merge request reports

Loading