[Feature request] translations in mixins
See original GitHub issueReading other issues, you seem to discourage ppl from using mixins, but they’re so useful.
I would like to share some behavior between a bunch of components (especially across different builds, where “global” translations would still have to be duplicated)
const ChickenMixin = {
methods: {
scream () {
alert(this.$t('scream'))
}
},
i18n: {
messages: {
en: {
scream: 'cock-a-doodle-do'
},
fr: {
scream: 'cocorico'
}
}
}
}
it does not work at the moment : http://jsfiddle.net/2hs4pgwe/2/
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:10
Top Results From Across the Web
Mixins - Vue.js
Mixins are a flexible way to distribute reusable functionalities for Vue components. A mixin object can contain any component options. When a component...
Read more >Including mixins using variables for name in Sass
I'm trying to call a mixin using a variable as the name, like so: ... This sounds more like a feature request for...
Read more >Vue.js Mixins, extending components and High Order ...
The translate function looks for the translated string using the locale , configured by the Vue instance and the key. In case the...
Read more >Mixins - The Modern JavaScript Tutorial
As defined in Wikipedia, a mixin is a class containing methods that ... An important feature of many browser objects (for instance) is...
Read more >Apache Tapestry - Component Mixins
A mixin for this purpose would need access to at least the disabled, and value parameters, and possibly the translate parameter (for a...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think adding a flag to enable mixin merging is a solution. Is there any plans for this feature? @kazupon
I had the same issue and found the solution using
optionMergeStrategies
a bit intrusive. I tried a few things and came up with this helper function which solved the problem:You can simply use it within a
beforeCreate
hook by providing the $i18n plugin of the current Vue instance (a.k.a.this.$i18n
). As you don’t provide the i18n root instance, your translations will be scoped to the component which means you will still have component-based localization.@/locales/chicken.json
I personally like having my translations in separate files, but of course, you can define the object directly in your mixin. Hope it helps.