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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: t-helper for vue-intl #3444

Open
fkm opened this issue Feb 27, 2022 · 8 comments
Open

Feature request: t-helper for vue-intl #3444

fkm opened this issue Feb 27, 2022 · 8 comments
Labels

Comments

@fkm
Copy link

fkm commented Feb 27, 2022

It would be nice to have a t-helper function for code like this:
馃槏 $t('one') $t('two', { foo: 'bar' }) instead of:
馃槩 $formatMessage({ id: 'one' }) $formatMessage({ id: 'two' }, { foo: 'bar' })

Something like this seems to be enough:
app.config.globalProperties.$t = (id, values) => intl.formatMessage({ id }, values);

This would be in line with Ember's implementation.
https://ember-intl.github.io/ember-intl/docs/helpers/t

@glen-84
Copy link
Contributor

glen-84 commented Mar 13, 2022

See also #2476.

@longlho
Copy link
Member

longlho commented Mar 14, 2022

I'm kinda coming around to this but will have to find time to implement it

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the Stale label Mar 29, 2022
@glen-84
Copy link
Contributor

glen-84 commented Mar 29, 2022

Not stale.

@longlho longlho added pinned and removed Stale labels Mar 29, 2022
@longlho
Copy link
Member

longlho commented May 20, 2024

hmm how do you typically specify defaultMessage within vue?

@glen-84
Copy link
Contributor

glen-84 commented May 20, 2024

hmm how do you typically specify defaultMessage within vue?

Assuming that nothing has changed since I last used this library (I'm not currently doing f/end):

{{ $formatMessage({defaultMessage: "All"}) }}

@longlho
Copy link
Member

longlho commented May 20, 2024

Right, but the new syntax being proposed with $t seems to be slightly different where 1st arg is the id?

@glen-84
Copy link
Contributor

glen-84 commented May 21, 2024

Ya, I had suggested something similar, which also included the default message.

I don't really like the "my-id-or-null-for-default" part though. Perhaps the signature could remain the same, but shorten defaultMessage to default:

{{ $fm({default: "default-message"}, {value: 123}) }}

Using an ID:

{{ $fm({id: "one"}, {foo: "bar"}) }}

(I prefer fm to t because you can have fn for formatNumber, fd for formatDate, etc.)

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

No branches or pull requests

3 participants