From 8d4a94633c38132b17c3fa10fb1ae8a45003503f Mon Sep 17 00:00:00 2001 From: Henry Heino Date: Tue, 15 Oct 2024 16:11:18 -0700 Subject: [PATCH] Desktop: Accessibility: Declare app locale with the HTML lang attribute --- 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 31109526969..e73c261503d 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') {