Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desktop: Accessibility: Declare app locale with the HTML lang attribute #11218

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/app-desktop/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down
Loading