Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add translation support to restore db #431

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions build/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
"title": "Update v{{version}} downloaded",
"description": "Should the app be updated right now?"
}
},
"restoreDB": {
"modalDialog": {
"title": "Select DB backup file",
"confirmButtonText": "OK",
"cancelButtonText": "Cancel"
},
"messageModalDialog": {
"title": "DB restoring",
"message": "Suitable DB backup file has not been found",
"dbRestoredMessage": "DB has been restored",
"dbNotRestoredMessage": "DB has not been restored",
"confirmButtonText": "OK"
}
}
},
"menu": {
Expand Down
14 changes: 14 additions & 0 deletions build/locales/ru/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@
"title": "Обновление v{{version}} загружено",
"description": "Стоит ли обновить приложение прямо сейчас?"
}
},
"restoreDB": {
"modalDialog": {
"title": "Выберите файл резервной копии БД",
"confirmButtonText": "OK",
"cancelButtonText": "Отменить"
},
"messageModalDialog": {
"title": "Восстановление БД",
"message": "Подходящий файл резервной копии БД не найден",
"dbRestoredMessage": "БД была восстановлена",
"dbNotRestoredMessage": "БД не была восстановлена",
"confirmButtonText": "OK"
}
}
},
"menu": {
Expand Down
17 changes: 17 additions & 0 deletions src/helpers/get-ui-fonts-as-css-string.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict'

const { rootPath } = require('electron-root-path')
const fs = require('fs')
const path = require('path')

const fontsPath = path.join(rootPath, 'bfx-report-ui/build/fonts/')
const fontsStyle = fs.readFileSync(
path.join(fontsPath, 'roboto.css'),
'utf8'
)
const fStyleWithNormalizedPaths = fontsStyle.replace(
/url\(\.\/(.*\..*)\)/g,
`url(${fontsPath}$1)`
)

module.exports = () => fStyleWithNormalizedPaths
4 changes: 3 additions & 1 deletion src/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getAlertCustomClassObj = require('./get-alert-custom-class-obj')
const parseEnvValToBool = require('./parse-env-val-to-bool')
const isBfxApiStaging = require('./is-bfx-api-staging')
const waitPort = require('./wait-port')
const getUIFontsAsCSSString = require('./get-ui-fonts-as-css-string')

module.exports = {
getFreePort,
Expand All @@ -29,5 +30,6 @@ module.exports = {
getAlertCustomClassObj,
parseEnvValToBool,
isBfxApiStaging,
waitPort
waitPort,
getUIFontsAsCSSString
}
17 changes: 7 additions & 10 deletions src/manage-worker-messages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

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

const wins = require('./window-creators/windows')
const relaunch = require('./relaunch')
Expand All @@ -27,10 +28,7 @@ const PROCESS_STATES = require(
)

module.exports = (ipc) => {
const win = isMainWinAvailable(
wins.mainWindow,
{ shouldCheckVisibility: true }
)
const win = isMainWinAvailable(wins.mainWindow)
? wins.mainWindow
: BrowserWindow.getFocusedWindow()

Expand Down Expand Up @@ -66,18 +64,17 @@ module.exports = (ipc) => {
await showWindow(win)

const hasNotDbBeenRestored = state === PROCESS_MESSAGES.DB_HAS_NOT_BEEN_RESTORED
const messChunk = hasNotDbBeenRestored
? ' not'
: ''
const type = hasNotDbBeenRestored
? 'error'
: 'info'

await showMessageModalDialog(win, {
type,
title: 'DB restoring',
message: `DB has${messChunk} been restored`,
buttons: ['OK'],
title: i18next.t('common.restoreDB.messageModalDialog.title'),
message: hasNotDbBeenRestored
? i18next.t('common.restoreDB.messageModalDialog.dbNotRestoredMessage')
: i18next.t('common.restoreDB.messageModalDialog.dbRestoredMessage'),
buttons: [i18next.t('common.restoreDB.messageModalDialog.confirmButtonText')],
defaultId: 0,
cancelId: 0
})
Expand Down
25 changes: 12 additions & 13 deletions src/restore-db/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { app, screen, remote } = require('electron')
const fs = require('fs')
const path = require('path')
const Alert = require('electron-alert')
const { rootPath } = require('electron-root-path')
const i18next = require('i18next')

const ipcs = require('../ipcs')
const wins = require('../window-creators/windows')
Expand All @@ -17,6 +17,9 @@ const isMainWinAvailable = require(
const getAlertCustomClassObj = require(
'../helpers/get-alert-custom-class-obj'
)
const getUIFontsAsCSSString = require(
'../helpers/get-ui-fonts-as-css-string'
)
const showMessageModalDialog = require(
'../show-message-modal-dialog'
)
Expand All @@ -31,9 +34,7 @@ const {
addOnceProcEventHandler
} = require('../window-creators/window-event-manager')

const fontsStyle = fs.readFileSync(path.join(
rootPath, 'bfx-report-ui/build/fonts/roboto.css'
))
const fontsStyle = getUIFontsAsCSSString()
const alertStyle = fs.readFileSync(path.join(
__dirname, '../modal-dialog-src/modal-dialog.css'
))
Expand All @@ -55,7 +56,7 @@ const sound = { freq: 'F2', type: 'triange', duration: 1.5 }

const _fireAlert = (params) => {
const {
title = 'Select DB backup file',
title = i18next.t('common.restoreDB.modalDialog.title'),
backupFilesMetadata
} = params
const win = wins.mainWindow
Expand Down Expand Up @@ -100,10 +101,7 @@ const _fireAlert = (params) => {
darkTheme: false,
parent: win,
modal: true,
width: 1000,
webPreferences: {
contextIsolation: false
}
minWidth: 1000
}
const swalOptions = {
position: 'center',
Expand All @@ -121,7 +119,8 @@ const _fireAlert = (params) => {
showConfirmButton: true,
focusCancel: true,
showCancelButton: true,
cancelButtonText: 'Cancel',
confirmButtonText: i18next.t('common.restoreDB.modalDialog.confirmButtonText'),
cancelButtonText: i18next.t('common.restoreDB.modalDialog.cancelButtonText'),
timerProgressBar: false,

input: 'radio',
Expand Down Expand Up @@ -238,9 +237,9 @@ module.exports = () => {
) {
await showMessageModalDialog(wins.mainWindow, {
type: 'warning',
title: 'DB restoring',
message: 'Suitable DB backup file has not been found',
buttons: ['OK'],
title: i18next.t('common.restoreDB.messageModalDialog.title'),
message: i18next.t('common.restoreDB.messageModalDialog.message'),
buttons: [i18next.t('common.restoreDB.messageModalDialog.confirmButtonText')],
defaultId: 0,
cancelId: 0
})
Expand Down