Skip to content

Commit

Permalink
Add basic multi-language support
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Aug 7, 2021
1 parent e503553 commit 2e13ca8
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 323 deletions.
40 changes: 40 additions & 0 deletions locales/en/translation.json
@@ -0,0 +1,40 @@
{
"&File": "&File",
"Force &Reload": "Force &Reload",
"&Quit": "&Quit",
"&Edit": "&Edit",
"Undo": "Undo",
"Redo": "Redo",
"Cut": "Cut",
"Copy": "Copy",
"Paste": "Paste",
"Select All": "Select All",
"Language": "Language",
"en": "English (en)",
"hi": "हिंदी (hi)",
"Tab": "Tab",
"Add New Tab": "Add New Tab",
"Edit Active Tab": "Edit Active Tab",
"Close Active Tab": "Close Active Tab",
"Open Tab DevTools": "Open Tab DevTools",
"Restore Tab": "Restore Tab",
"Go to Next Tab": "Go to Next Tab",
"Go to Previous Tab": "Go to Previous Tab",
"Go to First Tab": "Go to First Tab",
"Go to Last Tab": "Go to Last Tab",
"&View": "&View",
"Toggle Fullscreen": "Toggle Fullscreen",
"Toggle Tab Bar": "Toggle Tab Bar",
"Themes": "Themes",
"Theme Manager": "Theme Manager",
"&Settings": "&Settings",
"&Help": "&Help",
"&About": "&About",
"Donate": "Donate",
"Check For &Updates": "Check For &Updates",
"Links": "Links",
"Report Bugs/Issues": "Report Bugs/Issues",
"Website": "Website",
"Repository": "Repository",
"Open &DevTools": "Open &DevTools"
}
Empty file.
40 changes: 40 additions & 0 deletions locales/hi/translation.json
@@ -0,0 +1,40 @@
{
"&File": "फ़ाइल",
"Force &Reload": "रीलोड करें",
"&Quit": "बंद करे",
"&Edit": "बदल",
"Undo": "पूर्ववत् करें",
"Redo": "फिर से करें",
"Cut": "कट करें",
"Copy": "कापी करें",
"Paste": "पेस्ट करें",
"Select All": "सभी का चयन करे",
"Language": "भाषा",
"en": "English (en)",
"hi": "हिंदी (hi)",
"Tab": "Tab",
"Add New Tab": "नया टैब खोलें",
"Edit Active Tab": "मौजूदा टैब बदलें",
"Close Active Tab": "मौजूदा टैब बंद करें",
"Open Tab DevTools": "टैब DevTools खोलें",
"Restore Tab": "पिछला टैब पुनः खोलें",
"Go to Next Tab": "अगले टैब पर जाएँ",
"Go to Previous Tab": "पिछले टैब पर जाएँ",
"Go to First Tab": "पहले टैब पर जाएँ",
"Go to Last Tab": "आखरी टैब पर जाएँ",
"&View": "दृश्य",
"Toggle Fullscreen": "Toggle Fullscreen",
"Toggle Tab Bar": "Toggle Tab Bar",
"Themes": "दिखावट",
"Theme Manager": "Theme Manager",
"&Settings": "सेटिंग्स",
"&Help": "मदद",
"&About": "Altus के बारे में",
"Donate": "योगदान करें",
"Check For &Updates": "अपडेट के लिये जांचें",
"Links": "लिंक",
"Report Bugs/Issues": "समस्या की सूचना दें",
"Website": "वेबसाइट",
"Repository": "GitHub",
"Open &DevTools": "DevTools खोलें"
}
Empty file.
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -104,6 +104,8 @@
"electron-dl": "^3.2.1",
"electron-reload": "^1.5.0",
"electron-store": "^8.0.0",
"i18next": "^20.3.5",
"i18next-node-fs-backend": "^2.1.3",
"node-fetch": "^2.6.1",
"sass": "^1.35.2",
"sirv-cli": "^1.0.12",
Expand Down
24 changes: 24 additions & 0 deletions src/i18next.conf.js
@@ -0,0 +1,24 @@
const i18n = require("i18next");
const backend = require("i18next-node-fs-backend");
const langConf = require("./lang.conf");

const i18nOptions = {
backend: {
loadPath: "./locales/{{lng}}/{{ns}}.json",
addPath: "./locales/{{lng}}/{{ns}}.missing.json",
jsonIndent: 2,
},
interpolation: {
espaceValue: true,
},
saveMissing: true,
fallbackLng: langConf.fallbackLang,
whitelist: langConf.languages,
react: {
wait: false,
},
};

i18n.use(backend);

module.exports = { i18n, i18nOptions };
14 changes: 13 additions & 1 deletion src/index.js
Expand Up @@ -26,6 +26,7 @@ const contextMenu = require("electron-context-menu");
const handleWhatsappLinks = require("./util/handleWhatsappLinks");
const electronDL = require("electron-dl");
const createCloneableMenuItem = require("./util/createCloneableMenuItem");
const { i18n, i18nOptions } = require("./i18next.conf");

let settings = new Store({
name: "settings",
Expand Down Expand Up @@ -120,7 +121,18 @@ const createMainWindow = () => {
windowState.store = mainWindow.getBounds();
});

Menu.setApplicationMenu(mainMenu);
if (!i18n.isInitialized) {
i18n.init(i18nOptions, (err, _) => {
i18n.on("loaded", () => {
i18n.changeLanguage(app.getLocale());
i18n.off("loaded");
});

i18n.on("languageChanged", (lang) => {
Menu.setApplicationMenu(mainMenu(i18n));
});
});
}
};

const singleInstanceLock = app.requestSingleInstanceLock();
Expand Down
5 changes: 5 additions & 0 deletions src/lang.conf.js
@@ -0,0 +1,5 @@
module.exports = {
languages: ["en", "hi"],
fallbackLang: "en",
namespace: "translation",
};

0 comments on commit 2e13ca8

Please sign in to comment.