From f29b879215af33356c6411cafadf1b6b69ab2f42 Mon Sep 17 00:00:00 2001 From: alexsparkes Date: Thu, 29 Jan 2026 22:26:02 +0000 Subject: [PATCH] feat(greeting, date): enhance turkish localisation support for date --- src/features/greeting/Greeting.jsx | 3 ++- src/features/time/Date.jsx | 14 ++++++++------ src/i18n/locales/tr_TR.json | 2 +- src/utils/date/index.js | 16 +++++++++++----- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/features/greeting/Greeting.jsx b/src/features/greeting/Greeting.jsx index ac04b714..11622685 100644 --- a/src/features/greeting/Greeting.jsx +++ b/src/features/greeting/Greeting.jsx @@ -106,7 +106,8 @@ const Greeting = () => { if (birth.getDate() === now.getDate() && birth.getMonth() === now.getMonth()) { if (localStorage.getItem('birthdayage') === 'true' && calculateAge(birth) !== 0) { const text = t('widgets.greeting.birthday').split(' '); - message = `${text[0]} ${nth(calculateAge(birth))} ${text[1]}`; + const lang = variables.languagecode.split('_')[0]; + message = `${text[0]} ${nth(calculateAge(birth), lang)} ${text[1]}`; } else { message = t('widgets.greeting.birthday'); } diff --git a/src/features/time/Date.jsx b/src/features/time/Date.jsx index b0fe4678..5cf7cf51 100644 --- a/src/features/time/Date.jsx +++ b/src/features/time/Date.jsx @@ -29,11 +29,13 @@ const DateWidget = () => { dateToday.setMonth(0, 1 + ((4 - dateToday.getDay() + 7) % 7)); } - setWeekNumber( - `${variables.getMessage('widgets.date.week')} ${ - 1 + Math.ceil((firstThursday - dateToday) / 604800000) - }`, - ); + const weekLabel = variables.getMessage('widgets.date.week'); + const weekNum = 1 + Math.ceil((firstThursday - dateToday) / 604800000); + // Support {number} placeholder for locales that need different word order (e.g., Turkish: "{number}. Hafta") + const weekText = weekLabel.includes('{number}') + ? weekLabel.replace('{number}', weekNum) + : `${weekLabel} ${weekNum}`; + setWeekNumber(weekText); }; const getDate = () => { @@ -97,7 +99,7 @@ const DateWidget = () => { // Long date const lang = variables.languagecode.split('_')[0]; const datenth = - localStorage.getItem('datenth') === 'true' ? nth(date.getDate()) : date.getDate(); + localStorage.getItem('datenth') === 'true' ? nth(date.getDate(), lang) : date.getDate(); const dateDay = localStorage.getItem('dayofweek') === 'true' ? date.toLocaleDateString(lang, { weekday: 'long' }) diff --git a/src/i18n/locales/tr_TR.json b/src/i18n/locales/tr_TR.json index 918eac9d..829bdd29 100644 --- a/src/i18n/locales/tr_TR.json +++ b/src/i18n/locales/tr_TR.json @@ -43,7 +43,7 @@ "url_error": "URL sağlanmalıdır" }, "date": { - "week": "Hafta" + "week": "{number}. Hafta" }, "weather": { "not_found": "Bulunamadı", diff --git a/src/utils/date/index.js b/src/utils/date/index.js index 9dd48fc2..40a2483d 100644 --- a/src/utils/date/index.js +++ b/src/utils/date/index.js @@ -1,11 +1,17 @@ // todo: maybe move stuff /** - * If the number is between 3 and 20, return the number with the suffix "th". Otherwise, return the - * number with the suffix "st", "nd", "rd", or "th" depending on the last digit of the number - * @param d - The day of the month. - * @returns the day of the month with the appropriate suffix. + * Returns the number with an ordinal suffix for English locales (st, nd, rd, th). + * For non-English locales, returns the plain number since ordinal conventions vary by language. + * @param d - The day of the month or any number. + * @param lang - Optional language code (e.g., 'en', 'tr'). If starts with 'en', applies English ordinals. + * @returns The number, optionally with an English ordinal suffix. */ -export function nth(d) { +export function nth(d, lang) { + // Only apply English ordinal suffixes for English locales + if (lang && !lang.startsWith('en')) { + return d; + } + if (d > 3 && d < 21) { return d + 'th'; }