Skip to content

Commit

Permalink
BC-8683 - Wrong plural for news and the time specification (#3554)
Browse files Browse the repository at this point in the history
* adjusting moment locales for German specific cases
  • Loading branch information
MartinSchuhmacher authored Jan 20, 2025
1 parent 269e480 commit 0590262
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 80 deletions.
20 changes: 20 additions & 0 deletions helpers/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ const changeLanguage = (langAttribute) => {
if (availableLanguages.includes(langAttribute)) {
const momentOptions = momentHelper.selectMomentOptions(langAttribute);
i18nMoment.locale(langAttribute, momentOptions);
if (langAttribute === 'de') {
i18nMoment.updateLocale('de', {
relativeTime: {
future: 'in %s',
past: 'vor %s',
s: 'ein paar Sekunden',
ss: '%d Sekunden',
m: 'einer Minute',
mm: '%d Minuten',
h: 'einer Stunde',
hh: '%d Stunden',
d: 'einem Tag',
dd: '%d Tagen',
M: 'einem Monat',
MM: '%d Monaten',
y: 'einem Jahr',
yy: '%d Jahren',
},
});
}
return i18next.changeLanguage(langAttribute);
}
return false;
Expand Down
62 changes: 44 additions & 18 deletions helpers/momentHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,52 @@ const relativeTime = {

const createCustomRelativeTimeConfig = (localFile, lang) => {
const commonConfig = {
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']}`,
yy: `%d ${localFile['moment.relativeTime.years']}`,
d: `${localFile['moment.relativeTime.aDay']}`, // e.g. "ein Tag"
dd: `%d ${localFile['moment.relativeTime.days']}`, // e.g. "2 Tage"
future: `${localFile['moment.relativeTime.futureIn']} %s`, // e.g. "in 3 Tagen"
h: `${localFile['moment.relativeTime.anHour']}`, // e.g. "eine Stunde"
hh: `%d ${localFile['moment.relativeTime.hours']}`, // e.g. "2 Stunden"
m: `${localFile['moment.relativeTime.aMinute']}`, // e.g. "eine Minute"
mm: `%d ${localFile['moment.relativeTime.minutes']}`, // e.g. "2 Minuten"
M: `${localFile['moment.relativeTime.aMonth']}`, // e.g. "ein Monat"
MM: `%d ${localFile['moment.relativeTime.months']}`, // e.g. "3 Monate"
past: `%s ${localFile['moment.relativeTime.pastAgo']}`, // Standard
s: `${localFile['moment.relativeTime.aFewSeconds']}`, // e.g. "ein paar Sekunden"
ss: `%d ${localFile['moment.relativeTime.seconds']}`, // e.g. "5 Sekunden"
w: `${localFile['moment.relativeTime.aWeek']}`, // e.g. "eine Woche"
ww: `%d ${localFile['moment.relativeTime.weeks']}`, // e.g. "2 Wochen"
y: `${localFile['moment.relativeTime.aYear']}`, // e.g. "ein Jahr"
yy: `%d ${localFile['moment.relativeTime.years']}`, // e.g. "2 Jahre"
};

if (lang === 'de' || lang === 'es') {
commonConfig.past = `${localFile['moment.relativeTime.pastAgo']} %s`;
if (lang === 'de') {
// specific adjustments for German
commonConfig.past = (unit, value) => {
if (value === 1) {
// special cases for singular
if (unit === 'd') return 'vor einem Tag';
if (unit === 'h') return 'vor einer Stunde';
if (unit === 'm') return 'vor einer Minute';
if (unit === 'M') return 'vor einem Monat';
if (unit === 'w') return 'vor einer Woche';
if (unit === 'y') return 'vor einem Jahr';
}
// default for plural
return `%s ${localFile['moment.relativeTime.pastAgo']}`;
};
commonConfig.future = (unit, value) => {
if (value === 1) {
// special cases for singular
if (unit === 'd') return 'in einem Tag';
if (unit === 'h') return 'in einer Stunde';
if (unit === 'm') return 'in einer Minute';
if (unit === 'M') return 'in einem Monat';
if (unit === 'w') return 'in einer Woche';
if (unit === 'y') return 'in einem Jahr';
}
// default for plural
return 'in %s';
};
}

return commonConfig;
Expand Down
34 changes: 17 additions & 17 deletions locales/calendar/de.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"moment.relativeTime.aDay": "ein Tag",
"moment.relativeTime.days": "Tage",
"moment.relativeTime.futureIn": "in",
"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",
"moment.relativeTime.years": "Jahren"
{
"moment.relativeTime.aDay": "ein Tag",
"moment.relativeTime.days": "Tage",
"moment.relativeTime.futureIn": "in",
"moment.relativeTime.anHour": "eine Stunde",
"moment.relativeTime.hours": "Stunden",
"moment.relativeTime.aMinute": "eine Minute",
"moment.relativeTime.aMonth": "ein Monat",
"moment.relativeTime.minutes": "Minuten",
"moment.relativeTime.months": "Monate",
"moment.relativeTime.pastAgo": "vor",
"moment.relativeTime.aFewSeconds": "ein paar Sekunden",
"moment.relativeTime.seconds": "Sekunden",
"moment.relativeTime.aWeek": "eine Woche",
"moment.relativeTime.weeks": "Wochen",
"moment.relativeTime.aYear": "ein Jahr",
"moment.relativeTime.years": "Jahre"
}
34 changes: 17 additions & 17 deletions locales/calendar/es.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"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",
"moment.relativeTime.years": "años"
{
"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.aMonth": "un mes",
"moment.relativeTime.minutes": "minutos",
"moment.relativeTime.months": "meses",
"moment.relativeTime.pastAgo": "hace",
"moment.relativeTime.aFewSeconds": "unos segundos",
"moment.relativeTime.seconds": "segundos",
"moment.relativeTime.aWeek": "una semana",
"moment.relativeTime.weeks": "semanas",
"moment.relativeTime.aYear": "un año",
"moment.relativeTime.years": "años"
}
56 changes: 28 additions & 28 deletions locales/calendar/uk.json
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
{
"calendar.allDayText": "весь день",
"calendar.buttonText.prev": "Повернення",
"calendar.buttonText.next": "Попереду",
"calendar.buttonText.today": "сьогодні",
"calendar.buttonText.year": "Рік",
"calendar.buttonText.month": "Місяць",
"calendar.buttonText.week": "тиждень",
"calendar.buttonText.day": "День",
"calendar.buttonText.list": "Огляд прийому",
"calendar.eventLimitText": "Далі",
"calendar.noEventsMessage": "Немає подій для показу",
"calendar.weekLabel": "тиждень",
"moment.relativeTime.aDay": "день",
"moment.relativeTime.days": "дні (-в)",
"moment.relativeTime.futureIn": "через",
"moment.relativeTime.anHour": "годину",
"moment.relativeTime.hours": "годин (-и)",
"moment.relativeTime.aMinute": "хвилинy",
"moment.relativeTime.aMonths": "місяць",
"moment.relativeTime.minutes": "хвилин (-и)",
"moment.relativeTime.months": "місяців",
"moment.relativeTime.pastAgo": "тому",
"moment.relativeTime.aFewSecondes": "кілька секунд",
"moment.relativeTime.seconds": "секунд",
"moment.relativeTime.aWeek": "тиждень",
"moment.relativeTime.weeks": "тижнів",
"moment.relativeTime.aYear": "рік",
"moment.relativeTime.years": "років"
"calendar.allDayText": "весь день",
"calendar.buttonText.prev": "Повернення",
"calendar.buttonText.next": "Попереду",
"calendar.buttonText.today": "сьогодні",
"calendar.buttonText.year": "Рік",
"calendar.buttonText.month": "Місяць",
"calendar.buttonText.week": "тиждень",
"calendar.buttonText.day": "День",
"calendar.buttonText.list": "Огляд прийому",
"calendar.eventLimitText": "Далі",
"calendar.noEventsMessage": "Немає подій для показу",
"calendar.weekLabel": "тиждень",
"moment.relativeTime.aDay": "день",
"moment.relativeTime.days": "дні (-в)",
"moment.relativeTime.futureIn": "через",
"moment.relativeTime.anHour": "годину",
"moment.relativeTime.hours": "годин (-и)",
"moment.relativeTime.aMinute": "хвилинy",
"moment.relativeTime.aMonth": "місяць",
"moment.relativeTime.minutes": "хвилин (-и)",
"moment.relativeTime.months": "місяців",
"moment.relativeTime.pastAgo": "тому",
"moment.relativeTime.aFewSeconds": "кілька секунд",
"moment.relativeTime.seconds": "секунд",
"moment.relativeTime.aWeek": "тиждень",
"moment.relativeTime.weeks": "тижнів",
"moment.relativeTime.aYear": "рік",
"moment.relativeTime.years": "років"
}
20 changes: 20 additions & 0 deletions static/scripts/helpers/AlertMessageController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,26 @@ class AlertMessageController {

const getLangAttribute = () => document.querySelector('html').getAttribute('lang');
moment.updateLocale(getLangAttribute(), momentHelper.selectMomentOptions(getLangAttribute()));
if (getLangAttribute() === 'de') {
moment.updateLocale('de', {
relativeTime: {
future: 'in %s',
past: 'vor %s',
s: 'ein paar Sekunden',
ss: '%d Sekunden',
m: 'einer Minute',
mm: '%d Minuten',
h: 'einer Stunde',
hh: '%d Stunden',
d: 'einem Tag',
dd: '%d Tagen',
M: 'einem Monat',
MM: '%d Monaten',
y: 'einem Jahr',
yy: '%d Jahren',
},
});
}
const item = document.createElement('div');
if (this.loggedin) {
item.className = 'alert-item';
Expand Down

0 comments on commit 0590262

Please sign in to comment.