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

Easier way to set attribute directly? #772

Closed
fipp opened this issue Jun 9, 2022 · 7 comments
Closed

Easier way to set attribute directly? #772

fipp opened this issue Jun 9, 2022 · 7 comments

Comments

@fipp
Copy link

fipp commented Jun 9, 2022

First of all, great project! Your blog post about vue-i18n resonates.

But I wonder if it's a way to set attributes more directly. Let's say I have this image where I want to localize the alt text:
<img :src="logo" alt="Logo of company X" />

As I understand it, I can do:

<img :src="logo" v-bind="$ta('logo')" />

And have a .ftl definition of:

logo =
  .alt = Logo of company X

Is it possible to set it more directly? In vue-i18n-next I can reference the language tag directly:

<img :src="logo" :alt="t('logoAltText')" />

As I understand it, this is not supported now, or maybe it is? If not, do you think it could be? I see the $ta pattern great for translating two or more attributes, but if there is only one, it would be nice to reference the language tag directly?

Again thank you for your work!

EDIT Solved, see my reply to myself :D

@fipp
Copy link
Author

fipp commented Jun 9, 2022

d'oh, i'm stupid. don't know why I didn't realize, but I can already do this:

<img :src="logo" :alt="$t('logoAltText')" />

@fipp fipp closed this as completed Jun 9, 2022
@Demivan
Copy link
Member

Demivan commented Jun 9, 2022

@fipp Thanks for your kind words. Glad you liked the project.
I recommend using v-t directive for this. It is what is was designed for.

<img :src="logo" v-t:logo />

Using v-bind is not recommended as translators could add attributes that should not be localizable (src for example) and break your app. v-t directive only allows to bind localizable properties (aria, alt, title, etc.).

I have updated docs with a note that discourages using $ta.

@fipp
Copy link
Author

fipp commented Jun 9, 2022

How about setting the attribute directly like so @Demivan, see any problems with that (what I meant in my reply, changed from v-bind just now)?

<img :src="logo" :alt="$t('logoAltText')" />

@Demivan
Copy link
Member

Demivan commented Jun 9, 2022

This one is fine. I use this pattern all the time if I need to localize just one attribute. But if there are more attributes v-t is more convenient.

I thought about adding $t('logo.alt') support but at that point it is easier to use directive anyway.

@Demivan
Copy link
Member

Demivan commented Jun 9, 2022

I'm curious to know, how did you find the project?

@fipp
Copy link
Author

fipp commented Jun 9, 2022

By googling "fluent vue" or "vue fluent" I believe :)

I asked around at my company's slack channel for tips about i18n, and another team recommended me projectfluent with weblate as localization tool. So far so good!

@Demivan
Copy link
Member

Demivan commented Jun 9, 2022

By the way there is a Pontoon project by Mozilla. If you need a self-hosted alternative to Weblate

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

No branches or pull requests

2 participants