-
-
Notifications
You must be signed in to change notification settings - Fork 861
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
Request: add the path as argument to the custom formatter #484
Comments
Hello, @louisameline class CustomFormatter {
interpolate (message, values, path) {
if (path == 'firstDay') {
// do calculations to determine the first day of the first week
}
else {
// do something else
}
return result
}
} ? |
Hello, it's less logical but it's backwards compatible, so yes if you prefer :) |
Raiondesu
added a commit
to Raiondesu/vue-i18n
that referenced
this issue
Dec 19, 2018
Raiondesu
added a commit
to Raiondesu/vue-i18n
that referenced
this issue
Dec 19, 2018
kazupon
pushed a commit
that referenced
this issue
Dec 21, 2018
…er (#489) by @Raiondesu * ⚡improvement(types): typed autocomplete in date and number format options Replace Number and Date format options with standard TS `Intl` types, while also adding guiding TS autocomplete to them. This change exterminates the confusion of which types to follow, while preserving backwards-compatibility for types and adding optional autocomplete. * ⚡improvement(types/test): add type constraints to format options It's useful to check static variables types whenever possible. * ⚡new(formatter): add path to the formatter arguments and allow optional formatting * ⚡improvement(types): backward-compatibility for #484 * 📃docs(formatter): add case for the undefined return type * ⚡improvement(types): include the possible undefined return type * ✅tests(issues): make formatter return undefined in test for #484 * update(formatter): change default foramtter invocation from undefined to null
Great, thank you. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I'd like to have the path of the message as a parameter of my interpolate function:
Use case : let's assume my messages are like this:
The
date
variable in the output will depend on the current year, but also on internationalization because the first day of the week is Monday in Europe and Sunday in the USA for example. So in Europe it would be like "Monday, January 1st, 2018", while it would be "Saturday, January 9th, 2018" in the USA.So I'd like to handle this within a i18n custom formatter that would like this :
Right now I have to do:
It's an issue to have to use the message for a comparison, I'd rather do
From a wider perspective, the idea behind this request is that the custom formatter is currently pretty useless unless you want to apply the same formatting to all messages. I'd like to be able to insert more logic in a formatter.
Also, I'd like to be able to tell i18n that my formatter will not process all messages. Maybe if my formatter returns false for example, i18n should format the message as usual.
I hope I was clear :) Thank you for your work.
The text was updated successfully, but these errors were encountered: