🌐 (notification) add i18n for notif

This commit is contained in:
2020-07-18 23:41:27 +02:00
parent 62749a3bf7
commit 83245b1f12
4 changed files with 30 additions and 4 deletions

View File

@@ -3,6 +3,7 @@ import { StopwatchState } from '@/types/StopwatchState'
import { notify } from '@/utils/notification'
import { useInterval } from './useInterval'
import { useWakeLock } from './useWakeLock'
import i18n from '@/i18n'
const format = (num: number) => {
return num.toString().padStart(2, '0')
@@ -48,8 +49,8 @@ export const useTimer = () => {
const dev = isDev1Turn.value ? 'Dev 1' : 'Dev 2'
notify('Change!', {
body: `${dev}, your turn!`
notify(i18n.t('notification.change.title').toString(), {
body: i18n.t('notification.change.body', { dev }).toString()
})
}
}, 1000)

12
src/locales/en.json Normal file
View File

@@ -0,0 +1,12 @@
{
"notification": {
"update": {
"title": "An update is available!",
"body": "Reload the app to install the update."
},
"change": {
"title": "Change!",
"body": "{dev}, your turn"
}
}
}

12
src/locales/fr.json Normal file
View File

@@ -0,0 +1,12 @@
{
"notification": {
"update": {
"title": "Une mise à jour est disponible !",
"body": "Recharger l'application pour l'installer."
},
"change": {
"title": "Changement !",
"body": "À votre tour {dev}."
}
}
}

View File

@@ -2,6 +2,7 @@
import { register } from 'register-service-worker'
import { setNotificationInstance, notify } from './utils/notification'
import i18n from '@/i18n'
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
@@ -30,8 +31,8 @@ if (process.env.NODE_ENV === 'production') {
setNotificationInstance((title, options?) =>
sw.showNotification(title, options)
)
notify('An update is available!', {
body: `Reload the app to install the update.`,
notify(i18n.t('notification.update.title').toString(), {
body: i18n.t('notification.update.body').toString(),
tag: 'new-version'
})
},