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

Using vue-gettext with vuetify and other components #104

Open
duduklein opened this issue Jan 2, 2020 · 2 comments
Open

Using vue-gettext with vuetify and other components #104

duduklein opened this issue Jan 2, 2020 · 2 comments

Comments

@duduklein
Copy link

I'm trying to use vue-gettext with vuetify. For a button, I used v-translate directive, as in
<v-btn :value="false" v-translate>inactive</v-btn>, which extracts correctly the string "inactive" for translation.

The issue I'm facing is the translation itself. After translating the .po and generating the json file, the string is not translated.

Actually if I switch to <v-btn :value="false"><translate>inactive</translate></v-btn>, it works, but it adds a useless span tag inside the button.

Any suggestion on how to handle this situation?
Thanks in advance

@adambullmer
Copy link

We ran into this one too. Looks like the way the slot works is incompatible with the way the directive gets the string to be translated. Vuetify doesn't transclude unknonw directives on the default slot, and this library grabs the innerHTML of the element the directive is placed upon, as it may be desirable to include simple nested html, like links, or formatting elements. If you inspect the button element, you'll see some data attributes showing the msgid, and it contains all the stringified html from the vuetify btn html and it is for this reason the translations don't work.

The extra element is a bummer, but it shouldn't cause you issues. If you're really concerned about it, you could always make a computed property with the translated string and render that instead of the plain text.

<template>
  <v-btn :value="false">{{ btnText }}</v-btn>
</template>
<script>
export default {
  computed: {
    btnText() {
      return this.$gettext('inactive');
    }
  }
}
</script>

An alternative proposal to the library is to maybe add an option to ignore nested html. I'm sure this will affect others who want to translate complex components and not add weight to the DOM structure with elements that aren't essential. Maybe add a ignore-html directive to be the antithesis to render-html. This would only be to solve the difference between source code and rendered components with slots that seem to be something the community at large is having problems with. (#93 and #49 still being open issues)

I imagine it would look something like this:

<template>
  <v-btn :value="false" v-translate ignore-html>inactive</v-btn>
</template>

and the implementation would be to just grab the innerText rather than innerHTML of the component with the directive here. https://github.com/Polyconseil/vue-gettext/blob/master/src/directive.js#L73

@duduklein
Copy link
Author

duduklein commented Feb 5, 2020 via email

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

No branches or pull requests

2 participants