Skip to content

Comments

fix(i18n): Replace hardcoded Spanish strings in formatRelativeTime#1699

Open
mohi-devhub wants to merge 2 commits intoruxailab:developfrom
mohi-devhub:fix/i18n-hardcoded-spanish-relative-time
Open

fix(i18n): Replace hardcoded Spanish strings in formatRelativeTime#1699
mohi-devhub wants to merge 2 commits intoruxailab:developfrom
mohi-devhub:fix/i18n-hardcoded-spanish-relative-time

Conversation

@mohi-devhub
Copy link
Contributor

Summary

Fixes hardcoded Spanish strings in formatRelativeTime() in src/shared/utils/dateUtils.js by 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)

  • Replaced hardcoded Spanish strings:
    • "Hoy", "Ayer", "Hace X días", "Hace X semanas", "Hace X meses", "Hace X años"
    • Now use i18n.global.t() calls with interpolated { count } parameters.
  • Imported i18n instance:
    • Uses the same pattern as src/shared/utils/toast.js:
    import i18n from '@/app/plugins/i18n'
  • Standardized default locales:

    • formatDateShort: 'en-GB''en'
    • formatDateTime: 'es-ES''en'
    • Now consistent with formatDateLong default locale.
  • Translated JSDoc comments from Spanish to English for consistency.


2. Locale Files (All 10 Languages)

Added relativeTime translation keys to all locale files:

  • today
  • yesterday
  • daysAgo
  • weeksAgo
  • monthsAgo
  • yearsAgo

Supported languages updated:

  • English (en)
  • Spanish (es)
  • Arabic (ar)
  • German (de)
  • French (fr)
  • Hindi (hi)
  • Japanese (ja)
  • Portuguese BR (pt_br)
  • Russian (ru)
  • Chinese (zh)

Problem Solved

Previously, formatRelativeTime() had:

  • Hardcoded Spanish strings displayed to all users regardless of locale
  • No integration with the project’s i18n system
  • Inconsistent locale defaults across related functions (en, en-GB, es-ES)

Why This Matters

  • User Experience: All supported languages now display correct relative time text.
  • Consistency: Date utility functions now share a unified default locale.
  • Maintainability: Aligns with existing i18n usage patterns in the codebase.

Testing

  • Verify relative time strings display correctly in English (default locale).
  • Switch to Spanish and confirm "Hoy", "Ayer", "Hace X días" appear correctly.
  • Test other supported languages (e.g., French, German, Japanese) to ensure proper translations.
  • Confirm formatDateShort and formatDateTime still function correctly with the updated default locale.

Images

Screenshot 2026-02-17 at 10 20 18 PM

Fixes : #1698

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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() in src/shared/utils/dateUtils.js to use i18n.global.t() translation keys instead of hardcoded Spanish strings.
  • Standardized default locales in formatDateShort and formatDateTime to '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.

Comment on lines 27 to 32
* 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') => {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 2370 to 2373
"daysAgo": "{count} days ago",
"weeksAgo": "{count} weeks ago",
"monthsAgo": "{count} months ago",
"yearsAgo": "{count} years ago"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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"

Copilot uses AI. Check for mistakes.
Comment on lines 2376 to 2379
"daysAgo": "{count} дней назад",
"weeksAgo": "{count} недель назад",
"monthsAgo": "{count} месяцев назад",
"yearsAgo": "{count} лет назад"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"daysAgo": "{count} дней назад",
"weeksAgo": "{count} недель назад",
"monthsAgo": "{count} месяцев назад",
"yearsAgo": "{count} лет назад"
"daysAgo": "{count} день назад | {count} дня назад | {count} дней назад",
"weeksAgo": "{count} неделю назад | {count} недели назад | {count} недель назад",
"monthsAgo": "{count} месяц назад | {count} месяца назад | {count} месяцев назад",
"yearsAgo": "{count} год назад | {count} года назад | {count} лет назад"

Copilot uses AI. Check for mistakes.
Comment on lines 32 to 35
export const formatDateShort = (date, locale = 'en') => {
if (!date) return '-'

try {
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines 84 to 89
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 })
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Comment on lines 2376 to 2379
"daysAgo": "Il y a {count} jours",
"weeksAgo": "Il y a {count} semaines",
"monthsAgo": "Il y a {count} mois",
"yearsAgo": "Il y a {count} ans"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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"

Copilot uses AI. Check for mistakes.
Comment on lines 2377 to 2380
"daysAgo": "Vor {count} Tagen",
"weeksAgo": "Vor {count} Wochen",
"monthsAgo": "Vor {count} Monaten",
"yearsAgo": "Vor {count} Jahren"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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"

Copilot uses AI. Check for mistakes.
Comment on lines 2356 to 2359
"daysAgo": "Há {count} dias",
"weeksAgo": "Há {count} semanas",
"monthsAgo": "Há {count} meses",
"yearsAgo": "Há {count} anos"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"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"

Copilot uses AI. Check for mistakes.
Comment on lines 2372 to 2375
"daysAgo": "منذ {count} أيام",
"weeksAgo": "منذ {count} أسابيع",
"monthsAgo": "منذ {count} أشهر",
"yearsAgo": "منذ {count} سنوات"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"daysAgo": "منذ {count} أيام",
"weeksAgo": "منذ {count} أسابيع",
"monthsAgo": "منذ {count} أشهر",
"yearsAgo": "منذ {count} سنوات"
"daysAgo": "اليوم|منذ يوم واحد|منذ يومين|منذ {count} أيام|منذ {count} يومًا|منذ {count} يوم",
"weeksAgo": "هذا الأسبوع|منذ أسبوع واحد|منذ أسبوعين|منذ {count} أسابيع|منذ {count} أسبوعًا|منذ {count} أسبوع",
"monthsAgo": "هذا الشهر|منذ شهر واحد|منذ شهرين|منذ {count} أشهر|منذ {count} شهرًا|منذ {count} شهر",
"yearsAgo": "هذا العام|منذ سنة واحدة|منذ سنتين|منذ {count} سنوات|منذ {count} سنةً|منذ {count} سنة"

Copilot uses AI. Check for mistakes.
Comment on lines 2355 to 2358
"daysAgo": "{count} दिन पहले",
"weeksAgo": "{count} सप्ताह पहले",
"monthsAgo": "{count} महीने पहले",
"yearsAgo": "{count} साल पहले"
Copy link

Copilot AI Feb 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"daysAgo": "{count} दिन पहले",
"weeksAgo": "{count} सप्ताह पहले",
"monthsAgo": "{count} महीने पहले",
"yearsAgo": "{count} साल पहले"
"daysAgo": "1 दिन पहले | {count} दिन पहले",
"weeksAgo": "1 सप्ताह पहले | {count} सप्ताह पहले",
"monthsAgo": "1 महीने पहले | {count} महीने पहले",
"yearsAgo": "1 साल पहले | {count} साल पहले"

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

@mohi-devhub
Copy link
Contributor Author

@marcgc21
Hi, after merging the latest develop to resolve the merge conflicts, I realized the branch is now identical to develop. It looks like the hardcoded Spanish strings issue has already been fixed in develop using Intl.RelativeTimeFormat, which handles i18n natively via the locale parameter. This PR is no longer needed... feel free to close it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐞 BUG]: Hardcoded Spanish Strings in formatRelativeTime()

1 participant