Skip to content

Commit

Permalink
Application localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jan 15, 2022
1 parent c7f40b4 commit e2d690c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions languages/main.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const en = require("./en")
const hu = require("./hu")

const languages = {
en,
hu,
}

module.exports = {
en,
hu,
languages,
}
26 changes: 26 additions & 0 deletions lib/localization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { languages } = require("@levminer/languages")
const electron = require("electron")

/**
* Localization
*/
module.exports = {
/**
* Localize the page
* @param {renderer} rendererName
*/
localize: (renderer) => {
const res = electron.ipcRenderer.sendSync("lang").lang_code
let loc_id = 0

document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll("[data-loc]").forEach(translateElements)
})

const translateElements = (element) => {
element.textContent = languages[res][renderer][loc_id]

loc_id++
}
},
}
2 changes: 2 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const typedef = require("./typedef")
const convert = require("./convert")
const time = require("./time")
const password = require("./password/index")
const localization = require("./localization")

// ? export modules
module.exports = {
Expand All @@ -19,4 +20,5 @@ module.exports = {
convert,
time,
password,
localization,
}
8 changes: 8 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,14 @@ ipc.on("loggerError", (event, data) => {
logger.rendererError(data.id, data.message, data.error)
})

/**
* Send lang code
*/
ipc.on("lang", (event) => {
const lang_code = app.getLocale().slice(0, 2)
event.returnValue = { lang_code }
})

/**
* Logger path
*/
Expand Down

0 comments on commit e2d690c

Please sign in to comment.