i18n and date formatting
yoannfleurydev opened this issue ยท 6 comments
It could be great to handle date formatting with i18next and give example in the code
- https://github.com/BearStudio/start-ui-web/blob/master/src/lib/i18n/config.ts
- https://www.i18next.com/translation-function/formatting#datetime
i18next
.use(initReactI18next)
.init({
resources,
lng: DEFAULT_I18N_LANGUAGE,
interpolation: {
escapeValue: false,
format: (value, format) => {
if (isDate(value)) {
return formatDate(value, format);
}
// List of custom formatters
if (format === 'minutesToHours') {
return minutesToHours(value)?.toString();
}
return value;
},
},
})
"create_by": "{{displayName}} le {{date, dd MMMM yyyy}}"
It's a great idea !
It's a great idea !
Of course it is, it's yours ๐
@yoannfleurydev I would like to contribute on this issue !
@yoannfleurydev I would like to contribute on this issue !
Awesome, I assigned you to the issue ๐
@yoannfleurydev I would like to clarify 1 small detail :
On top of the formatDate
that will allow the use of the synthax :
"create_by": "{{displayName}} le {{date, dd MMMM yyyy}}"
Should I provide more functions like 'hoursToMinutes or simply demonstrate the possibility to add more ?
@yoannfleurydev I would like to clarify 1 small detail : On top of the
formatDate
that will allow the use of the synthax :"create_by": "{{displayName}} le {{date, dd MMMM yyyy}}"
Should I provide more functions like 'hoursToMinutes or simply demonstrate the possibility to add more ?
Don't bother adding too much logic @ntatoud , just the bare minimum to show how to add custom date format in translation.