Skip to content

Commit

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

Add translation support to import-db module
  • Loading branch information
ezewer authored Nov 15, 2024
2 parents 6cea044 + dd5fb94 commit f7a3799
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
9 changes: 9 additions & 0 deletions build/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
"title": "Database export",
"message": "Exported successfully"
}
},
"importDB": {
"openDialog": {
"title": "Database import",
"buttonLabel": "Import"
},
"modalDialog": {
"title": "Database import"
}
}
},
"menu": {
Expand Down
9 changes: 9 additions & 0 deletions build/locales/ru/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@
"title": "Экспорт базы данных",
"message": "Экспортирована успешно"
}
},
"importDB": {
"openDialog": {
"title": "Импорт базы данных",
"buttonLabel": "Импортировать"
},
"modalDialog": {
"title": "Импорт базы данных"
}
}
},
"menu": {
Expand Down
19 changes: 14 additions & 5 deletions src/import-db.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

const {
InvalidFilePathError,
Expand All @@ -10,7 +11,8 @@ const { unzip } = require('./archiver')
const showErrorModalDialog = require('./show-error-modal-dialog')
const pauseApp = require('./pause-app')
const relaunch = require('./relaunch')
const { rm } = require('./helpers')
const { rm, isMainWinAvailable } = require('./helpers')
const wins = require('./window-creators/windows')
const {
DB_FILE_NAME,
DB_SHM_FILE_NAME,
Expand Down Expand Up @@ -39,7 +41,9 @@ module.exports = ({
pathToUserDocuments
}) => {
return async () => {
const win = BrowserWindow.getFocusedWindow()
const win = isMainWinAvailable(wins.mainWindow)
? wins.mainWindow
: BrowserWindow.getFocusedWindow()

try {
const {
Expand All @@ -48,9 +52,10 @@ module.exports = ({
} = await dialog.showOpenDialog(
win,
{
title: 'Database import',
title: i18next.t('common.importDB.openDialog.title'),
defaultPath: pathToUserDocuments,
buttonLabel: 'Import',
buttonLabel: i18next
.t('common.importDB.openDialog.buttonLabel'),
properties: [
'openFile',
'createDirectory',
Expand Down Expand Up @@ -95,7 +100,11 @@ module.exports = ({
relaunch()
} catch (err) {
try {
await showErrorModalDialog(win, 'Database import', err)
await showErrorModalDialog(
win,
i18next.t('common.importDB.modalDialog.title'),
err
)
} catch (err) {
console.error(err)
}
Expand Down

0 comments on commit f7a3799

Please sign in to comment.