Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n and date formatting #391

Open
yoannfleurydev opened this issue Jul 6, 2023 · 6 comments
Open

i18n and date formatting #391

yoannfleurydev opened this issue Jul 6, 2023 · 6 comments
Assignees

Comments

@yoannfleurydev
Copy link
Member

It could be great to handle date formatting with i18next and give example in the code

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}}"
@Jessy-BAER
Copy link
Contributor

It's a great idea !

@yoannfleurydev
Copy link
Member Author

It's a great idea !

Of course it is, it's yours 😛

@ntatoud
Copy link
Contributor

ntatoud commented Jul 19, 2023

@yoannfleurydev I would like to contribute on this issue !

@yoannfleurydev
Copy link
Member Author

@yoannfleurydev I would like to contribute on this issue !

Awesome, I assigned you to the issue 😃

@ntatoud
Copy link
Contributor

ntatoud commented Jul 19, 2023

@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
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

3 participants