mirror of
https://github.com/mue/mue.git
synced 2026-07-18 22:44:08 +02:00
feat(greeting, date): enhance turkish localisation support for date
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
@@ -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' })
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
"url_error": "URL sağlanmalıdır"
|
||||
},
|
||||
"date": {
|
||||
"week": "Hafta"
|
||||
"week": "{number}. Hafta"
|
||||
},
|
||||
"weather": {
|
||||
"not_found": "Bulunamadı",
|
||||
|
||||
@@ -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';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user