fix(i18n): Replace hardcoded Spanish strings in formatRelativeTime#1699
fix(i18n): Replace hardcoded Spanish strings in formatRelativeTime#1699mohi-devhub wants to merge 2 commits intoruxailab:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR removes hardcoded Spanish output from formatRelativeTime() by routing relative-time strings through the app’s Vue I18n messages, and aligns some date formatting defaults.
Changes:
- Updated
formatRelativeTime()insrc/shared/utils/dateUtils.jsto usei18n.global.t()translation keys instead of hardcoded Spanish strings. - Standardized default locales in
formatDateShortandformatDateTimeto'en'and translated related JSDoc to English. - Added new
relativeTime.*translation keys across all supported locale JSON files.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/shared/utils/dateUtils.js | Uses i18n keys for relative-time strings; changes default locales and updates JSDoc. |
| src/app/plugins/locales/en.json | Adds relativeTime translations for English. |
| src/app/plugins/locales/es.json | Adds relativeTime translations for Spanish. |
| src/app/plugins/locales/fr.json | Adds relativeTime translations for French. |
| src/app/plugins/locales/de.json | Adds relativeTime translations for German. |
| src/app/plugins/locales/pt_br.json | Adds relativeTime translations for Portuguese (Brazil). |
| src/app/plugins/locales/ru.json | Adds relativeTime translations for Russian. |
| src/app/plugins/locales/ar.json | Adds relativeTime translations for Arabic. |
| src/app/plugins/locales/hi.json | Adds relativeTime translations for Hindi. |
| src/app/plugins/locales/ja.json | Adds relativeTime translations for Japanese. |
| src/app/plugins/locales/zh.json | Adds relativeTime translations for Chinese. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/shared/utils/dateUtils.js
Outdated
| * Format date to short format "15/08/2024" | ||
| * @param {string|Date} date - The date to format | ||
| * @param {string} locale - The locale for formatting | ||
| * @returns {string} - Formatted date or '-' if invalid | ||
| */ | ||
| export const formatDateShort = (date, locale = 'en-GB') => { | ||
| export const formatDateShort = (date, locale = 'en') => { |
There was a problem hiding this comment.
The JSDoc example for formatDateShort shows a DD/MM/YYYY output ("15/08/2024"), but the default locale was changed to 'en', which commonly formats as MM/DD/YYYY in many environments (e.g., en-US). Either update the example to match the default output or keep a locale default that guarantees the documented format.
src/app/plugins/locales/en.json
Outdated
| "daysAgo": "{count} days ago", | ||
| "weeksAgo": "{count} weeks ago", | ||
| "monthsAgo": "{count} months ago", | ||
| "yearsAgo": "{count} years ago" |
There was a problem hiding this comment.
These strings don’t handle singular vs plural (e.g., they will render "1 days ago"). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "{count} days ago", | |
| "weeksAgo": "{count} weeks ago", | |
| "monthsAgo": "{count} months ago", | |
| "yearsAgo": "{count} years ago" | |
| "daysAgo": "{count} day ago | {count} days ago", | |
| "weeksAgo": "{count} week ago | {count} weeks ago", | |
| "monthsAgo": "{count} month ago | {count} months ago", | |
| "yearsAgo": "{count} year ago | {count} years ago" |
src/app/plugins/locales/ru.json
Outdated
| "daysAgo": "{count} дней назад", | ||
| "weeksAgo": "{count} недель назад", | ||
| "monthsAgo": "{count} месяцев назад", | ||
| "yearsAgo": "{count} лет назад" |
There was a problem hiding this comment.
These strings don’t handle Russian plural rules (e.g., they will render "1 дней назад" instead of the correct form). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "{count} дней назад", | |
| "weeksAgo": "{count} недель назад", | |
| "monthsAgo": "{count} месяцев назад", | |
| "yearsAgo": "{count} лет назад" | |
| "daysAgo": "{count} день назад | {count} дня назад | {count} дней назад", | |
| "weeksAgo": "{count} неделю назад | {count} недели назад | {count} недель назад", | |
| "monthsAgo": "{count} месяц назад | {count} месяца назад | {count} месяцев назад", | |
| "yearsAgo": "{count} год назад | {count} года назад | {count} лет назад" |
src/shared/utils/dateUtils.js
Outdated
| export const formatDateShort = (date, locale = 'en') => { | ||
| if (!date) return '-' | ||
|
|
||
| try { |
There was a problem hiding this comment.
formatDateShort is documented/typed as returning a string (or '-') but the implementation later returns the caught error object from the catch block. This can leak Error objects into the UI; consider returning '-' (or '') on exceptions to match the other helpers.
src/shared/utils/dateUtils.js
Outdated
| const diffMs = now - d | ||
| const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24)) | ||
|
|
||
| if (diffDays === 0) return 'Hoy' | ||
| if (diffDays === 1) return 'Ayer' | ||
| if (diffDays < 7) return `Hace ${diffDays} días` | ||
| if (diffDays < 30) return `Hace ${Math.floor(diffDays / 7)} semanas` | ||
| if (diffDays < 365) return `Hace ${Math.floor(diffDays / 30)} meses` | ||
|
|
||
| return `Hace ${Math.floor(diffDays / 365)} años` | ||
| if (diffDays === 0) return t('relativeTime.today') | ||
| if (diffDays === 1) return t('relativeTime.yesterday') | ||
| if (diffDays < 7) return t('relativeTime.daysAgo', { count: diffDays }) |
There was a problem hiding this comment.
diffDays can be negative for future dates (when date is after now), which will produce strings like “-2 days ago”. Add explicit handling for diffDays < 0 (e.g., clamp to 0, return a dedicated “in X days” message, or fall back to an absolute date).
src/app/plugins/locales/fr.json
Outdated
| "daysAgo": "Il y a {count} jours", | ||
| "weeksAgo": "Il y a {count} semaines", | ||
| "monthsAgo": "Il y a {count} mois", | ||
| "yearsAgo": "Il y a {count} ans" |
There was a problem hiding this comment.
These strings don’t handle singular vs plural (e.g., they will render "Il y a 1 jours"). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "Il y a {count} jours", | |
| "weeksAgo": "Il y a {count} semaines", | |
| "monthsAgo": "Il y a {count} mois", | |
| "yearsAgo": "Il y a {count} ans" | |
| "daysAgo": "Il y a {count} jour|Il y a {count} jours", | |
| "weeksAgo": "Il y a {count} semaine|Il y a {count} semaines", | |
| "monthsAgo": "Il y a {count} mois|Il y a {count} mois", | |
| "yearsAgo": "Il y a {count} an|Il y a {count} ans" |
src/app/plugins/locales/de.json
Outdated
| "daysAgo": "Vor {count} Tagen", | ||
| "weeksAgo": "Vor {count} Wochen", | ||
| "monthsAgo": "Vor {count} Monaten", | ||
| "yearsAgo": "Vor {count} Jahren" |
There was a problem hiding this comment.
These strings don’t handle singular vs plural (e.g., they will render "Vor 1 Tagen"). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "Vor {count} Tagen", | |
| "weeksAgo": "Vor {count} Wochen", | |
| "monthsAgo": "Vor {count} Monaten", | |
| "yearsAgo": "Vor {count} Jahren" | |
| "daysAgo": "Vor {count} Tag|Vor {count} Tagen", | |
| "weeksAgo": "Vor {count} Woche|Vor {count} Wochen", | |
| "monthsAgo": "Vor {count} Monat|Vor {count} Monaten", | |
| "yearsAgo": "Vor {count} Jahr|Vor {count} Jahren" |
src/app/plugins/locales/pt_br.json
Outdated
| "daysAgo": "Há {count} dias", | ||
| "weeksAgo": "Há {count} semanas", | ||
| "monthsAgo": "Há {count} meses", | ||
| "yearsAgo": "Há {count} anos" |
There was a problem hiding this comment.
These strings don’t handle singular vs plural (e.g., they will render "Há 1 dias"). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "Há {count} dias", | |
| "weeksAgo": "Há {count} semanas", | |
| "monthsAgo": "Há {count} meses", | |
| "yearsAgo": "Há {count} anos" | |
| "daysAgo": "Há {count} dia|Há {count} dias", | |
| "weeksAgo": "Há {count} semana|Há {count} semanas", | |
| "monthsAgo": "Há {count} mês|Há {count} meses", | |
| "yearsAgo": "Há {count} ano|Há {count} anos" |
src/app/plugins/locales/ar.json
Outdated
| "daysAgo": "منذ {count} أيام", | ||
| "weeksAgo": "منذ {count} أسابيع", | ||
| "monthsAgo": "منذ {count} أشهر", | ||
| "yearsAgo": "منذ {count} سنوات" |
There was a problem hiding this comment.
These strings don’t handle Arabic singular/plural forms (e.g., for 1 it should differ from "{count} أيام/أسابيع/أشهر/سنوات"). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "منذ {count} أيام", | |
| "weeksAgo": "منذ {count} أسابيع", | |
| "monthsAgo": "منذ {count} أشهر", | |
| "yearsAgo": "منذ {count} سنوات" | |
| "daysAgo": "اليوم|منذ يوم واحد|منذ يومين|منذ {count} أيام|منذ {count} يومًا|منذ {count} يوم", | |
| "weeksAgo": "هذا الأسبوع|منذ أسبوع واحد|منذ أسبوعين|منذ {count} أسابيع|منذ {count} أسبوعًا|منذ {count} أسبوع", | |
| "monthsAgo": "هذا الشهر|منذ شهر واحد|منذ شهرين|منذ {count} أشهر|منذ {count} شهرًا|منذ {count} شهر", | |
| "yearsAgo": "هذا العام|منذ سنة واحدة|منذ سنتين|منذ {count} سنوات|منذ {count} سنةً|منذ {count} سنة" |
src/app/plugins/locales/hi.json
Outdated
| "daysAgo": "{count} दिन पहले", | ||
| "weeksAgo": "{count} सप्ताह पहले", | ||
| "monthsAgo": "{count} महीने पहले", | ||
| "yearsAgo": "{count} साल पहले" |
There was a problem hiding this comment.
These strings don’t handle singular vs plural (e.g., they will render "1 दिन पहले" / "1 सप्ताह पहले" depending on language rules). The codebase already uses Vue I18n plural forms with pipe-separated variants in common.timeAgo; consider using the same pluralization pattern here for correct grammar.
| "daysAgo": "{count} दिन पहले", | |
| "weeksAgo": "{count} सप्ताह पहले", | |
| "monthsAgo": "{count} महीने पहले", | |
| "yearsAgo": "{count} साल पहले" | |
| "daysAgo": "1 दिन पहले | {count} दिन पहले", | |
| "weeksAgo": "1 सप्ताह पहले | {count} सप्ताह पहले", | |
| "monthsAgo": "1 महीने पहले | {count} महीने पहले", | |
| "yearsAgo": "1 साल पहले | {count} साल पहले" |
|
|
@marcgc21 |



Summary
Fixes hardcoded Spanish strings in
formatRelativeTime()insrc/shared/utils/dateUtils.jsby replacing them with i18n translation keys, ensuring relative time displays correctly across all 10 supported languages.Changes Made
1. Date Utility Fix (
src/shared/utils/dateUtils.js)i18n.global.t()calls with interpolated{ count }parameters.src/shared/utils/toast.js:Standardized default locales:
formatDateShort:'en-GB'→'en'formatDateTime:'es-ES'→'en'formatDateLongdefault locale.Translated JSDoc comments from Spanish to English for consistency.
2. Locale Files (All 10 Languages)
Added
relativeTimetranslation keys to all locale files:todayyesterdaydaysAgoweeksAgomonthsAgoyearsAgoSupported languages updated:
Problem Solved
Previously,
formatRelativeTime()had:en,en-GB,es-ES)Why This Matters
Testing
formatDateShortandformatDateTimestill function correctly with the updated default locale.Images
Fixes : #1698