This commit is contained in:
Arash Shakery
2023-12-23 00:28:40 -07:00
committed by GitHub
3 changed files with 33 additions and 1 deletions

19
assets/js/datelocale.ts Normal file
View File

@ -0,0 +1,19 @@
function formatDate(date: string | null) {
if (!date) return date;
return new Intl.DateTimeFormat(process.env.lang_code, {
year: 'numeric',
month: 'long',
day: 'numeric',
}).format(new Date(date));
}
if ('Intl' in window) {
window.addEventListener('load', () => {
for(const span of [...document.querySelectorAll('.localizable-date')]) {
const localizedDate = formatDate(span.getAttribute('title'));
if (localizedDate) {
span.innerHTML = localizedDate;
}
}
});
}