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

feat: Added formatter, values, path to MessageContext #1271

Merged

Conversation

fabis94
Copy link
Contributor

@fabis94 fabis94 commented Jun 10, 2021

If you use message function functionality, vue-i18n skips running the formatter on the results. I don't want this, I want to do some custom work in the message function, but then defer all of the formatting back to vue-i18n.

To make this possible I've added the formatter, all values and path into the MessageContext. I've added a test case for this as well.

@kazupon
Copy link
Owner

kazupon commented Jun 12, 2021

Thank you for your contribution.
I really appreciate your improvements to the message function!

The use-case for the message function, as mentioned in the documentation, is to support complex cases that cannot be handled by vue-i18n's formatter.
https://kazupon.github.io/vue-i18n/guide/messages.html#message-function

In PR, it is possible to specify a message, but it is difficult to extract this message as a resource. This makes it difficult to integrate it into the translation workflow with localization service.

This PR is great that can improve DX by supporting fomatter for message funciton, but it needs to solve the issue of integration with translation workflow.

There is a feature in vue-i18n that allows you to reference a message called linked locale message.
https://kazupon.github.io/vue-i18n/guide/messages.html#linked-locale-messages

We can solve the problem of integration with translation workflows by making it possible to reference messages in the message function.

However, at this time, we do not have a way to make the linked locale message available in the message function.
We need to make that available as well.

@fabis94
Copy link
Contributor Author

fabis94 commented Jun 14, 2021

@kazupon Am I understanding you correctly that there also needs to be a way to get the entire "messages" object inside the message function?

If so, I've added both messages and locale to the message context so that you can get any translated message this way.

@kazupon
Copy link
Owner

kazupon commented Jun 19, 2021

@fabis94
Thank you for your updating!

Sorry for my poor explanation.

I add a liked function that can refer to a resource message in the context passed to the message functions as follows, and assumed the following usage:

{
  hey: 'hey {x} {y}'.
  hello: (ctx) => ctx.formatter.interpolate(ctx.linked('hey'), ctx.values, ctx.path).join('')
}

@fabis94
Copy link
Contributor Author

fabis94 commented Jul 8, 2021

@kazupon I've updated the PR to also include the functionality you requested

@kazupon kazupon added the Type: Feature Includes new features label Jul 16, 2021
Copy link
Owner

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, late response

Thank you for your contribution!

I’ll merge your PR, but several props (path, formatter, messages, and locale`) of message context are not compatible for vue-i18n@v9.
I’ll write those to docs as a limitation

I appreciate your work!

@fabis94
Copy link
Contributor Author

fabis94 commented Jul 16, 2021

thank you @kazupon! any ideas when this will be released as a new version?

@kazupon
Copy link
Owner

kazupon commented Jul 16, 2021

I'm preparing for release now
#1322

@kazupon
Copy link
Owner

kazupon commented Jul 16, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged Type: Feature Includes new features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants