feat(greeting, date): enhance turkish localisation support for date

This commit is contained in:
alexsparkes
2026-01-29 22:26:02 +00:00
parent 09308a4452
commit f29b879215
4 changed files with 22 additions and 13 deletions

View File

@@ -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');
}

View File

@@ -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' })

View File

@@ -43,7 +43,7 @@
"url_error": "URL sağlanmalıdır"
},
"date": {
"week": "Hafta"
"week": "{number}. Hafta"
},
"weather": {
"not_found": "Bulunamadı",

View File

@@ -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';
}