Skip to content

Commit

Permalink
Merge pull request #450 from ZIMkaRU/feature/add-translation-support-…
Browse files Browse the repository at this point in the history
…to-remove-db

Add translation support to remove-db module
  • Loading branch information
ezewer authored Nov 21, 2024
2 parents c55ff55 + e1023af commit ab15001
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 17 deletions.
22 changes: 22 additions & 0 deletions build/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@
"description": "Importing DB ...",
"unzippedBytes": "DB size {{prettyUnzippedBytes}}"
}
},
"removeDB": {
"modalDialog": {
"clearDataTitle": "Clear all data",
"removeDBTitle": "Remove database",
"clearDataMessage": "Are you sure you want to clear all data?",
"removeDBMessage": "Are you sure you want to remove the database?"
},
"messageModalDialog": {
"dbRemovingTitle": "DB removing",
"dbDataHasBeenRemovedMessage": "DB data has been removed",
"dbDataHasNotBeenRemovedMessage": "DB data has not been removed",
"dbHasNotBeenRestoredTitle": "DB has not been restored",
"removeDBTitle": "Remove database",
"removeDBMessage": "Should all tables be removed?",
"confirmButtonText": "OK",
"cancelButtonText": "Cancel"
},
"loadingWindow": {
"removingDBDescription": "Removing DB ...",
"clearingAllDataDescription": "Clearing all data ..."
}
}
},
"menu": {
Expand Down
22 changes: 22 additions & 0 deletions build/locales/ru/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@
"description": "Импортирование БД ...",
"unzippedBytes": "размер БД {{prettyUnzippedBytes}}"
}
},
"removeDB": {
"modalDialog": {
"clearDataTitle": "Очистить все данные",
"removeDBTitle": "Удалить базу данных",
"clearDataMessage": "Вы уверены, что хотите удалить все данные?",
"removeDBMessage": "Вы уверены, что хотите удалить базу данных?"
},
"messageModalDialog": {
"dbRemovingTitle": "Удаление БД",
"dbDataHasBeenRemovedMessage": "Данные БД были удалены",
"dbDataHasNotBeenRemovedMessage": "Данные БД не были удалены",
"dbHasNotBeenRestoredTitle": "БД не восстановлена",
"removeDBTitle": "Удалить базу данных",
"removeDBMessage": "Следует ли удалить все таблицы?",
"confirmButtonText": "OK",
"cancelButtonText": "Отмена"
},
"loadingWindow": {
"removingDBDescription": "Удаление БД ...",
"clearingAllDataDescription": "Очистка всех данные ..."
}
}
},
"menu": {
Expand Down
25 changes: 15 additions & 10 deletions src/manage-worker-messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,20 @@ module.exports = (ipc) => {
await showWindow(win)

const haveNotAllDbDataBeenRemoved = state === PROCESS_MESSAGES.ALL_TABLE_HAVE_NOT_BEEN_REMOVED
const messChunk = haveNotAllDbDataBeenRemoved
? ' not'
: ''
const message = haveNotAllDbDataBeenRemoved
? i18next.t('common.removeDB.messageModalDialog.dbDataHasNotBeenRemovedMessage')
: i18next.t('common.removeDB.messageModalDialog.dbDataHasBeenRemovedMessage')
const type = haveNotAllDbDataBeenRemoved
? 'error'
: 'info'

await showMessageModalDialog(win, {
type,
title: 'DB removing',
message: `DB data have${messChunk} been removed`,
buttons: ['OK'],
title: i18next.t('common.removeDB.messageModalDialog.dbRemovingTitle'),
message,
buttons: [
i18next.t('common.removeDB.messageModalDialog.confirmButtonText')
],
defaultId: 0,
cancelId: 0
})
Expand Down Expand Up @@ -219,16 +221,19 @@ module.exports = (ipc) => {
}
if (state === PROCESS_MESSAGES.REQUEST_SHOULD_ALL_TABLES_BE_REMOVED) {
const title = data.isNotDbRestored
? 'DB has not been restored'
: 'Remove database'
? i18next.t('common.removeDB.messageModalDialog.dbHasNotBeenRestoredTitle')
: i18next.t('common.removeDB.messageModalDialog.removeDBTitle')

const {
btnId
} = await showMessageModalDialog(win, {
type: 'question',
title,
message: 'Should all tables be removed?',
buttons: ['Cancel', 'OK']
message: i18next.t('common.removeDB.messageModalDialog.removeDBMessage'),
buttons: [
i18next.t('common.removeDB.messageModalDialog.cancelButtonText'),
i18next.t('common.removeDB.messageModalDialog.confirmButtonText')
]
})

if (btnId === 0) {
Expand Down
27 changes: 20 additions & 7 deletions src/remove-db.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict'

const electron = require('electron')
const { BrowserWindow } = require('electron')
const i18next = require('i18next')

const ipcs = require('./ipcs')
const showErrorModalDialog = require('./show-error-modal-dialog')
const showMessageModalDialog = require('./show-message-modal-dialog')
const wins = require('./window-creators/windows')
const isMainWinAvailable = require('./helpers/is-main-win-available')
const pauseApp = require('./pause-app')
const relaunch = require('./relaunch')
const { rm } = require('./helpers')
Expand Down Expand Up @@ -85,13 +88,15 @@ module.exports = ({
shouldAllTablesBeCleared
}) => {
return async () => {
const win = electron.BrowserWindow.getFocusedWindow()
const win = isMainWinAvailable(wins.mainWindow)
? wins.mainWindow
: BrowserWindow.getFocusedWindow()
const title = shouldAllTablesBeCleared
? 'Clear all data'
: 'Remove database'
? i18next.t('common.removeDB.modalDialog.clearDataTitle')
: i18next.t('common.removeDB.modalDialog.removeDBTitle')
const message = shouldAllTablesBeCleared
? 'Are you sure you want to clear all data?'
: 'Are you sure you want to remove the database?'
? i18next.t('common.removeDB.modalDialog.clearDataMessage')
: i18next.t('common.removeDB.modalDialog.removeDBMessage')

try {
const {
Expand All @@ -114,6 +119,11 @@ module.exports = ({
}

await _clearAllTables()
},
loadingWinParams: {
description: shouldAllTablesBeCleared
? i18next.t('common.removeDB.loadingWindow.clearingAllDataDescription')
: i18next.t('common.removeDB.loadingWindow.removingDBDescription')
}
})

Expand All @@ -124,7 +134,10 @@ module.exports = ({
relaunch()
} catch (err) {
try {
await showErrorModalDialog(win, title, err)
const _win = isMainWinAvailable(wins.loadingWindow)
? wins.loadingWindow
: win
await showErrorModalDialog(_win, title, err)
} catch (err) {
console.error(err)
}
Expand Down

0 comments on commit ab15001

Please sign in to comment.