Vue-i18n: Override component translations

Created on 20 Sep 2016  路  8Comments  路  Source: kazupon/vue-i18n

I would like to create translatable reusable component, but I cannot figure out how to override component default locales from global locales. Is it possible now?
Like this maybe
In component:

locales: {
  en: { hello: 'world' },
}

In global locales:

en: { componentName: { hello: 'my world' } }

Most helpful comment

@kazupon another use case I currently face is that a few customers disagree with the way to translate a word.

Components translations is fantastic to keep the translations close to the need. Global translation could be a nice way to customise the translation when a subset of the users need to see something translated differently.

All 8 comments

You can use Component locale.
see the below docs:
https://kazupon.github.io/vue-i18n/component.html

Yes, I have seen this docs, but this is not what I was looking for. Here I can override global locale by components locale, but what about the opposite?

but what about the opposite?

I cannot understand use-cases...
I think we don't hardly override component locales with global locales.

Possible use case is when I want to create a component that is not easily edited (downloaded from npm for example) and supports i18n, but also can be translated from outside.

@kazupon another use case I currently face is that a few customers disagree with the way to translate a word.

Components translations is fantastic to keep the translations close to the need. Global translation could be a nice way to customise the translation when a subset of the users need to see something translated differently.

There is definitely a valid use case for this. Please reopen and reconsider this.

I would second the reopening of it (if it's not solved in another way by now). My use case is also reusable components where I want to override translations from the containing app without changing the component.

(e.g. for german I at least want to change the formal "you" (Sie) to a more personal one ("Du") depending on the use case).

Hi guys, we have faced the same issue, where we have a core project used as a base for other projects and we needed to override some core components translations. As there is no easy way to do it with vue-i18n, after some research we decided to go for a custom translation loader for Webpack. We have open sourced the solution, so feel free to check it out and propose modification, if that will not fit your use case.

https://github.com/infermedica/object-override-loader

It turned out to be more general purpose loader to override JSON/YAML resources during the compilation. It does not interfere with other loaders like @kazupon/vue-i18n-loader or yaml-loader.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zecar picture zecar  路  15Comments

metalanti picture metalanti  路  15Comments

flaird picture flaird  路  15Comments

thelinuxlich picture thelinuxlich  路  66Comments

flaird picture flaird  路  28Comments