From e8d582269b8379bb6123f3ee2a3c5ae624963808 Mon Sep 17 00:00:00 2001 From: Tomazed Date: Mon, 30 Jan 2023 00:52:28 +0100 Subject: [PATCH] localized date-fns library --- client/plugins/i18n.js | 2 ++ client/plugins/init.client.js | 18 +++++++++++++++++- client/strings/de.json | 1 + client/strings/en-us.json | 1 + client/strings/es.json | 1 + client/strings/fr.json | 1 + client/strings/hr.json | 1 + client/strings/it.json | 1 + client/strings/pl.json | 1 + client/strings/zh-cn.json | 1 + 10 files changed, 27 insertions(+), 1 deletion(-) diff --git a/client/plugins/i18n.js b/client/plugins/i18n.js index bd8015f3..5616ea8e 100644 --- a/client/plugins/i18n.js +++ b/client/plugins/i18n.js @@ -73,6 +73,8 @@ async function loadi18n(code) { for (const key in Vue.prototype.$strings) { Vue.prototype.$strings[key] = strings[key] || translations[defaultCode][key] } + console.log(`ConfigDateFnsLocale = ${translations[code].ConfigDateFnsLocale}`) + Vue.prototype.$setDateFnsLocale(translations[code].ConfigDateFnsLocale) console.log('i18n strings=', Vue.prototype.$strings) Vue.prototype.$eventBus.$emit('change-lang', code) diff --git a/client/plugins/init.client.js b/client/plugins/init.client.js index 86aae006..5908165c 100644 --- a/client/plugins/init.client.js +++ b/client/plugins/init.client.js @@ -1,10 +1,26 @@ import Vue from 'vue' import Path from 'path' import vClickOutside from 'v-click-outside' -import { formatDistance, format, addDays, isDate } from 'date-fns' +import { formatDistance, format, addDays, isDate, setDefaultOptions } from 'date-fns' +import { de as localeDE, enUS as localeENUS, es as localeES, fr as localeFR, hr as localeHR, it as localeIT, pl as localePL, zhCN as localeZNCN } from 'date-fns/locale' +let locale = { + de: localeDE, + enUS: localeENUS, + es: localeES, + fr: localeFR, + hr: localeHR, + it: localeIT, + pl: localePL, + znCN: localeZNCN +} Vue.directive('click-outside', vClickOutside.directive) + +Vue.prototype.$setDateFnsLocale = (localeString) => { + if (!locale[localeString]) return 0 + return setDefaultOptions({locale: locale[localeString]}) +} Vue.prototype.$dateDistanceFromNow = (unixms) => { if (!unixms) return '' return formatDistance(unixms, Date.now(), { addSuffix: true }) diff --git a/client/strings/de.json b/client/strings/de.json index 81c8c910..ea4aec75 100644 --- a/client/strings/de.json +++ b/client/strings/de.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Benutzer {0} bearbeiten", "ButtonViewAll": "Alles anzeigen", "ButtonYes": "Ja", + "ConfigDateFnsLocale": "de", "HeaderAccount": "Konto", "HeaderAdvanced": "Erweitert", "HeaderAppriseNotificationSettings": "Apprise Benachrichtigungseinstellungen", diff --git a/client/strings/en-us.json b/client/strings/en-us.json index 2c68bba0..3a2b1d0d 100644 --- a/client/strings/en-us.json +++ b/client/strings/en-us.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Edit user {0}", "ButtonViewAll": "View All", "ButtonYes": "Yes", + "ConfigDateFnsLocale": "enUS", "HeaderAccount": "Account", "HeaderAdvanced": "Advanced", "HeaderAppriseNotificationSettings": "Apprise Notification Settings", diff --git a/client/strings/es.json b/client/strings/es.json index 2c68bba0..f3da9146 100644 --- a/client/strings/es.json +++ b/client/strings/es.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Edit user {0}", "ButtonViewAll": "View All", "ButtonYes": "Yes", + "ConfigDateFnsLocale": "es", "HeaderAccount": "Account", "HeaderAdvanced": "Advanced", "HeaderAppriseNotificationSettings": "Apprise Notification Settings", diff --git a/client/strings/fr.json b/client/strings/fr.json index d237c68d..815c90a4 100644 --- a/client/strings/fr.json +++ b/client/strings/fr.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Modifier l'utilisateur {0}", "ButtonViewAll": "Afficher Tout", "ButtonYes": "Oui", + "ConfigDateFnsLocale": "fr", "HeaderAccount": "Compte", "HeaderAdvanced": "Avancé", "HeaderAppriseNotificationSettings": "Configuration des Notifications Apprise", diff --git a/client/strings/hr.json b/client/strings/hr.json index bb144df1..17e7234f 100644 --- a/client/strings/hr.json +++ b/client/strings/hr.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Edit user {0}", "ButtonViewAll": "Prikaži sve", "ButtonYes": "Da", + "ConfigDateFnsLocale": "hr", "HeaderAccount": "Korisnički račun", "HeaderAdvanced": "Napredno", "HeaderAppriseNotificationSettings": "Apprise Notification Settings", diff --git a/client/strings/it.json b/client/strings/it.json index 15f0d9dd..1be82ce2 100644 --- a/client/strings/it.json +++ b/client/strings/it.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Modifica Utente {0}", "ButtonViewAll": "Mostra Tutto", "ButtonYes": "Si", + "ConfigDateFnsLocale": "it", "HeaderAccount": "Account", "HeaderAdvanced": "Avanzate", "HeaderAppriseNotificationSettings": "Apprendi le impostazioni di Notifica", diff --git a/client/strings/pl.json b/client/strings/pl.json index f87a79a3..d41ae912 100644 --- a/client/strings/pl.json +++ b/client/strings/pl.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "Edit user {0}", "ButtonViewAll": "Zobacz wszystko", "ButtonYes": "Tak", + "ConfigDateFnsLocale": "pl", "HeaderAccount": "Konto", "HeaderAdvanced": "Zaawansowane", "HeaderAppriseNotificationSettings": "Ustawienia powiadomień Apprise", diff --git a/client/strings/zh-cn.json b/client/strings/zh-cn.json index 4e594305..132f4704 100644 --- a/client/strings/zh-cn.json +++ b/client/strings/zh-cn.json @@ -80,6 +80,7 @@ "ButtonUserEdit": "编辑用户 {0}", "ButtonViewAll": "查看全部", "ButtonYes": "确定", + "ConfigDateFnsLocale": "znCN", "HeaderAccount": "帐户", "HeaderAdvanced": "高级", "HeaderAppriseNotificationSettings": "测试通知设置",