start-ui-web icon indicating copy to clipboard operation
start-ui-web copied to clipboard

i18n and date formatting

Open yoannfleurydev opened this issue 2 years ago β€’ 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}}"

yoannfleurydev avatar Jul 06 '23 07:07 yoannfleurydev

It's a great idea !

Jessy-BAER avatar Jul 07 '23 08:07 Jessy-BAER

It's a great idea !

Of course it is, it's yours πŸ˜›

yoannfleurydev avatar Jul 10 '23 07:07 yoannfleurydev

@yoannfleurydev I would like to contribute on this issue !

ntatoud avatar Jul 19 '23 14:07 ntatoud

@yoannfleurydev I would like to contribute on this issue !

Awesome, I assigned you to the issue πŸ˜ƒ

yoannfleurydev avatar Jul 19 '23 14:07 yoannfleurydev

@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 ?

ntatoud avatar Jul 19 '23 15:07 ntatoud

@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.

yoannfleurydev avatar Jul 20 '23 07:07 yoannfleurydev