Refactor languageHandler to avoid import cycles (#33948)

* Refactor languageHandler to avoid import cycles

Also move its tests to vitest

* Small refactor

* Iterate

* Iterate
This commit is contained in:
Michael Telatynski
2026-06-24 10:49:49 +01:00
committed by GitHub
parent 29b9c04d20
commit f9b97be1d7
38 changed files with 780 additions and 555 deletions
+2 -1
View File
@@ -8,7 +8,8 @@ SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Com
Please see LICENSE files in the repository root for full details.
*/
import { _t, getUserLanguage } from "./languageHandler";
import { _t } from "./languageHandler";
import { getUserLanguage } from "./i18n/settings";
import { getUserTimezone } from "./TimezoneHandler";
export { formatSeconds } from "@element-hq/web-shared-components";
+1 -1
View File
@@ -18,7 +18,7 @@ import { logger } from "matrix-js-sdk/src/logger";
import Modal from "./Modal";
import TermsDialog from "./components/views/dialogs/TermsDialog";
import { pickBestLanguage } from "./languageHandler.tsx";
import { pickBestLanguage } from "./i18n/utils";
export class TermsNotSignedError extends Error {}
@@ -10,7 +10,8 @@ import React, { type ReactElement } from "react";
import { COUNTRIES, getEmojiFlag, type PhoneNumberCountryDefinition } from "../../../phonenumber";
import SdkConfig from "../../../SdkConfig";
import { _t, getUserLanguage } from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getUserLanguage } from "../../../i18n/settings";
import Dropdown from "../elements/Dropdown";
import { type NonEmptyArray } from "../../../@types/common";
@@ -25,7 +25,8 @@ import {
import { ErrorIcon } from "@vector-im/compound-design-tokens/assets/web/icons";
import BaseDialog from "./BaseDialog";
import { _t, getUserLanguage } from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getUserLanguage } from "../../../i18n/settings";
import AccessibleButton, { type AccessibleButtonKind } from "../elements/AccessibleButton";
import { ElementWidgetDriver } from "../../../stores/widgets/ElementWidgetDriver";
import { MatrixClientPeg } from "../../../MatrixClientPeg";
@@ -10,13 +10,14 @@ Please see LICENSE files in the repository root for full details.
import React, { type ReactElement } from "react";
import classNames from "classnames";
import * as languageHandler from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getAllLanguagesWithLabels } from "../../../i18n/utils";
import { getUserLanguage } from "../../../i18n/settings";
import Spinner from "./Spinner";
import Dropdown from "./Dropdown";
import { type NonEmptyArray } from "../../../@types/common";
type Languages = Awaited<ReturnType<typeof languageHandler.getAllLanguagesWithLabels>>;
type Languages = Awaited<ReturnType<typeof getAllLanguagesWithLabels>>;
function languageMatchesSearchQuery(query: string, language: Languages[0]): boolean {
if (language.labelInTargetLanguage.toUpperCase().includes(query.toUpperCase())) return true;
@@ -48,8 +49,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
}
public componentDidMount(): void {
languageHandler
.getAllLanguagesWithLabels()
getAllLanguagesWithLabels()
.then((langs) => {
langs.sort(function (a, b) {
if (a.labelInTargetLanguage < b.labelInTargetLanguage) return -1;
@@ -73,7 +73,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
if (!this.props.value) {
// If no value is given, we start with the first country selected,
// but our parent component doesn't know this, therefore we do this.
const language = languageHandler.getUserLanguage();
const language = getUserLanguage();
this.props.onOptionChange(language);
}
}
@@ -89,7 +89,7 @@ export default class LanguageDropdown extends React.Component<IProps, IState> {
return <Spinner />;
}
let displayedLanguages: Awaited<ReturnType<typeof languageHandler.getAllLanguagesWithLabels>>;
let displayedLanguages: Awaited<ReturnType<typeof getAllLanguagesWithLabels>>;
if (this.state.searchQuery) {
displayedLanguages = this.state.langs.filter((lang) => {
return languageMatchesSearchQuery(this.state.searchQuery, lang);
@@ -10,7 +10,8 @@ import React, { type ReactElement } from "react";
import Dropdown from "../../views/elements/Dropdown";
import PlatformPeg from "../../../PlatformPeg";
import { _t, getUserLanguage } from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getUserLanguage } from "../../../i18n/settings";
import Spinner from "./Spinner";
import { type NonEmptyArray } from "../../../@types/common";
@@ -10,7 +10,8 @@ import React from "react";
import SpellCheckLanguagesDropdown from "../../../components/views/elements/SpellCheckLanguagesDropdown";
import AccessibleButton, { type ButtonEvent } from "../../../components/views/elements/AccessibleButton";
import { _t, getUserLanguage } from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getUserLanguage } from "../../../i18n/settings";
interface ExistingSpellCheckLanguageIProps {
language: string;
@@ -0,0 +1,70 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
// @vitest-environment happy-dom
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import fetchMock from "@fetch-mock/vitest";
import SdkConfig from "../../src/SdkConfig";
import { setLanguage } from "./settings";
import { UserFriendlyError } from "./UserFriendlyError";
import { setupTranslationOverridesForTests } from "./__mocks__";
describe("UserFriendlyError", () => {
const testErrorMessage = "This email address is already in use (%(email)s)" as TranslationKey;
beforeEach(async () => {
await setLanguage("en");
// Setup some strings with variable substituations that we can use in the tests.
const deOverride = "Diese E-Mail-Adresse wird bereits verwendet (%(email)s)";
await setupTranslationOverridesForTests({
[testErrorMessage]: {
en: testErrorMessage,
de: deOverride,
},
});
});
afterEach(() => {
SdkConfig.reset();
fetchMock.removeRoute("i18n-override");
});
it("includes English message and localized translated message", async () => {
await setLanguage("de");
const friendlyError = new UserFriendlyError(testErrorMessage, {
email: "test@example.com",
cause: undefined,
});
// Ensure message is in English so it's readable in the logs
expect(friendlyError.message).toStrictEqual("This email address is already in use (test@example.com)");
// Ensure the translated message is localized appropriately
expect(friendlyError.translatedMessage).toStrictEqual(
"Diese E-Mail-Adresse wird bereits verwendet (test@example.com)",
);
});
it("includes underlying cause error", async () => {
await setLanguage("de");
const underlyingError = new Error("Fake underlying error");
const friendlyError = new UserFriendlyError(testErrorMessage, {
email: "test@example.com",
cause: underlyingError,
});
expect(friendlyError.cause).toStrictEqual(underlyingError);
});
it("ok to omit the substitution variables and cause object, there just won't be any cause", async () => {
const friendlyError = new UserFriendlyError("foo error" as TranslationKey);
expect(friendlyError.cause).toBeUndefined();
});
});
+52
View File
@@ -0,0 +1,52 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { type StringVariables } from "@element-hq/web-shared-components";
import { _t } from "@element-hq/web-shared-components";
export interface ErrorOptions {
// Because we're mixing the substitution variables and `cause` into the same object
// below, we want them to always explicitly say whether there is an underlying error
// or not to avoid typos of "cause" slipping through unnoticed.
cause: unknown | undefined;
}
/**
* Used to rethrow an error with a user-friendly translatable message while maintaining
* access to that original underlying error. Downstream consumers can display the
* `translatedMessage` property in the UI and inspect the underlying error with the
* `cause` property.
*
* The error message will display as English in the console and logs so Element
* developers can easily understand the error and find the source in the code. It also
* helps tools like Sentry deduplicate the error, or just generally searching in
* rageshakes to find all instances regardless of the users locale.
*
* @param message - The untranslated error message text, e.g "Something went wrong with %(foo)s".
* @param substitutionVariablesAndCause - Variable substitutions for the translation and
* original cause of the error. If there is no cause, just pass `undefined`, e.g { foo:
* 'bar', cause: err || undefined }
*/
export class UserFriendlyError extends Error {
public readonly translatedMessage: string;
public constructor(
message: TranslationKey,
substitutionVariablesAndCause?: Omit<StringVariables, keyof ErrorOptions> | ErrorOptions,
) {
// Prevent "Could not find /%\(cause\)s/g in x" logs to the console by removing it from the list
const { cause, ...substitutionVariables } = substitutionVariablesAndCause ?? {};
const errorOptions = { cause };
// Create the error with the English version of the message that we want to show up in the logs
const englishTranslatedMessage = _t(message, { ...substitutionVariables, locale: "en" });
super(englishTranslatedMessage, errorOptions);
// Also provide a translated version of the error in the users locale to display
this.translatedMessage = _t(message, substitutionVariables);
}
}
+30
View File
@@ -0,0 +1,30 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { type TranslationStringsObject } from "@matrix-org/react-sdk-module-api";
import { vi, beforeAll } from "vitest";
import fetchMock from "@fetch-mock/vitest";
import SdkConfig from "../../SdkConfig";
import { registerCustomTranslations } from "../custom";
beforeAll(() => {
vi.stubEnv("NODE_ENV", "test");
});
export async function setupTranslationOverridesForTests(overrides: TranslationStringsObject) {
const lookupUrl = "/translations.json";
SdkConfig.add({
custom_translations_url: lookupUrl,
});
fetchMock.get(lookupUrl, overrides, { name: "i18n-override" });
await registerCustomTranslations({
testOnlyIgnoreCustomTranslationsCache: true,
});
}
+36
View File
@@ -0,0 +1,36 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
// @vitest-environment happy-dom
import { vi, describe, it, expect, beforeEach } from "vitest";
import { getLanguagesFromBrowser } from "./browser";
describe("getLanguagesFromBrowser", () => {
beforeEach(() => {
vi.restoreAllMocks();
});
it("should return navigator.languages if available", () => {
vi.spyOn(window.navigator, "languages", "get").mockReturnValue(["en", "de"]);
expect(getLanguagesFromBrowser()).toEqual(["en", "de"]);
});
it("should return navigator.language if available", () => {
vi.spyOn(window.navigator, "languages", "get").mockReturnValue([]);
vi.spyOn(window.navigator, "language", "get").mockReturnValue("de");
expect(getLanguagesFromBrowser()).toEqual(["de"]);
});
it("should return 'en' otherwise", () => {
vi.spyOn(window.navigator, "languages", "get").mockReturnValue([]);
vi.spyOn(window.navigator, "language", "get").mockReturnValue(undefined as any);
expect(getLanguagesFromBrowser()).toEqual(["en"]);
});
});
+21
View File
@@ -0,0 +1,21 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
/**
* Query the browser for the user's language preferences
*/
export function getLanguagesFromBrowser(): readonly string[] {
if (navigator.languages && navigator.languages.length) return navigator.languages;
return [navigator.language ?? "en"];
}
/**
* Query the browser for the user's primary language preference
*/
export function getLanguageFromBrowser(): string {
return getLanguagesFromBrowser()[0];
}
+91
View File
@@ -0,0 +1,91 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
// @vitest-environment happy-dom
import { describe, it, expect, beforeEach, afterEach } from "vitest";
import fetchMock from "@fetch-mock/vitest";
import { type Translation } from "matrix-web-i18n";
import SdkConfig from "../../src/SdkConfig";
import { _t } from ".";
import { setLanguage } from "./settings";
import { setupTranslationOverridesForTests } from "./__mocks__";
describe("registerCustomTranslations", () => {
beforeEach(async () => {
await setLanguage("en");
});
afterEach(() => {
SdkConfig.reset();
fetchMock.removeRoute("i18n-override");
});
it("should support overriding translations", async () => {
const str: TranslationKey = "power_level|default";
const enOverride: Translation = "Visitor";
const deOverride: Translation = "Besucher";
// First test that overrides aren't being used
await setLanguage("en");
expect(_t(str)).toMatchInlineSnapshot(`"Default"`);
await setLanguage("de");
expect(_t(str)).toMatchInlineSnapshot(`"Standard"`);
await setupTranslationOverridesForTests({
[str]: {
en: enOverride,
de: deOverride,
},
});
// Now test that they *are* being used
await setLanguage("en");
expect(_t(str)).toEqual(enOverride);
await setLanguage("de");
expect(_t(str)).toEqual(deOverride);
});
it("should support overriding plural translations", async () => {
const str: TranslationKey = "voip|n_people_joined";
const enOverride: Translation = {
other: "%(count)s people in the call",
one: "%(count)s person in the call",
};
const deOverride: Translation = {
other: "%(count)s Personen im Anruf",
one: "%(count)s Person im Anruf",
};
// First test that overrides aren't being used
await setLanguage("en");
expect(_t(str, { count: 1 })).toMatchInlineSnapshot(`"1 person joined"`);
expect(_t(str, { count: 5 })).toMatchInlineSnapshot(`"5 people joined"`);
await setLanguage("de");
expect(_t(str, { count: 1 })).toMatchInlineSnapshot(`"1 Person beigetreten"`);
expect(_t(str, { count: 5 })).toMatchInlineSnapshot(`"5 Personen beigetreten"`);
await setupTranslationOverridesForTests({
[str]: {
en: enOverride,
de: deOverride,
},
});
// Now test that they *are* being used
await setLanguage("en");
expect(_t(str, { count: 1 })).toMatchInlineSnapshot(`"1 person in the call"`);
expect(_t(str, { count: 5 })).toMatchInlineSnapshot(`"5 people in the call"`);
await setLanguage("de");
expect(_t(str, { count: 1 })).toMatchInlineSnapshot(`"1 Person im Anruf"`);
expect(_t(str, { count: 5 })).toMatchInlineSnapshot(`"5 Personen im Anruf"`);
});
});
+82
View File
@@ -0,0 +1,82 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { MapWithDefault } from "matrix-js-sdk/src/utils";
import _ from "lodash";
import { type TranslationStringsObject } from "@matrix-org/react-sdk-module-api";
import { KEY_SEPARATOR, registerTranslations } from "@element-hq/web-shared-components";
import SdkConfig from "../SdkConfig";
import { ModuleRunner } from "../modules/ModuleRunner";
let cachedCustomTranslations: TranslationStringsObject | undefined;
let cachedCustomTranslationsExpire = 0; // zero to trigger expiration right away
/**
* Any custom modules with translations to load are parsed first, followed by an
* optionally defined translations file in the config. If no customization is made,
* or the file can't be parsed, no action will be taken.
*
* This function should be called *after* registering other translations data to
* ensure it overrides strings properly.
*/
export async function registerCustomTranslations({
testOnlyIgnoreCustomTranslationsCache = false,
}: {
testOnlyIgnoreCustomTranslationsCache?: boolean;
} = {}): Promise<void> {
const moduleTranslations = ModuleRunner.instance.allTranslations;
doRegisterTranslations(moduleTranslations);
const lookupUrl = SdkConfig.get().custom_translations_url;
if (!lookupUrl) return; // easy - nothing to do
try {
let json: TranslationStringsObject | undefined;
if (testOnlyIgnoreCustomTranslationsCache || Date.now() >= cachedCustomTranslationsExpire) {
json = (await (await fetch(lookupUrl)).json()) as TranslationStringsObject;
cachedCustomTranslations = json;
// Set expiration to the future, but not too far. Just trying to avoid
// repeated, successive, calls to the server rather than anything long-term.
cachedCustomTranslationsExpire = Date.now() + 5 * 60 * 1000;
} else {
json = cachedCustomTranslations;
}
// If the (potentially cached) json is invalid, don't use it.
if (!json) return;
// Finally, register it.
doRegisterTranslations(json);
} catch (e) {
// We consume all exceptions because it's considered non-fatal for custom
// translations to break. Most failures will be during initial development
// of the json file and not (hopefully) at runtime.
logger.warn("Ignoring error while registering custom translations: ", e);
// Like above: trigger a cache of the json to avoid successive calls.
cachedCustomTranslationsExpire = Date.now() + 5 * 60 * 1000;
}
}
function doRegisterTranslations(customTranslations: TranslationStringsObject): void {
// We convert the operator-friendly version into something counterpart can consume.
// Map: lang → Record: string → translation
const langs: MapWithDefault<string, Record<string, string>> = new MapWithDefault(() => ({}));
for (const [translationKey, translations] of Object.entries(customTranslations)) {
for (const [lang, translation] of Object.entries(translations)) {
_.set(langs.getOrCreate(lang), translationKey.split(KEY_SEPARATOR), translation);
}
}
// Finally, tell counterpart about our translations
for (const [lang, translations] of langs) {
registerTranslations(lang, translations);
}
}
+212
View File
@@ -0,0 +1,212 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
// @vitest-environment happy-dom
import React from "react";
import { describe, it, expect, beforeEach } from "vitest";
import {
setMissingEntryGenerator,
substitute,
type TranslatedString,
type IVariables,
type Tags,
} from "@element-hq/web-shared-components";
import { _t, _tDom } from ".";
import { setLanguage } from "./settings";
import { stubClient } from "../../test/test-utils";
describe("languageHandler", function () {
// See setupLanguage.ts for how we are stubbing out translations to provide fixture data for these tests
const basicString = "common|rooms";
const selfClosingTagSub = "Accept <policyLink /> to continue:" as TranslationKey;
const textInTagSub = "<a>Upgrade</a> to your own domain" as TranslationKey;
const plurals = "common|and_n_others";
const variableSub = "slash_command|ignore_dialog_description";
type TestCase = [string, TranslationKey, IVariables, Tags | undefined, TranslatedString];
const testCasesEn: TestCase[] = [
// description of the test case, translationString, variables, tags, expected result
["translates a basic string", basicString, {}, undefined, "Rooms"],
["handles plurals when count is 0", plurals, { count: 0 }, undefined, "and 0 others..."],
["handles plurals when count is 1", plurals, { count: 1 }, undefined, "and one other..."],
["handles plurals when count is not 1", plurals, { count: 2 }, undefined, "and 2 others..."],
["handles simple variable substitution", variableSub, { userId: "foo" }, undefined, "You are now ignoring foo"],
[
"handles simple tag substitution",
selfClosingTagSub,
{},
{ policyLink: () => "foo" },
"Accept foo to continue:",
],
["handles text in tags", textInTagSub, {}, { a: (sub: string) => `x${sub}x` }, "xUpgradex to your own domain"],
[
"handles variable substitution with React function component",
variableSub,
{ userId: () => <i>foo</i> },
undefined,
// eslint-disable-next-line react/jsx-key
<span>
You are now ignoring <i>foo</i>
</span>,
],
[
"handles variable substitution with react node",
variableSub,
{ userId: <i>foo</i> },
undefined,
// eslint-disable-next-line react/jsx-key
<span>
You are now ignoring <i>foo</i>
</span>,
],
[
"handles tag substitution with React function component",
selfClosingTagSub,
{},
{ policyLink: () => <i>foo</i> },
// eslint-disable-next-line react/jsx-key
<span>
Accept <i>foo</i> to continue:
</span>,
],
];
describe("when translations exist in language", () => {
beforeEach(async () => {
stubClient();
await setLanguage("en");
setMissingEntryGenerator((key) => key.split("|", 2)[1]);
});
it("translates a string to german", async () => {
await setLanguage("de");
const translated = _t(basicString);
expect(translated).toBe("Chats");
});
it.each(testCasesEn)("%s", (_d, translationString, variables, tags, result) => {
expect(_t(translationString, variables, tags!)).toEqual(result);
});
it("replacements in the wrong order", function () {
const text = "%(var1)s %(var2)s" as TranslationKey;
expect(_t(text, { var2: "val2", var1: "val1" })).toBe("val1 val2");
});
it("multiple replacements of the same variable", function () {
const text = "%(var1)s %(var1)s";
expect(substitute(text, { var1: "val1" })).toBe("val1 val1");
});
it("multiple replacements of the same tag", function () {
const text = "<a>Click here</a> to join the discussion! <a>or here</a>";
expect(substitute(text, {}, { a: (sub) => `x${sub}x` })).toBe(
"xClick herex to join the discussion! xor herex",
);
});
});
describe("for a non-en language", () => {
beforeEach(async () => {
stubClient();
await setLanguage("lv");
// counterpart doesn't expose any way to restore default config
// missingEntryGenerator is mocked in the root setup file
// reset to default here
const counterpartDefaultMissingEntryGen = function (key: string) {
return "missing translation: " + key;
};
setMissingEntryGenerator(counterpartDefaultMissingEntryGen);
});
// mocked lv has only `"Uploading %(filename)s and %(count)s others|one"`
const lvExistingPlural = "room|upload|uploading_multiple_file";
const lvNonExistingPlural = "%(spaceName)s and %(count)s others";
describe("pluralization", () => {
const pluralCases = [
[
"falls back when plural string exists but not for for count",
lvExistingPlural,
{ count: 2, filename: "test.txt" },
undefined,
"Uploading test.txt and 2 others",
],
[
"falls back when plural string does not exists at all",
lvNonExistingPlural,
{ count: 2, spaceName: "test" },
undefined,
"test and 2 others",
],
] as TestCase[];
describe("_t", () => {
it("translated correctly when plural string exists for count", () => {
expect(_t(lvExistingPlural, { count: 1, filename: "test.txt" })).toEqual(
"Качване на test.txt и 1 друг",
);
});
it.each(pluralCases)("%s", (_d, translationString, variables, tags, result) => {
expect(_t(translationString, variables, tags!)).toEqual(result);
});
});
describe("_tDom()", () => {
it("translated correctly when plural string exists for count", () => {
expect(_tDom(lvExistingPlural, { count: 1, filename: "test.txt" })).toEqual(
"Качване на test.txt и 1 друг",
);
});
it.each(pluralCases)(
"%s and translates with fallback locale, attributes fallback locale",
(_d, translationString, variables, tags, result) => {
expect(_tDom(translationString, variables, tags!)).toEqual(<span lang="en">{result}</span>);
},
);
});
});
describe("when a translation string does not exist in active language", () => {
describe("_t", () => {
it.each(testCasesEn)(
"%s and translates with fallback locale",
(_d, translationString, variables, tags, result) => {
expect(_t(translationString, variables, tags!)).toEqual(result);
},
);
});
describe("_tDom()", () => {
it.each(testCasesEn)(
"%s and translates with fallback locale, attributes fallback locale",
(_d, translationString, variables, tags, result) => {
expect(_tDom(translationString, variables, tags!)).toEqual(<span lang="en">{result}</span>);
},
);
});
});
});
describe("when languages dont load", () => {
it("_t", () => {
const STRING_NOT_IN_THE_DICTIONARY = "a string that isn't in the translations dictionary" as TranslationKey;
expect(_t(STRING_NOT_IN_THE_DICTIONARY, {})).toEqual(STRING_NOT_IN_THE_DICTIONARY);
});
it("_tDom", () => {
const STRING_NOT_IN_THE_DICTIONARY = "a string that isn't in the translations dictionary" as TranslationKey;
expect(_tDom(STRING_NOT_IN_THE_DICTIONARY, {})).toEqual(
<span lang="en">{STRING_NOT_IN_THE_DICTIONARY}</span>,
);
});
});
});
+27
View File
@@ -0,0 +1,27 @@
/*
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
/**
* This file is heavily imported and must be careful not to import anything which imports something else popular,
* e.g. SettingsStore as this would cause import cycles.
*/
export {
_t,
_td,
_tDom,
type IVariables,
type Tags,
type TranslatedString,
lookupString,
sanitizeForTranslation,
normalizeLanguageKey,
getNormalizedLanguageKeys,
getLocale as getCurrentLanguage,
} from "@element-hq/web-shared-components";
export * from "./UserFriendlyError";
+47
View File
@@ -0,0 +1,47 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { retry } from "../utils/promise";
const i18nFolder = "i18n/";
interface ICounterpartTranslation {
[key: string]:
| string
| {
[pluralisation: string]: string;
};
}
/**
* Fetch a language file with configurable retry behaviour
* @param langPath the name of the language file within the i18n dir
* @param num the number of times to retry
*/
export async function getLanguageRetry(langPath: string, num = 3): Promise<ICounterpartTranslation> {
return retry(
() => getLanguage(i18nFolder + langPath),
num,
(e) => {
logger.log("Failed to load i18n", langPath);
logger.error(e);
return true; // always retry
},
);
}
async function getLanguage(langPath: string): Promise<ICounterpartTranslation> {
const res = await fetch(langPath, { method: "GET" });
if (!res.ok) {
throw new Error(`Failed to load ${langPath}, got ${res.status}`);
}
return res.json();
}
+56
View File
@@ -0,0 +1,56 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { normalizeLanguageKey, getLangsJson, registerTranslations, setLocale } from "@element-hq/web-shared-components";
import SettingsStore from "../settings/SettingsStore";
import PlatformPeg from "../PlatformPeg";
import { SettingLevel } from "../settings/SettingLevel";
import { getLanguageRetry } from "./languages";
import { getLanguageFromBrowser } from "./browser";
import { registerCustomTranslations } from "./custom";
export function getUserLanguage(): string {
const language = SettingsStore.getValue("language", null, /*excludeDefault:*/ true);
if (typeof language === "string" && language !== "") {
return language;
} else {
return normalizeLanguageKey(getLanguageFromBrowser());
}
}
export async function setLanguage(...preferredLangs: string[]): Promise<void> {
PlatformPeg.get()?.setLanguage(preferredLangs);
const availableLanguages = await getLangsJson();
let chosenLanguage = preferredLangs.find((lang) => availableLanguages.hasOwnProperty(lang));
if (!chosenLanguage) {
// Fallback to en_EN if none is found
chosenLanguage = "en";
logger.error("Unable to find an appropriate language, preferred: ", preferredLangs);
}
const languageData = await getLanguageRetry(availableLanguages[chosenLanguage]);
registerTranslations(chosenLanguage, languageData);
setLocale(chosenLanguage);
await SettingsStore.setValue("language", null, SettingLevel.DEVICE, chosenLanguage);
// Adds a lot of noise to test runs, so disable logging there.
if (process.env.NODE_ENV !== "test") {
logger.log("set language to " + chosenLanguage);
}
// Set 'en' as fallback language:
if (chosenLanguage !== "en") {
const fallbackLanguageData = await getLanguageRetry(availableLanguages["en"]);
registerTranslations("en", fallbackLanguageData);
}
await registerCustomTranslations();
}
+45
View File
@@ -0,0 +1,45 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
// @vitest-environment happy-dom
import { describe, it, expect } from "vitest";
import fetchMock from "@fetch-mock/vitest";
import { getAllLanguagesWithLabels } from "./utils";
describe("getAllLanguagesWithLabels", () => {
it("should handle unknown language sanely", async () => {
fetchMock.modifyRoute("languages", {
response: {
en: "en_EN.json",
de: "de_DE.json",
qq: "qq.json",
},
});
await expect(getAllLanguagesWithLabels()).resolves.toMatchInlineSnapshot(`
[
{
"label": "English",
"labelInTargetLanguage": "English",
"value": "en",
},
{
"label": "German",
"labelInTargetLanguage": "Deutsch",
"value": "de",
},
{
"label": "qq",
"labelInTargetLanguage": "qq",
"value": "qq",
},
]
`);
});
});
+64
View File
@@ -0,0 +1,64 @@
/*
* Copyright 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { getLangsJson, getLocale, normalizeLanguageKey } from "@element-hq/web-shared-components";
async function getAllLanguagesFromJson(): Promise<string[]> {
return Object.keys(await getLangsJson());
}
type Language = {
value: string;
label: string; // translated
labelInTargetLanguage: string; // translated
};
export async function getAllLanguagesWithLabels(): Promise<Language[]> {
const languageNames = new Intl.DisplayNames([getLocale()], { type: "language", style: "short" });
const languages = await getAllLanguagesFromJson();
return languages.map<Language>((langKey) => {
return {
value: langKey,
label: languageNames.of(langKey)!,
labelInTargetLanguage: new Intl.DisplayNames([langKey], { type: "language", style: "short" }).of(langKey)!,
};
});
}
/**
* Given a list of language codes, pick the most appropriate one
* given the current language (ie. getCurrentLanguage())
* English is assumed to be a reasonable default.
*
* @param {string[]} langs List of language codes to pick from
* @returns {string} The most appropriate language code from langs
*/
export function pickBestLanguage(langs: string[]): string {
const currentLang = getLocale();
const normalisedLangs = langs.map(normalizeLanguageKey);
{
// Best is an exact match
const currentLangIndex = normalisedLangs.indexOf(currentLang);
if (currentLangIndex > -1) return langs[currentLangIndex];
}
{
// Failing that, a different dialect of the same language
const closeLangIndex = normalisedLangs.findIndex((l) => l.slice(0, 2) === currentLang.slice(0, 2));
if (closeLangIndex > -1) return langs[closeLangIndex];
}
{
// Neither of those? Try an english variant.
const enIndex = normalisedLangs.findIndex((l) => l.startsWith("en"));
if (enIndex > -1) return langs[enIndex];
}
// if nothing else, use the first
return langs[0];
}
+3 -295
View File
@@ -1,304 +1,12 @@
/*
* Copyright 2025 New Vector Ltd.
* Copyright 2026 Element Creations Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
* Please see LICENSE files in the repository root for full details.
*/
import { logger } from "matrix-js-sdk/src/logger";
import { MapWithDefault } from "matrix-js-sdk/src/utils";
import { type TranslationStringsObject } from "@matrix-org/react-sdk-module-api";
import _ from "lodash";
import {
_t,
normalizeLanguageKey,
type StringVariables,
KEY_SEPARATOR,
getLangsJson,
registerTranslations,
setLocale,
getLocale,
setMissingEntryGenerator as setMissingEntryGeneratorSharedComponents,
} from "@element-hq/web-shared-components";
import SettingsStore from "./settings/SettingsStore";
import PlatformPeg from "./PlatformPeg";
import { SettingLevel } from "./settings/SettingLevel";
import { retry } from "./utils/promise";
import SdkConfig from "./SdkConfig";
import { ModuleRunner } from "./modules/ModuleRunner";
export {
_t,
type IVariables,
type Tags,
type TranslatedString,
_td,
_tDom,
lookupString,
sanitizeForTranslation,
normalizeLanguageKey,
getNormalizedLanguageKeys,
substitute,
} from "@element-hq/web-shared-components";
const i18nFolder = "i18n/";
export interface ErrorOptions {
// Because we're mixing the substitution variables and `cause` into the same object
// below, we want them to always explicitly say whether there is an underlying error
// or not to avoid typos of "cause" slipping through unnoticed.
cause: unknown | undefined;
}
/**
* Used to rethrow an error with a user-friendly translatable message while maintaining
* access to that original underlying error. Downstream consumers can display the
* `translatedMessage` property in the UI and inspect the underlying error with the
* `cause` property.
*
* The error message will display as English in the console and logs so Element
* developers can easily understand the error and find the source in the code. It also
* helps tools like Sentry deduplicate the error, or just generally searching in
* rageshakes to find all instances regardless of the users locale.
*
* @param message - The untranslated error message text, e.g "Something went wrong with %(foo)s".
* @param substitutionVariablesAndCause - Variable substitutions for the translation and
* original cause of the error. If there is no cause, just pass `undefined`, e.g { foo:
* 'bar', cause: err || undefined }
* Re-export of the i18n main export, to lessen the diff for the pull request.
*/
export class UserFriendlyError extends Error {
public readonly translatedMessage: string;
public constructor(
message: TranslationKey,
substitutionVariablesAndCause?: Omit<StringVariables, keyof ErrorOptions> | ErrorOptions,
) {
// Prevent "Could not find /%\(cause\)s/g in x" logs to the console by removing it from the list
const { cause, ...substitutionVariables } = substitutionVariablesAndCause ?? {};
const errorOptions = { cause };
// Create the error with the English version of the message that we want to show up in the logs
const englishTranslatedMessage = _t(message, { ...substitutionVariables, locale: "en" });
super(englishTranslatedMessage, errorOptions);
// Also provide a translated version of the error in the users locale to display
this.translatedMessage = _t(message, substitutionVariables);
}
}
export function getUserLanguage(): string {
const language = SettingsStore.getValue("language", null, /*excludeDefault:*/ true);
if (typeof language === "string" && language !== "") {
return language;
} else {
return normalizeLanguageKey(getLanguageFromBrowser());
}
}
/**
* Allow overriding the text displayed when no translation exists
* Currently only used in unit tests to avoid having to load
* the translations in element-web
* @knipignore
*/
export function setMissingEntryGenerator(f: (value: string) => void): void {
setMissingEntryGeneratorSharedComponents(f);
}
export async function setLanguage(...preferredLangs: string[]): Promise<void> {
PlatformPeg.get()?.setLanguage(preferredLangs);
const availableLanguages = await getLangsJson();
let chosenLanguage = preferredLangs.find((lang) => availableLanguages.hasOwnProperty(lang));
if (!chosenLanguage) {
// Fallback to en_EN if none is found
chosenLanguage = "en";
logger.error("Unable to find an appropriate language, preferred: ", preferredLangs);
}
const languageData = await getLanguageRetry(i18nFolder + availableLanguages[chosenLanguage]);
registerTranslations(chosenLanguage, languageData);
setLocale(chosenLanguage);
await SettingsStore.setValue("language", null, SettingLevel.DEVICE, chosenLanguage);
// Adds a lot of noise to test runs, so disable logging there.
if (process.env.NODE_ENV !== "test") {
logger.log("set language to " + chosenLanguage);
}
// Set 'en' as fallback language:
if (chosenLanguage !== "en") {
const fallbackLanguageData = await getLanguageRetry(i18nFolder + availableLanguages["en"]);
registerTranslations("en", fallbackLanguageData);
}
await registerCustomTranslations();
}
type Language = {
value: string;
label: string; // translated
labelInTargetLanguage: string; // translated
};
export async function getAllLanguagesFromJson(): Promise<string[]> {
return Object.keys(await getLangsJson());
}
export async function getAllLanguagesWithLabels(): Promise<Language[]> {
const languageNames = new Intl.DisplayNames([getUserLanguage()], { type: "language", style: "short" });
const languages = await getAllLanguagesFromJson();
return languages.map<Language>((langKey) => {
return {
value: langKey,
label: languageNames.of(langKey)!,
labelInTargetLanguage: new Intl.DisplayNames([langKey], { type: "language", style: "short" }).of(langKey)!,
};
});
}
export function getLanguagesFromBrowser(): readonly string[] {
if (navigator.languages && navigator.languages.length) return navigator.languages;
return [navigator.language ?? "en"];
}
export function getLanguageFromBrowser(): string {
return getLanguagesFromBrowser()[0];
}
export function getCurrentLanguage(): string {
return getLocale();
}
/**
* Given a list of language codes, pick the most appropriate one
* given the current language (ie. getCurrentLanguage())
* English is assumed to be a reasonable default.
*
* @param {string[]} langs List of language codes to pick from
* @returns {string} The most appropriate language code from langs
*/
export function pickBestLanguage(langs: string[]): string {
const currentLang = getCurrentLanguage();
const normalisedLangs = langs.map(normalizeLanguageKey);
{
// Best is an exact match
const currentLangIndex = normalisedLangs.indexOf(currentLang);
if (currentLangIndex > -1) return langs[currentLangIndex];
}
{
// Failing that, a different dialect of the same language
const closeLangIndex = normalisedLangs.findIndex((l) => l.slice(0, 2) === currentLang.slice(0, 2));
if (closeLangIndex > -1) return langs[closeLangIndex];
}
{
// Neither of those? Try an english variant.
const enIndex = normalisedLangs.findIndex((l) => l.startsWith("en"));
if (enIndex > -1) return langs[enIndex];
}
// if nothing else, use the first
return langs[0];
}
interface ICounterpartTranslation {
[key: string]:
| string
| {
[pluralisation: string]: string;
};
}
async function getLanguageRetry(langPath: string, num = 3): Promise<ICounterpartTranslation> {
return retry(
() => getLanguage(langPath),
num,
(e) => {
logger.log("Failed to load i18n", langPath);
logger.error(e);
return true; // always retry
},
);
}
async function getLanguage(langPath: string): Promise<ICounterpartTranslation> {
const res = await fetch(langPath, { method: "GET" });
if (!res.ok) {
throw new Error(`Failed to load ${langPath}, got ${res.status}`);
}
return res.json();
}
let cachedCustomTranslations: TranslationStringsObject | undefined;
let cachedCustomTranslationsExpire = 0; // zero to trigger expiration right away
function doRegisterTranslations(customTranslations: TranslationStringsObject): void {
// We convert the operator-friendly version into something counterpart can consume.
// Map: lang → Record: string → translation
const langs: MapWithDefault<string, Record<string, string>> = new MapWithDefault(() => ({}));
for (const [translationKey, translations] of Object.entries(customTranslations)) {
for (const [lang, translation] of Object.entries(translations)) {
_.set(langs.getOrCreate(lang), translationKey.split(KEY_SEPARATOR), translation);
}
}
// Finally, tell counterpart about our translations
for (const [lang, translations] of langs) {
registerTranslations(lang, translations);
}
}
/**
* Any custom modules with translations to load are parsed first, followed by an
* optionally defined translations file in the config. If no customization is made,
* or the file can't be parsed, no action will be taken.
*
* This function should be called *after* registering other translations data to
* ensure it overrides strings properly.
*/
export async function registerCustomTranslations({
testOnlyIgnoreCustomTranslationsCache = false,
}: {
testOnlyIgnoreCustomTranslationsCache?: boolean;
} = {}): Promise<void> {
const moduleTranslations = ModuleRunner.instance.allTranslations;
doRegisterTranslations(moduleTranslations);
const lookupUrl = SdkConfig.get().custom_translations_url;
if (!lookupUrl) return; // easy - nothing to do
try {
let json: TranslationStringsObject | undefined;
if (testOnlyIgnoreCustomTranslationsCache || Date.now() >= cachedCustomTranslationsExpire) {
json = (await (await fetch(lookupUrl)).json()) as TranslationStringsObject;
cachedCustomTranslations = json;
// Set expiration to the future, but not too far. Just trying to avoid
// repeated, successive, calls to the server rather than anything long-term.
cachedCustomTranslationsExpire = Date.now() + 5 * 60 * 1000;
} else {
json = cachedCustomTranslations;
}
// If the (potentially cached) json is invalid, don't use it.
if (!json) return;
// Finally, register it.
doRegisterTranslations(json);
} catch (e) {
// We consume all exceptions because it's considered non-fatal for custom
// translations to break. Most failures will be during initial development
// of the json file and not (hopefully) at runtime.
logger.warn("Ignoring error while registering custom translations: ", e);
// Like above: trigger a cache of the json to avoid successive calls.
cachedCustomTranslationsExpire = Date.now() + 5 * 60 * 1000;
}
}
export * from "./i18n";
@@ -37,7 +37,8 @@ import {
} from "matrix-widget-api";
import { logger } from "matrix-js-sdk/src/logger";
import { _t, getUserLanguage } from "../../languageHandler";
import { _t } from "../../languageHandler";
import { getUserLanguage } from "../../i18n/settings";
import { ElementWidgetDriver } from "./ElementWidgetDriver";
import { WidgetMessagingStore } from "./WidgetMessagingStore";
import { MatrixClientPeg } from "../../MatrixClientPeg";
+20
View File
@@ -0,0 +1,20 @@
/*
Copyright 2026 Element Creations Ltd.
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { vi } from "vitest";
import { mocks } from "../../test/setup/mocks.ts";
// set up AudioContext API mock
vi.stubGlobal("AudioContext", function () {
return mocks.AudioContext;
});
if (globalThis.window === undefined) {
// We are in a node environment, stub a basic window so singletons work
vi.stubGlobal("window", {});
}
+66
View File
@@ -0,0 +1,66 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2022 The Matrix.org Foundation C.I.C.
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import fetchMock from "@fetch-mock/vitest";
import { merge } from "lodash";
import { setMissingEntryGenerator, setLanguage } from "@element-hq/web-shared-components";
import enElementWeb from "../i18n/strings/en_EN.json";
import deElementWeb from "../i18n/strings/de_DE.json";
// Cheat and import relatively here as these aren't exported by the module (should they be?)
// eslint-disable-next-line no-restricted-imports
import enSharedComponents from "../../../../packages/shared-components/src/i18n/strings/en_EN.json";
// eslint-disable-next-line no-restricted-imports
import deSharedComponents from "../../../../packages/shared-components/src/i18n/strings/de_DE.json";
const lv = {
Save: "Saglabāt",
room: {
upload: {
uploading_multiple_file: {
one: "Качване на %(filename)s и %(count)s друг",
},
},
},
};
// Fake languages.json containing references to en_EN, de_DE and lv
// en_EN.json
// de_DE.json
// lv.json - mock version with few translations, used to test fallback translation
export function setupLanguageMock() {
// Pull the translations from shared components too as they have
// the strings for things like `humanizeTime` which do appear in
// snapshots (needs 'merge' which does a deep-merge rather than just
// replacing top-level keys).
const enTranslations = merge(enElementWeb, enSharedComponents);
const deTranslations = merge(deElementWeb, deSharedComponents);
fetchMock
.get(
"end:/i18n/languages.json",
{
en: "en_EN.json",
de: "de_DE.json",
lv: "lv.json",
},
{ name: "languages" },
)
.get("end:en_EN.json", enTranslations)
.get("end:de_DE.json", deTranslations)
.get("end:lv.json", lv);
}
// Initialise the fetchMock before the test starts so the languageHandler.setLanguage call below can function
fetchMock.mockGlobal();
fetchMock.catch(404);
setupLanguageMock();
setLanguage("en");
setMissingEntryGenerator((key) => key.split("|", 2)[1]);
+6 -11
View File
@@ -5,11 +5,12 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
Please see LICENSE files in the repository root for full details.
*/
import { vi, beforeEach } from "vitest";
import { beforeEach, afterEach } from "vitest";
import fetchMock, { manageFetchMockGlobally } from "@fetch-mock/vitest";
import { mocks } from "../../test/setup/mocks.ts";
import SdkConfig, { DEFAULTS } from "../SdkConfig";
import "./setupGlobals.ts";
import { setupLanguageMock } from "./setupLanguage.ts";
manageFetchMockGlobally();
@@ -18,17 +19,11 @@ beforeEach(() => {
fetchMock.hardReset();
fetchMock.catch(404);
fetchMock.mockGlobal();
setupLanguageMock();
});
// set up AudioContext API mock
vi.stubGlobal("AudioContext", function () {
return mocks.AudioContext;
});
if (globalThis.window === undefined) {
// We are in a node environment, stub a basic window so singletons work
vi.stubGlobal("window", {});
}
afterEach(() => fetchMock.callHistory.flush());
// uninitialised SdkConfig causes lots of warnings in console, init with defaults
SdkConfig.put(DEFAULTS);
+2 -1
View File
@@ -10,7 +10,8 @@ Please see LICENSE files in the repository root for full details.
import { type ReactElement, type ReactNode } from "react";
import { useIdColorHash } from "@vector-im/compound-web";
import { _t, getCurrentLanguage, getUserLanguage } from "../languageHandler";
import { _t, getCurrentLanguage } from "../languageHandler";
import { getUserLanguage } from "../i18n/settings";
import { jsxJoin } from "./ReactUtils";
export { formatBytes } from "@element-hq/web-shared-components";
+7 -6
View File
@@ -12,8 +12,11 @@ import { createRoot } from "react-dom/client";
import React, { StrictMode } from "react";
import { logger } from "matrix-js-sdk/src/logger";
import { ModuleLoader } from "@element-hq/element-web-module-api";
import { getNormalizedLanguageKeys } from "@element-hq/web-shared-components";
import * as languageHandler from "../languageHandler";
import { getLanguagesFromBrowser } from "../i18n/browser";
import { setLanguage } from "../i18n/settings";
import { getCurrentLanguage } from "../i18n";
import SettingsStore from "../settings/SettingsStore";
import PlatformPeg from "../PlatformPeg";
import SdkConfig from "../SdkConfig";
@@ -68,15 +71,13 @@ export async function loadLanguage(): Promise<void> {
let langs: string[] = [];
if (!prefLang) {
languageHandler.getLanguagesFromBrowser().forEach((l) => {
langs.push(...languageHandler.getNormalizedLanguageKeys(l));
});
langs = getLanguagesFromBrowser().flatMap(getNormalizedLanguageKeys);
} else {
langs = [prefLang];
}
try {
await languageHandler.setLanguage(...langs);
document.documentElement.setAttribute("lang", languageHandler.getCurrentLanguage());
await setLanguage(...langs);
document.documentElement.setAttribute("lang", getCurrentLanguage());
} catch (e) {
logger.error("Unable to set language", e);
}
@@ -20,7 +20,8 @@ import { MatrixClientPeg } from "../../../MatrixClientPeg";
import dispatcher from "../../../dispatcher/dispatcher";
import { Action } from "../../../dispatcher/actions";
import { type ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload";
import { _t, getUserLanguage } from "../../../languageHandler";
import { _t } from "../../../languageHandler";
import { getUserLanguage } from "../../../i18n/settings";
import Modal from "../../../Modal";
import SettingsStore from "../../../settings/SettingsStore";
import { UIFeature } from "../../../settings/UIFeature";