From 0c511535614a2725ead56d9257cdeaa8134fa535 Mon Sep 17 00:00:00 2001 From: micners Date: Mon, 18 Mar 2024 14:38:36 +0100 Subject: [PATCH 1/5] BC-6672 fix incorrect translation in alert --- helpers/i18n.js | 4 +++ locales/calendar/es.json | 17 +++++++++ .../scripts/helpers/AlertMessageController.js | 35 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 locales/calendar/es.json diff --git a/helpers/i18n.js b/helpers/i18n.js index 82b276ef58..88e0ad0220 100644 --- a/helpers/i18n.js +++ b/helpers/i18n.js @@ -7,6 +7,7 @@ const { Configuration } = require('@hpi-schul-cloud/commons'); const logger = require('./logger'); const api = require('../api'); const uk = require('../locales/calendar/uk.json'); +const es = require('../locales/calendar/es.json'); const i18nDebug = Configuration.get('I18N__DEBUG'); const fallbackLanguage = Configuration.get('I18N__FALLBACK_LANGUAGE'); @@ -133,6 +134,9 @@ const selectMomentOptions = (langAttribute) => { if (langAttribute === 'uk') { options.relativeTime = createCustomRelativeTimeConfig(uk); } + if (langAttribute === 'es') { + options.relativeTime = createCustomRelativeTimeConfig(es); + } return options; }; diff --git a/locales/calendar/es.json b/locales/calendar/es.json new file mode 100644 index 0000000000..2c6b899116 --- /dev/null +++ b/locales/calendar/es.json @@ -0,0 +1,17 @@ +{ + "moment.relativeTime.aDay": "un día", + "moment.relativeTime.days": "días", + "moment.relativeTime.futureIn": "en", + "moment.relativeTime.anHour": "una hora", + "moment.relativeTime.hours": "horas", + "moment.relativeTime.aMinute": "un minuto", + "moment.relativeTime.aMonths": "un mes", + "moment.relativeTime.minutes": "minutos", + "moment.relativeTime.months": "meses", + "moment.relativeTime.pastAgo": "hace", + "moment.relativeTime.aFewSecondes": "unos segundos", + "moment.relativeTime.seconds": "segundos", + "moment.relativeTime.aWeek": "una semana", + "moment.relativeTime.weeks": "semanas", + "moment.relativeTime.aYear": "un año" +} \ No newline at end of file diff --git a/static/scripts/helpers/AlertMessageController.js b/static/scripts/helpers/AlertMessageController.js index 8fb6d66653..7bd44750c4 100644 --- a/static/scripts/helpers/AlertMessageController.js +++ b/static/scripts/helpers/AlertMessageController.js @@ -1,4 +1,8 @@ +import moment from 'moment'; + const datetime = require('../datetime/datetime'); +const uk = require('../../../locales/calendar/uk.json'); +const es = require('../../../locales/calendar/es.json'); function getIconTag(status) { switch (status) { @@ -22,6 +26,8 @@ class AlertMessageController { buildMessage(message) { const icon = getIconTag(message.status); + const getLangAttribute = () => document.querySelector('html').getAttribute('lang'); + moment.locale(getLangAttribute(), this.selectMomentOptions(getLangAttribute())); const item = document.createElement('div'); if (this.loggedin) { item.className = 'alert-item'; @@ -53,6 +59,35 @@ class AlertMessageController { return item; } + createCustomRelativeTimeConfig = (localFile) => ({ + d: `${localFile['moment.relativeTime.aDay']}`, + dd: `%d ${localFile['moment.relativeTime.days']}`, + future: `${localFile['moment.relativeTime.futureIn']} %s`, + h: `${localFile['moment.relativeTime.anHour']}`, + hh: `%d ${localFile['moment.relativeTime.hours']}`, + m: `${localFile['moment.relativeTime.aMinute']}`, + M: `${localFile['moment.relativeTime.aMonths']}`, + mm: `%d ${localFile['moment.relativeTime.minutes']}`, + MM: `%d ${localFile['moment.relativeTime.months']}`, + past: `%s ${localFile['moment.relativeTime.pastAgo']}`, + s: `${localFile['moment.relativeTime.aFewSecondes']}`, + ss: `%d ${localFile['moment.relativeTime.seconds']}`, + w: `${localFile['moment.relativeTime.aWeek']}`, + ww: `%d ${localFile['moment.relativeTime.weeks']}`, + y: `${localFile['moment.relativeTime.aYear']}`, + }); + + selectMomentOptions = (langAttribute) => { + const options = {}; + if (langAttribute === 'uk') { + options.relativeTime = this.createCustomRelativeTimeConfig(uk); + } + if (langAttribute === 'es') { + options.relativeTime = this.createCustomRelativeTimeConfig(es); + } + return options; + }; + showAlert(messageArray) { if (!messageArray || messageArray.length === 0) { // If messageArray is empty, we do not show the triangle From 843a6f45b7ead4505ae093ff53e7ced212858b63 Mon Sep 17 00:00:00 2001 From: micners Date: Mon, 18 Mar 2024 15:30:55 +0100 Subject: [PATCH 2/5] BC-6672 --- .prettierrc.js | 7 +++ helpers/i18n.js | 56 +----------------- helpers/momentHelper.js | 58 +++++++++++++++++++ .../scripts/helpers/AlertMessageController.js | 34 +---------- 4 files changed, 69 insertions(+), 86 deletions(-) create mode 100644 .prettierrc.js create mode 100644 helpers/momentHelper.js diff --git a/.prettierrc.js b/.prettierrc.js new file mode 100644 index 0000000000..a8600eeee4 --- /dev/null +++ b/.prettierrc.js @@ -0,0 +1,7 @@ +module.exports = { + semi: true, + singleQuote: true, + printWidth: 120, + useTabs: true, + endOfLine: 'auto', +}; diff --git a/helpers/i18n.js b/helpers/i18n.js index 88e0ad0220..46999a86cc 100644 --- a/helpers/i18n.js +++ b/helpers/i18n.js @@ -6,8 +6,7 @@ const path = require('path'); const { Configuration } = require('@hpi-schul-cloud/commons'); const logger = require('./logger'); const api = require('../api'); -const uk = require('../locales/calendar/uk.json'); -const es = require('../locales/calendar/es.json'); +const momentHelper = require('./momentHelper'); const i18nDebug = Configuration.get('I18N__DEBUG'); const fallbackLanguage = Configuration.get('I18N__FALLBACK_LANGUAGE'); @@ -90,60 +89,9 @@ const getInstance = () => (key, options = {}) => i18next.t(key, { ...options, }); -/* -// const CONFIG_ORIG = i18nMoment().locale('en').localeData()._relativeTime; -const relativeTime = { - d: 'a day', - dd: '%d days', - future: 'in %s', - h: 'an hour', - hh: '%d hours', - m: 'a minute', - M: 'a month', - mm: '%d minutes', - MM: '%d months', - past: '%s ago', - s: 'a few seconds', - ss: '%d seconds', - w: 'a week', - ww: '%d weeks', - y: 'a year', -}; -*/ -const createCustomRelativeTimeConfig = (localFile) => ({ - d: `${localFile['moment.relativeTime.aDay']}`, - dd: `%d ${localFile['moment.relativeTime.days']}`, - future: `${localFile['moment.relativeTime.futureIn']} %s`, - h: `${localFile['moment.relativeTime.anHour']}`, - hh: `%d ${localFile['moment.relativeTime.hours']}`, - m: `${localFile['moment.relativeTime.aMinute']}`, - M: `${localFile['moment.relativeTime.aMonths']}`, - mm: `%d ${localFile['moment.relativeTime.minutes']}`, - MM: `%d ${localFile['moment.relativeTime.months']}`, - past: `%s ${localFile['moment.relativeTime.pastAgo']}`, - s: `${localFile['moment.relativeTime.aFewSecondes']}`, - ss: `%d ${localFile['moment.relativeTime.seconds']}`, - w: `${localFile['moment.relativeTime.aWeek']}`, - ww: `%d ${localFile['moment.relativeTime.weeks']}`, - y: `${localFile['moment.relativeTime.aYear']}`, -}); - -const selectMomentOptions = (langAttribute) => { - const options = {}; - - if (langAttribute === 'uk') { - options.relativeTime = createCustomRelativeTimeConfig(uk); - } - if (langAttribute === 'es') { - options.relativeTime = createCustomRelativeTimeConfig(es); - } - - return options; -}; - const changeLanguage = (langAttribute) => { if (availableLanguages.includes(langAttribute)) { - const momentOptions = selectMomentOptions(langAttribute); + const momentOptions = momentHelper.selectMomentOptions(langAttribute); i18nMoment.locale(langAttribute, momentOptions); return i18next.changeLanguage(langAttribute); } diff --git a/helpers/momentHelper.js b/helpers/momentHelper.js new file mode 100644 index 0000000000..bebf7a65f7 --- /dev/null +++ b/helpers/momentHelper.js @@ -0,0 +1,58 @@ +const uk = require('../locales/calendar/uk.json'); +const es = require('../locales/calendar/es.json'); + +/* +// const CONFIG_ORIG = i18nMoment().locale('en').localeData()._relativeTime; +const relativeTime = { + d: 'a day', + dd: '%d days', + future: 'in %s', + h: 'an hour', + hh: '%d hours', + m: 'a minute', + M: 'a month', + mm: '%d minutes', + MM: '%d months', + past: '%s ago', + s: 'a few seconds', + ss: '%d seconds', + w: 'a week', + ww: '%d weeks', + y: 'a year', +}; +*/ + +const createCustomRelativeTimeConfig = (localFile) => ({ + d: `${localFile['moment.relativeTime.aDay']}`, + dd: `%d ${localFile['moment.relativeTime.days']}`, + future: `${localFile['moment.relativeTime.futureIn']} %s`, + h: `${localFile['moment.relativeTime.anHour']}`, + hh: `%d ${localFile['moment.relativeTime.hours']}`, + m: `${localFile['moment.relativeTime.aMinute']}`, + M: `${localFile['moment.relativeTime.aMonths']}`, + mm: `%d ${localFile['moment.relativeTime.minutes']}`, + MM: `%d ${localFile['moment.relativeTime.months']}`, + past: `%s ${localFile['moment.relativeTime.pastAgo']}`, + s: `${localFile['moment.relativeTime.aFewSecondes']}`, + ss: `%d ${localFile['moment.relativeTime.seconds']}`, + w: `${localFile['moment.relativeTime.aWeek']}`, + ww: `%d ${localFile['moment.relativeTime.weeks']}`, + y: `${localFile['moment.relativeTime.aYear']}`, +}); + +const selectMomentOptions = (langAttribute) => { + const options = {}; + + if (langAttribute === 'uk') { + options.relativeTime = createCustomRelativeTimeConfig(uk); + } + if (langAttribute === 'es') { + options.relativeTime = createCustomRelativeTimeConfig(es); + } + + return options; +}; + +module.exports = { + selectMomentOptions, +}; diff --git a/static/scripts/helpers/AlertMessageController.js b/static/scripts/helpers/AlertMessageController.js index 7bd44750c4..ac9f6d0c0d 100644 --- a/static/scripts/helpers/AlertMessageController.js +++ b/static/scripts/helpers/AlertMessageController.js @@ -1,8 +1,7 @@ import moment from 'moment'; const datetime = require('../datetime/datetime'); -const uk = require('../../../locales/calendar/uk.json'); -const es = require('../../../locales/calendar/es.json'); +const momentHelper = require('../../../helpers/momentHelper'); function getIconTag(status) { switch (status) { @@ -27,7 +26,7 @@ class AlertMessageController { const icon = getIconTag(message.status); const getLangAttribute = () => document.querySelector('html').getAttribute('lang'); - moment.locale(getLangAttribute(), this.selectMomentOptions(getLangAttribute())); + moment.locale(getLangAttribute(), momentHelper.selectMomentOptions(getLangAttribute())); const item = document.createElement('div'); if (this.loggedin) { item.className = 'alert-item'; @@ -59,35 +58,6 @@ class AlertMessageController { return item; } - createCustomRelativeTimeConfig = (localFile) => ({ - d: `${localFile['moment.relativeTime.aDay']}`, - dd: `%d ${localFile['moment.relativeTime.days']}`, - future: `${localFile['moment.relativeTime.futureIn']} %s`, - h: `${localFile['moment.relativeTime.anHour']}`, - hh: `%d ${localFile['moment.relativeTime.hours']}`, - m: `${localFile['moment.relativeTime.aMinute']}`, - M: `${localFile['moment.relativeTime.aMonths']}`, - mm: `%d ${localFile['moment.relativeTime.minutes']}`, - MM: `%d ${localFile['moment.relativeTime.months']}`, - past: `%s ${localFile['moment.relativeTime.pastAgo']}`, - s: `${localFile['moment.relativeTime.aFewSecondes']}`, - ss: `%d ${localFile['moment.relativeTime.seconds']}`, - w: `${localFile['moment.relativeTime.aWeek']}`, - ww: `%d ${localFile['moment.relativeTime.weeks']}`, - y: `${localFile['moment.relativeTime.aYear']}`, - }); - - selectMomentOptions = (langAttribute) => { - const options = {}; - if (langAttribute === 'uk') { - options.relativeTime = this.createCustomRelativeTimeConfig(uk); - } - if (langAttribute === 'es') { - options.relativeTime = this.createCustomRelativeTimeConfig(es); - } - return options; - }; - showAlert(messageArray) { if (!messageArray || messageArray.length === 0) { // If messageArray is empty, we do not show the triangle From 407dfa9e338e32f43cfcd2f59e5f2b72dc557270 Mon Sep 17 00:00:00 2001 From: micners Date: Tue, 19 Mar 2024 12:58:55 +0100 Subject: [PATCH 3/5] BC-6672 --- .prettierrc.js | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .prettierrc.js diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index a8600eeee4..0000000000 --- a/.prettierrc.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = { - semi: true, - singleQuote: true, - printWidth: 120, - useTabs: true, - endOfLine: 'auto', -}; From 4a4127c79222d01b24ab84b3bb36c9e962d056fa Mon Sep 17 00:00:00 2001 From: micners Date: Thu, 21 Mar 2024 11:48:10 +0100 Subject: [PATCH 4/5] BC-6672-fix-incorrect-alert-translation --- helpers/momentHelper.js | 4 ++++ locales/calendar/de.json | 17 +++++++++++++++++ .../scripts/helpers/AlertMessageController.js | 4 ++-- 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 locales/calendar/de.json diff --git a/helpers/momentHelper.js b/helpers/momentHelper.js index bebf7a65f7..c116dc46b4 100644 --- a/helpers/momentHelper.js +++ b/helpers/momentHelper.js @@ -1,5 +1,6 @@ const uk = require('../locales/calendar/uk.json'); const es = require('../locales/calendar/es.json'); +const de = require('../locales/calendar/de.json'); /* // const CONFIG_ORIG = i18nMoment().locale('en').localeData()._relativeTime; @@ -49,6 +50,9 @@ const selectMomentOptions = (langAttribute) => { if (langAttribute === 'es') { options.relativeTime = createCustomRelativeTimeConfig(es); } + if (langAttribute === 'de') { + options.relativeTime = createCustomRelativeTimeConfig(de); + } return options; }; diff --git a/locales/calendar/de.json b/locales/calendar/de.json new file mode 100644 index 0000000000..9ee41f4327 --- /dev/null +++ b/locales/calendar/de.json @@ -0,0 +1,17 @@ +{ + "moment.relativeTime.aDay": "ein Tag", + "moment.relativeTime.days": "Tage", + "moment.relativeTime.futureIn": "auf", + "moment.relativeTime.anHour": "eine Stunde", + "moment.relativeTime.hours": "Stunden", + "moment.relativeTime.aMinute": "eine Minute", + "moment.relativeTime.aMonths": "ein Monat", + "moment.relativeTime.minutes": "Minuten", + "moment.relativeTime.months": "Monate", + "moment.relativeTime.pastAgo": "vor", + "moment.relativeTime.aFewSecondes": "ein paar Sekunden", + "moment.relativeTime.seconds": "Sekunden", + "moment.relativeTime.aWeek": "eine Woche", + "moment.relativeTime.weeks": "Wochen", + "moment.relativeTime.aYear": "ein Jahr" +} \ No newline at end of file diff --git a/static/scripts/helpers/AlertMessageController.js b/static/scripts/helpers/AlertMessageController.js index ac9f6d0c0d..198585d1ed 100644 --- a/static/scripts/helpers/AlertMessageController.js +++ b/static/scripts/helpers/AlertMessageController.js @@ -26,7 +26,7 @@ class AlertMessageController { const icon = getIconTag(message.status); const getLangAttribute = () => document.querySelector('html').getAttribute('lang'); - moment.locale(getLangAttribute(), momentHelper.selectMomentOptions(getLangAttribute())); + moment.updateLocale(getLangAttribute(), momentHelper.selectMomentOptions(getLangAttribute())); const item = document.createElement('div'); if (this.loggedin) { item.className = 'alert-item'; @@ -38,7 +38,7 @@ class AlertMessageController { ${$t('alert.text.updatedAt')} ${datetime.fromNow(message.timestamp)} |
- ${$t('alert.text.createdAt')} ${datetime.toDateTimeString(message.createdAt)} + ${$t('alert.text.createdAt')} ${datetime.toDateTimeString(message.createdAt).replaceAll('/', '.')}
`; } else { From a6919e906871b8613abea7a95d68836b4580f457 Mon Sep 17 00:00:00 2001 From: micners Date: Thu, 21 Mar 2024 12:30:02 +0100 Subject: [PATCH 5/5] BC-6672-fix-incorrect-alert-translation --- helpers/momentHelper.js | 1 + locales/calendar/de.json | 3 ++- locales/calendar/es.json | 3 ++- locales/calendar/uk.json | 3 ++- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/helpers/momentHelper.js b/helpers/momentHelper.js index c116dc46b4..f016f1bd51 100644 --- a/helpers/momentHelper.js +++ b/helpers/momentHelper.js @@ -39,6 +39,7 @@ const createCustomRelativeTimeConfig = (localFile) => ({ w: `${localFile['moment.relativeTime.aWeek']}`, ww: `%d ${localFile['moment.relativeTime.weeks']}`, y: `${localFile['moment.relativeTime.aYear']}`, + yy: `%d ${localFile['moment.relativeTime.years']}`, }); const selectMomentOptions = (langAttribute) => { diff --git a/locales/calendar/de.json b/locales/calendar/de.json index 9ee41f4327..b8b789e3da 100644 --- a/locales/calendar/de.json +++ b/locales/calendar/de.json @@ -13,5 +13,6 @@ "moment.relativeTime.seconds": "Sekunden", "moment.relativeTime.aWeek": "eine Woche", "moment.relativeTime.weeks": "Wochen", - "moment.relativeTime.aYear": "ein Jahr" + "moment.relativeTime.aYear": "ein Jahr", + "moment.relativeTime.years": "Jahren" } \ No newline at end of file diff --git a/locales/calendar/es.json b/locales/calendar/es.json index 2c6b899116..ed9c7f13d7 100644 --- a/locales/calendar/es.json +++ b/locales/calendar/es.json @@ -13,5 +13,6 @@ "moment.relativeTime.seconds": "segundos", "moment.relativeTime.aWeek": "una semana", "moment.relativeTime.weeks": "semanas", - "moment.relativeTime.aYear": "un año" + "moment.relativeTime.aYear": "un año", + "moment.relativeTime.years": "años" } \ No newline at end of file diff --git a/locales/calendar/uk.json b/locales/calendar/uk.json index 5f6d8e3555..652088f39a 100644 --- a/locales/calendar/uk.json +++ b/locales/calendar/uk.json @@ -25,5 +25,6 @@ "moment.relativeTime.seconds": "секунд", "moment.relativeTime.aWeek": "тиждень", "moment.relativeTime.weeks": "тижнів", - "moment.relativeTime.aYear": "рік" + "moment.relativeTime.aYear": "рік", + "moment.relativeTime.years": "років" }