chore: Move to Typescript (#2783)

This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
This commit is contained in:
Tom Moor
2021-11-29 06:40:55 -08:00
committed by GitHub
parent 25ccfb5d04
commit 15b1069bcc
1017 changed files with 17410 additions and 54942 deletions

View File

@@ -1,4 +1,3 @@
/* eslint-disable flowtype/require-valid-file-annotation */
import i18n from "i18next";
import de_DE from "./locales/de_DE/translation.json";
import en_US from "./locales/en_US/translation.json";
@@ -27,7 +26,6 @@ describe("i18n process.env is unset", () => {
expect(i18n.t("Saving")).toBe("A guardar");
});
});
describe("i18n process.env is en-US", () => {
beforeEach(() => {
process.env.DEFAULT_LANGUAGE = "en-US";
@@ -50,7 +48,6 @@ describe("i18n process.env is en-US", () => {
expect(i18n.t("Saving")).toBe("A guardar");
});
});
describe("i18n process.env is de-DE", () => {
beforeEach(() => {
process.env.DEFAULT_LANGUAGE = "de-DE";
@@ -73,7 +70,6 @@ describe("i18n process.env is de-DE", () => {
expect(i18n.t("Saving")).toBe("A guardar");
});
});
describe("i18n process.env is pt-PT", () => {
beforeEach(() => {
process.env.DEFAULT_LANGUAGE = "pt-PT";

View File

@@ -1,4 +1,3 @@
// @flow
import i18n from "i18next";
import backend from "i18next-http-backend";
import { initReactI18next } from "react-i18next";
@@ -6,20 +5,62 @@ import { initReactI18next } from "react-i18next";
// Note: Updating the available languages? Make sure to also update the
// locales array in app/utils/i18n.js to enable translation for timestamps.
export const languageOptions = [
{ label: "English (US)", value: "en_US" },
{ label: "简体中文 (Chinese, Simplified)", value: "zh_CN" },
{ label: "繁體中文 (Chinese, Traditional)", value: "zh_TW" },
{ label: "Deutsch (Deutschland)", value: "de_DE" },
{ label: "Español (España)", value: "es_ES" },
{ label: "فارسی (Persian)", value: "fa_IR" },
{ label: "Français (France)", value: "fr_FR" },
{ label: "Italiano (Italia)", value: "it_IT" },
{ label: "日本語 (Japanese)", value: "ja_JP" },
{ label: "한국어 (Korean)", value: "ko_KR" },
{ label: "Português (Brazil)", value: "pt_BR" },
{ label: "Português (Portugal)", value: "pt_PT" },
{ label: "Pусский (Россия)", value: "ru_RU" },
{ label: "Polskie (Polska)", value: "pl_PL" },
{
label: "English (US)",
value: "en_US",
},
{
label: "简体中文 (Chinese, Simplified)",
value: "zh_CN",
},
{
label: "繁體中文 (Chinese, Traditional)",
value: "zh_TW",
},
{
label: "Deutsch (Deutschland)",
value: "de_DE",
},
{
label: "Español (España)",
value: "es_ES",
},
{
label: "فارسی (Persian)",
value: "fa_IR",
},
{
label: "Français (France)",
value: "fr_FR",
},
{
label: "Italiano (Italia)",
value: "it_IT",
},
{
label: "日本語 (Japanese)",
value: "ja_JP",
},
{
label: "한국어 (Korean)",
value: "ko_KR",
},
{
label: "Português (Brazil)",
value: "pt_BR",
},
{
label: "Português (Portugal)",
value: "pt_PT",
},
{
label: "Pусский (Россия)",
value: "ru_RU",
},
{
label: "Polskie (Polska)",
value: "pl_PL",
},
];
export const languages: string[] = languageOptions.map((i) => i.value);
@@ -27,13 +68,14 @@ export const languages: string[] = languageOptions.map((i) => i.value);
// Languages are stored in en_US format in the database, however the
// frontend translation framework (i18next) expects en-US
const underscoreToDash = (text: string) => text.replace("_", "-");
const dashToUnderscore = (text: string) => text.replace("-", "_");
export const initI18n = () => {
const lng = underscoreToDash(
// @ts-expect-error ts-migrate(2345) FIXME: Argument of type 'string | undefined' is not assig... Remove this comment to see the full error message
"DEFAULT_LANGUAGE" in process.env ? process.env.DEFAULT_LANGUAGE : "en_US"
);
i18n
.use(backend)
.use(initReactI18next)
@@ -41,7 +83,7 @@ export const initI18n = () => {
backend: {
// this must match the path defined in routes. It's the path that the
// frontend UI code will hit to load missing translations.
loadPath: (languages: string[], namespaces: string[]) =>
loadPath: (languages: string[]) =>
`/locales/${dashToUnderscore(languages[0])}.json`,
},
interpolation: {
@@ -57,6 +99,5 @@ export const initI18n = () => {
// debug: process.env.NODE_ENV === "development",
keySeparator: false,
});
return i18n;
};