Handle promise linting (#5488)
This commit is contained in:
@@ -4,7 +4,7 @@ export async function deleteAllDatabases() {
|
||||
|
||||
for (const database of databases) {
|
||||
if (database.name) {
|
||||
await window.indexedDB.deleteDatabase(database.name);
|
||||
window.indexedDB.deleteDatabase(database.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ describe("i18n env is unset", () => {
|
||||
it("translation of key should match", () =>
|
||||
expect(i18n.t("Saving")).toBe("Saving"));
|
||||
|
||||
it("translation if changed to de-DE", () => {
|
||||
i18n.changeLanguage("de-DE");
|
||||
it("translation if changed to de-DE", async () => {
|
||||
await i18n.changeLanguage("de-DE");
|
||||
expect(i18n.t("Saving")).toBe("Speichert");
|
||||
});
|
||||
|
||||
it("translation if changed to pt-PT", () => {
|
||||
i18n.changeLanguage("pt-PT");
|
||||
it("translation if changed to pt-PT", async () => {
|
||||
await i18n.changeLanguage("pt-PT");
|
||||
expect(i18n.t("Saving")).toBe("A guardar");
|
||||
});
|
||||
});
|
||||
@@ -36,13 +36,13 @@ describe("i18n env is en-US", () => {
|
||||
it("translation of key should match", () =>
|
||||
expect(i18n.t("Saving")).toBe("Saving"));
|
||||
|
||||
it("translation if changed to de-DE", () => {
|
||||
i18n.changeLanguage("de-DE");
|
||||
it("translation if changed to de-DE", async () => {
|
||||
await i18n.changeLanguage("de-DE");
|
||||
expect(i18n.t("Saving")).toBe("Speichert");
|
||||
});
|
||||
|
||||
it("translation if changed to pt-PT", () => {
|
||||
i18n.changeLanguage("pt-PT");
|
||||
it("translation if changed to pt-PT", async () => {
|
||||
await i18n.changeLanguage("pt-PT");
|
||||
expect(i18n.t("Saving")).toBe("A guardar");
|
||||
});
|
||||
});
|
||||
@@ -58,13 +58,13 @@ describe("i18n env is de-DE", () => {
|
||||
it("translation of key should match", () =>
|
||||
expect(i18n.t("Saving")).toBe("Speichert"));
|
||||
|
||||
it("translation if changed to en-US", () => {
|
||||
i18n.changeLanguage("en-US");
|
||||
it("translation if changed to en-US", async () => {
|
||||
await i18n.changeLanguage("en-US");
|
||||
expect(i18n.t("Saving")).toBe("Saving");
|
||||
});
|
||||
|
||||
it("translation if changed to pt-PT", () => {
|
||||
i18n.changeLanguage("pt-PT");
|
||||
it("translation if changed to pt-PT", async () => {
|
||||
await i18n.changeLanguage("pt-PT");
|
||||
expect(i18n.t("Saving")).toBe("A guardar");
|
||||
});
|
||||
});
|
||||
@@ -80,13 +80,13 @@ describe("i18n env is pt-PT", () => {
|
||||
it("translation of key should match", () =>
|
||||
expect(i18n.t("Saving")).toBe("A guardar"));
|
||||
|
||||
it("translation if changed to en-US", () => {
|
||||
i18n.changeLanguage("en-US");
|
||||
it("translation if changed to en-US", async () => {
|
||||
await i18n.changeLanguage("en-US");
|
||||
expect(i18n.t("Saving")).toBe("Saving");
|
||||
});
|
||||
|
||||
it("translation if changed to de-DE", () => {
|
||||
i18n.changeLanguage("de-DE");
|
||||
it("translation if changed to de-DE", async () => {
|
||||
await i18n.changeLanguage("de-DE");
|
||||
expect(i18n.t("Saving")).toBe("Speichert");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,7 @@ import backend from "i18next-http-backend";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
import { languages } from "@shared/i18n";
|
||||
import { unicodeCLDRtoBCP47, unicodeBCP47toCLDR } from "@shared/utils/date";
|
||||
import Logger from "./Logger";
|
||||
|
||||
const locales = {
|
||||
de_DE: de,
|
||||
@@ -59,11 +60,12 @@ export function dateLocale(language: string | null | undefined) {
|
||||
*
|
||||
* @param defaultLanguage The default language to use if the user's language
|
||||
* is not supported.
|
||||
* @returns i18n instance
|
||||
* @returns A promise resolving to the i18n instance
|
||||
*/
|
||||
export function initI18n(defaultLanguage = "en_US") {
|
||||
const lng = unicodeCLDRtoBCP47(defaultLanguage);
|
||||
i18n
|
||||
|
||||
void i18n
|
||||
.use(backend)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
@@ -85,7 +87,11 @@ export function initI18n(defaultLanguage = "en_US") {
|
||||
supportedLngs: languages.map(unicodeCLDRtoBCP47),
|
||||
keySeparator: false,
|
||||
returnNull: false,
|
||||
})
|
||||
.catch((err) => {
|
||||
Logger.error("Failed to initialize i18n", err);
|
||||
});
|
||||
|
||||
return i18n;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ export function detectLanguage() {
|
||||
return `${ln}_${region}`;
|
||||
}
|
||||
|
||||
export function changeLanguage(
|
||||
export async function changeLanguage(
|
||||
toLanguageString: string | null | undefined,
|
||||
i18n: i18n
|
||||
) {
|
||||
@@ -19,7 +19,7 @@ export function changeLanguage(
|
||||
if (locale && i18n.languages?.[0] !== locale) {
|
||||
// Languages are stored in en_US format in the database, however the
|
||||
// frontend translation framework (i18next) expects en-US
|
||||
i18n.changeLanguage(locale);
|
||||
Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]);
|
||||
await i18n.changeLanguage(locale);
|
||||
await Desktop.bridge?.setSpellCheckerLanguages(["en-US", locale]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user