Georgy Farniev
Georgy Farniev

Reputation: 35

How to localize my Vue components library?

I develop my own vue components library, and this components have a lot of texts that needs to be localized. vue-i18n doesn't support this, because it should be attached to Vue (e.g. Vue.use(VueI18n)), but in case of component library, it will result in conflict.

I need to have independent translation files in my library, totally separated from my application (to prevent conflicts)

I'm struggling to find any answer to this question in other sources, and I hope someone can give me example for this case. Thanks in advance.

Upvotes: 1

Views: 2338

Answers (1)

Michal Levý
Michal Levý

Reputation: 37753

Well it really seems that vue-i18n is not tailored for use in component libraries for reasons you are mentioning (attaching itself into Vue.prototype + conflict with user's code).

I don't know what features of vue-i18n are you using but if it's just simple translation, it seems rolling your own custom solution with an option to plug in the i18n library of user's choice would be the best. It's not that hard. Most of the component libraries are going that way...

You can take a look at how "big guys" do it - in this case Vuetify. Docs Code

Upvotes: 3

Related Questions