Skip to content

Commit

Permalink
fix: Add translation support for closing window (#640)
Browse files Browse the repository at this point in the history
* chore: Made closing text translatable

* chore: closing text update clean up

* Use IPC for updating the closing screen message

* Remove extra show call

* Remove unused variable

Co-authored-by: ErikSin <67773827+ErikSin@users.noreply.github.com>
  • Loading branch information
achou11 and ErikSin authored Dec 14, 2021
1 parent 133534e commit 2c8123c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 3 deletions.
3 changes: 2 additions & 1 deletion messages/main/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,6 @@
"convert-button": "Copy to Editor",
"convert-number": "You have filtered your data to show {count} observations",
"convert-detail": "{count} of these are not yet in Map Editor. Click OK to move these {count} observations to Map Editor.",
"convert-nothing": "These are all already in the Map Editor."
"convert-nothing": "These are all already in the Map Editor.",
"closing-screen": "Mapeo is closing..."
}
9 changes: 9 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,15 @@ async function startup ({
try {
if (winMain && winMain.webContents) {
winMain.webContents.send.apply(winMain.webContents, args)

if (
winClosing &&
winClosing.webContents &&
args[0].startsWith('CLOSING:')
) {
winClosing.webContents.send.apply(winClosing.webContents, args)
}

return true
} else return false
} catch (e) {
Expand Down
5 changes: 5 additions & 0 deletions src/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,17 @@ module.exports = function (ipcSend) {
ipcMain.on('set-locale', function (ev, locale) {
app.translations = i18n.setLocale(locale)
i18n.save()
ipcSend('CLOSING:update-message', i18n.t('closing-screen'))
})

ipcMain.on('get-locale', function (ev) {
ev.returnValue = i18n.locale
})

ipcMain.handle('CLOSING:get-message', function () {
return i18n.t('closing-screen')
})

ipcMain.on('save-file', function () {
var metadata = userConfig.getSettings('metadata')
var ext = metadata ? metadata.dataset_id : 'mapeodata'
Expand Down
5 changes: 4 additions & 1 deletion src/main/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ function ClosingWindow () {
center: true,
frame: false,
show: false,
alwaysOnTop: true
alwaysOnTop: true,
webPreferences: {
preload: path.join(__dirname, '../../static/closingPreload.js')
}
})
}
3 changes: 2 additions & 1 deletion static/closing.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,13 @@
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
color: white;
text-align: center;
}
</style>
</head>
<body>
<div class="root">
<h1>
<h1 id="closingText">
Esperando que termina Mapeo...
</h1>
</div>
Expand Down
11 changes: 11 additions & 0 deletions static/closingPreload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { ipcRenderer } = require('electron')

window.addEventListener('DOMContentLoaded', () => {
ipcRenderer.invoke('CLOSING:get-message').then(updateDom)
ipcRenderer.on('CLOSING:update-message', (ev, message) => updateDom(message))
})

function updateDom (message) {
const closingH1 = document.getElementById('closingText')
if (closingH1) closingH1.textContent = message
}

0 comments on commit 2c8123c

Please sign in to comment.