Skip to content

Commit

Permalink
Edit page backend localization
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Jan 28, 2022
1 parent 15b835d commit 5477ac0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 30 deletions.
72 changes: 43 additions & 29 deletions app/edit/src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { aes, convert, time } = require("@levminer/lib")
const { aes, convert, time, localization } = require("@levminer/lib")
const logger = require("@levminer/lib/logger/renderer")
const { app, dialog } = require("@electron/remote")
const { ipcRenderer: ipc } = require("electron")
Expand All @@ -17,6 +17,13 @@ window.onerror = (error) => {
*/
logger.getWindow("edit")

/**
* Localization
*/
localization.localize("edit")

const lang = localization.getLang()

/**
* Check if running in development
*/
Expand Down Expand Up @@ -85,13 +92,14 @@ fs.readFile(path.join(cache_path, "rollback.authme"), "utf-8", (err, data) => {
const edited_date = fs.statSync(cache_path).atime

const year = edited_date.getFullYear()
const month = edited_date.toLocaleString("en-us", { month: "long" })
let month = edited_date.toLocaleString(lang.locale.code, { month: "long" })
month = month.charAt(0).toUpperCase() + month.slice(1)
const day = edited_date.toISOString().substring(8, 10)

const temp_date = `${year}. ${month} ${day}.`
const temp_time = `${edited_date.getHours().toString().padStart(2, "0")}:${edited_date.getMinutes().toString().padStart(2, "0")}:${edited_date.getSeconds().toString().padStart(2, "0")}`

rollback_text.innerHTML = `Latest rollback: <br /> ${temp_date} ${temp_time}`
rollback_text.innerHTML = `${lang.text.latest_save}: <br /> ${temp_date} ${temp_time}`
}
})

Expand All @@ -102,12 +110,12 @@ const loadRollback = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to rollback to the latest save? \n\nThis will overwrite your saved codes!",
message: lang.edit_dialog.load_rollback,
})
.then((result) => {
if (result.response === 0) {
Expand All @@ -123,9 +131,10 @@ const loadRollback = () => {

dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
type: "info",
message: "Rollback successful! \n\nGo back to the main page to check out the changes!",
noLink: true,
message: lang.edit_dialog.rollback_successful,
})
}
})
Expand Down Expand Up @@ -268,9 +277,12 @@ const del = (number) => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
type: "warning",
message: "Are you sure you want to delete this code? \n\nIf you want to revert this, click more options and revert changes.",
defaultId: 1,
cancelId: 1,
noLink: true,
message: lang.edit_dialog.delete_code,
})
.then((result) => {
if (result.response === 0) {
Expand Down Expand Up @@ -301,12 +313,12 @@ const createSave = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to save the modified code(s)? \n\nThis will overwrite your saved codes!",
message: lang.edit_dialog.create_save,
})
.then((result) => {
if (result.response === 0) {
Expand Down Expand Up @@ -396,9 +408,9 @@ const saveModifications = () => {
const addCodes = () => {
dialog
.showOpenDialog({
title: "Import from Authme file",
title: lang.application_dialog.choose_import_file,
properties: ["openFile", "multiSelections"],
filters: [{ name: "Authme file", extensions: ["authme"] }],
filters: [{ name: lang.application_dialog.authme_file, extensions: ["authme"] }],
})
.then((result) => {
canceled = result.canceled
Expand Down Expand Up @@ -436,12 +448,12 @@ const addCodes = () => {
} else {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
defaultId: 0,
cancelId: 0,
type: "error",
noLink: true,
message: `This file is an Authme ${loaded.role} file! \n\nYou need an Authme export or import file!`,
message: `${lang.application_dialog.old_file_0} ${loaded.role} ${lang.application_dialog.old_file_1}`,
})
}
}
Expand All @@ -450,12 +462,12 @@ const addCodes = () => {

dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
defaultId: 0,
cancelId: 0,
type: "info",
noLink: true,
message: "Code(s) added! \n\nScroll down to view them!",
message: lang.edit_dialog.codes_added,
})
}
})
Expand Down Expand Up @@ -495,9 +507,10 @@ const loadError = () => {
if (err) {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
type: "error",
message: "No save file found. \n\nGo back to the main page and save your codes!",
noLink: true,
message: lang.export_dialog.no_save_found,
})
}
})
Expand All @@ -513,22 +526,22 @@ const loadCodes = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to load your currently saved codes? \n\nThis will overwrite your latest rollback!",
message: lang.edit_dialog.load_codes,
})
.then((result) => {
if (result.response === 0) {
fs.readFile(path.join(folder_path, "codes", "codes.authme"), "utf-8", (err, data) => {
if (err) {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
type: "error",
message: "No save file found. \n\nGo back to the main page and save your codes!",
message: lang.export_dialog.no_save_found,
})
} else {
let password
Expand Down Expand Up @@ -581,9 +594,10 @@ const loadCodes = () => {
if (err) {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
buttons: [lang.button.close],
type: "error",
message: "No save file found. \n\nGo back to the main page and save your codes!",
noLink: true,
message: lang.export_dialog.no_save_found,
})
} else {
let password
Expand Down Expand Up @@ -657,12 +671,12 @@ const revertChanges = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to revert all current change(s)? \n\nYou will lose all current changes!",
message: lang.edit_dialog.revert_changes,
})
.then((result) => {
if (result.response === 0) {
Expand All @@ -678,12 +692,12 @@ const deleteCodes = () => {
dialog
.showMessageBox({
title: "Authme",
buttons: ["Yes", "Cancel"],
buttons: [lang.button.yes, lang.button.cancel],
defaultId: 1,
cancelId: 1,
type: "warning",
noLink: true,
message: "Are you sure you want to delete all codes? \n\nYou can revert this with a rollback.",
message: lang.edit_dialog.delete_all_codes,
})
.then((result) => {
if (result.response === 0) {
Expand Down
19 changes: 18 additions & 1 deletion languages/en.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* prettier-ignore */
/* cSpell:disable */
/* English */
module.exports = {
"locale": {
"code": "en",
Expand Down Expand Up @@ -244,6 +244,12 @@ module.exports = {
"Ideal for scanning the QR codes or for security backup.",
],

"export_dialog": {
"text_file": "Text file",
"html_file": "HTML file",
"no_save_found": "No save file found. \n\nGo back to the main page and save your codes!",
},

"edit": [
"Edit codes",
"You can edit or delete your existing codes and you can add more codes.",
Expand All @@ -262,4 +268,15 @@ module.exports = {
"Revert changes",
"Delete codes",
],

"edit_dialog": {
"load_rollback": "Are you sure you want to rollback to the latest save? \n\nThis will overwrite your saved codes!",
"rollback_successful": "Rollback successful! \n\nGo back to the main page to check out the changes!",
"delete_code": "Are you sure you want to delete this code? \n\nIf you want to revert this, click more options and revert changes.",
"create_save": "Are you sure you want to save the modified code(s)? \n\nThis will overwrite your saved codes!",
"codes_added": "Code(s) added! \n\nScroll down to view them!",
"load_codes": "Are you sure you want to load your currently saved codes? \n\nThis will overwrite your latest rollback!",
"revert_changes": "Are you sure you want to revert all current change(s)? \n\nYou will lose all current changes!",
"delete_all_codes": "Are you sure you want to delete all codes? \n\nYou can revert this with a rollback.",
},
}
1 change: 1 addition & 0 deletions preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { ipcRenderer: ipc } = require("electron")

/**
* Prevent default shortcuts
* @param {KeyboardEvent} event
*/
document.addEventListener("keydown", (event) => {
if (event.ctrlKey && event.code === "KeyA" && event.target.type !== "text" && event.target.type !== "number" && event.target.type !== "textarea" && event.target.type !== "password") {
Expand Down

0 comments on commit 5477ac0

Please sign in to comment.