mirror of
https://github.com/outline/outline.git
synced 2026-11-22 05:51:43 +03:00
Finished 1st MVP of i18n for outline
This commit is contained in:
1 parent
7899cf0c66
commit
8d883f89eb
6 files changed
+150
-23
No files matched your search
+3
-1
@@ -14,7 +14,9 @@ import Toasts from "components/Toasts";
|
||||
import Routes from "./routes";
|
||||
import env from "env";
|
||||
|
||||
import "shared/translations/i18n";
|
||||
import { outlineTranslation } from "shared/translations/i18n";
|
||||
|
||||
outlineTranslation.init();
|
||||
|
||||
const element = document.getElementById("root");
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"Created by me": "Von mir erstellt",
|
||||
"Profile saved": "Profil gespeichert",
|
||||
"Profile picture updated": "Profilfoto wurde aktualisiert",
|
||||
"Unable to upload new avatar": "Neuer Avatar kann nicht hochgeladen werden",
|
||||
"Unable to upload new profile picture": "Neuer Avatar kann nicht hochgeladen werden",
|
||||
"Profile": "Profil",
|
||||
"Photo": "Foto",
|
||||
"Upload": "Hochladen",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
"Created by me": "Created by me",
|
||||
"Profile saved": "Profile saved",
|
||||
"Profile picture updated": "Profile picture updated",
|
||||
"Unable to upload new avatar": "Unable to upload new avatar",
|
||||
"Unable to upload new profile picture": "Unable to upload new profile picture",
|
||||
"Profile": "Profile",
|
||||
"Photo": "Photo",
|
||||
"Upload": "Upload",
|
||||
|
||||
+28
-20
@@ -2,26 +2,34 @@
|
||||
import i18n from "i18next";
|
||||
import { initReactI18next } from "react-i18next";
|
||||
|
||||
import de_DE from "./de_DE.json";
|
||||
import en_US from "./default.json";
|
||||
import de_DE from "./de_DE.json";
|
||||
import pt_PT from "./pt_PT.json";
|
||||
|
||||
i18n.use(initReactI18next).init({
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
react: {
|
||||
useSuspense: false,
|
||||
},
|
||||
lng: process.env.DEFAULT_LANGUAGE,
|
||||
debug: process.env.NODE_ENV !== "production",
|
||||
resources: {
|
||||
en_US: {
|
||||
translation: en_US,
|
||||
},
|
||||
de_DE: {
|
||||
translation: de_DE,
|
||||
},
|
||||
},
|
||||
});
|
||||
const outlineTranslation = {
|
||||
init: () => {
|
||||
i18n.use(initReactI18next).init({
|
||||
interpolation: {
|
||||
escapeValue: false,
|
||||
},
|
||||
react: {
|
||||
useSuspense: false,
|
||||
},
|
||||
lng: "DEFAULT_LANGUAGE" in process.env ? process.env.DEFAULT_LANGUAGE : "en_US",
|
||||
debug: process.env.NODE_ENV !== "production",
|
||||
resources: {
|
||||
en_US: {
|
||||
translation: en_US,
|
||||
},
|
||||
de_DE: {
|
||||
translation: de_DE,
|
||||
},
|
||||
pt_PT: {
|
||||
translation: pt_PT
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default i18n;
|
||||
export { outlineTranslation, i18n, en_US, de_DE, pt_PT };
|
||||
@@ -0,0 +1,97 @@
|
||||
/* eslint-disable flowtype/require-valid-file-annotation */
|
||||
import { outlineTranslation, i18n, en_US, de_DE, pt_PT } from "./i18n";
|
||||
import { isEqual } from "lodash";
|
||||
|
||||
describe("i18n configuration", () => {
|
||||
beforeEach(() => {
|
||||
outlineTranslation.init();
|
||||
});
|
||||
it("all languages should have same keys", () => {
|
||||
const en_US_Keys = Object.keys(en_US);
|
||||
const de_DE_Keys = Object.keys(de_DE);
|
||||
const pt_PT_Keys = Object.keys(pt_PT);
|
||||
|
||||
expect(isEqual(en_US_Keys, de_DE_Keys)).toBe(true);
|
||||
expect(isEqual(en_US_Keys, pt_PT_Keys)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("i18n process.env is unset", () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.DEFAULT_LANGUAGE;
|
||||
outlineTranslation.init();
|
||||
});
|
||||
|
||||
it("translation of key should match", () => expect(i18n.t("Saving…")).toBe("Saving…"));
|
||||
|
||||
it ("translation if changed to de_DE", () => {
|
||||
i18n.changeLanguage("de_DE");
|
||||
expect(i18n.t("Saving…")).toBe("Am speichern…");
|
||||
});
|
||||
|
||||
it ("translation if changed to pt_PT", () => {
|
||||
i18n.changeLanguage("pt_PT");
|
||||
expect(i18n.t("Saving…")).toBe("A guardar…");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("i18n process.env is en_US", () => {
|
||||
beforeEach(() => {
|
||||
process.env.DEFAULT_LANGUAGE = "en_US";
|
||||
outlineTranslation.init();
|
||||
});
|
||||
|
||||
it("translation of key should match", () => expect(i18n.t("Saving…")).toBe("Saving…"));
|
||||
|
||||
it ("translation if changed to de_DE", () => {
|
||||
i18n.changeLanguage("de_DE");
|
||||
expect(i18n.t("Saving…")).toBe("Am speichern…");
|
||||
});
|
||||
|
||||
it ("translation if changed to pt_PT", () => {
|
||||
i18n.changeLanguage("pt_PT");
|
||||
expect(i18n.t("Saving…")).toBe("A guardar…");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("i18n process.env is de_DE", () => {
|
||||
beforeEach(() => {
|
||||
process.env.DEFAULT_LANGUAGE = "de_DE";
|
||||
outlineTranslation.init();
|
||||
});
|
||||
|
||||
it("translation of key should match", () => expect(i18n.t("Saving…")).toBe("Am speichern…"));
|
||||
|
||||
it ("translation if changed to en_US", () => {
|
||||
i18n.changeLanguage("en_US");
|
||||
expect(i18n.t("Saving…")).toBe("Saving…");
|
||||
});
|
||||
|
||||
it ("translation if changed to pt_PT", () => {
|
||||
i18n.changeLanguage("pt_PT");
|
||||
expect(i18n.t("Saving…")).toBe("A guardar…");
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("i18n process.env is pt_PT", () => {
|
||||
beforeEach(() => {
|
||||
process.env.DEFAULT_LANGUAGE = "pt_PT";
|
||||
outlineTranslation.init();
|
||||
});
|
||||
|
||||
it("translation of key should match", () => expect(i18n.t("Saving…")).toBe("A guardar…"));
|
||||
|
||||
it ("translation if changed to en_US", () => {
|
||||
i18n.changeLanguage("en_US");
|
||||
expect(i18n.t("Saving…")).toBe("Saving…");
|
||||
});
|
||||
|
||||
it ("translation if changed to de_DE", () => {
|
||||
i18n.changeLanguage("de_DE");
|
||||
expect(i18n.t("Saving…")).toBe("Am speichern…");
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"Home": "Home",
|
||||
"Recently updated": "Recently updated",
|
||||
"Recently viewed": "Recently viewed",
|
||||
"Created by me": "Created by me",
|
||||
"Profile saved": "Profile saved",
|
||||
"Profile picture updated": "Profile picture updated",
|
||||
"Unable to upload new profile picture": "Unable to upload new avatar",
|
||||
"Profile": "Profile",
|
||||
"Photo": "Photo",
|
||||
"Upload": "Upload",
|
||||
"Full name": "Full name",
|
||||
"Language": "Language",
|
||||
"Saving…": "A guardar…",
|
||||
"Save": "Save",
|
||||
"Delete Account": "Delete Account",
|
||||
"You may delete your account at any time, note that this is unrecoverable": "You may delete your account at any time, note that this is unrecoverable",
|
||||
"Delete account": "Delete account"
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user