From 4580c63ac7ac38404c9bf95ec03b9bc8d32d1ec9 Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Sat, 26 Oct 2024 13:02:47 -0700 Subject: [PATCH] Desktop: Accessibility: Declare app locale with the HTML lang attribute (#11218) --- packages/app-desktop/app.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/packages/app-desktop/app.ts b/packages/app-desktop/app.ts index 311095269..e73c26150 100644 --- a/packages/app-desktop/app.ts +++ b/packages/app-desktop/app.ts @@ -118,13 +118,23 @@ class Application extends BaseApplication { } } + private updateLanguage() { + setLocale(Setting.value('locale')); + // The bridge runs within the main process, with its own instance of locale.js + // so it needs to be set too here. + bridge().setLocale(Setting.value('locale')); + + const htmlContainer = document.querySelector('html'); + // HTML expects the lang attribute to be in BCP47 format, with a dash rather than + // an underscore: + const htmlLang = Setting.value('locale').replace(/_/g, '-'); + htmlContainer.setAttribute('lang', htmlLang); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied protected async generalMiddleware(store: any, next: any, action: any) { if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'locale' || action.type === 'SETTING_UPDATE_ALL') { - setLocale(Setting.value('locale')); - // The bridge runs within the main process, with its own instance of locale.js - // so it needs to be set too here. - bridge().setLocale(Setting.value('locale')); + this.updateLanguage(); } if (action.type === 'SETTING_UPDATE_ONE' && action.key === 'showTrayIcon' || action.type === 'SETTING_UPDATE_ALL') {