dkfbasel / vuex-i18n

Localization plugin for vue.js 2.0 using vuex as store
MIT License
665 stars 56 forks source link

Translate sentences #94

Closed Ni55aN closed 5 years ago

Ni55aN commented 6 years ago

It may be useful to translate separately every sentence of the paragraph It can be done with the help of next filter

Vue.filter('stranslate', text => { // translate sentences
    if(!Vue.prototype.$t) throw 'Module vuex-i18n required';

    return text
        .split(/\. */g)
        .map(t => Vue.prototype.$t(t)) 
                   // or translate() function in scope of vuex-i18n-plugin.js
        .join('. ')
}); 

I can do a PR if this filter is useful for you

tikiatua commented 6 years ago

Hi @Ni55aN

Thank you for your suggestion. I would like to keep the api of the vuexI18n-plugin rather small. There fore, I would suggest that we finally create a proper documentation and add this in an example section.

Ni55aN commented 5 years ago

Is there any progress on this feature?

tikiatua commented 5 years ago

Hi @Ni55aN

Thank you for following up on this. I will likely not implement this feature directly into the library. In my opinion, the context of adjoint sentences often matters and therefore one should not just concatenate separate translations. Additionally translating one string could have unintended side-effects in a different part of the application.

That is also one of the reasons, that I do not think it should be possible to reference from one translation string to another – i.e. something like {sentence: "this is a translation of [email]", email: "message"} – which is implemented by other libraries.

However, a similar feature would be the possibility to have complete text blocks or even html content with included vue components as a translation element. I will look into how this can be achieved without compromising security too much.

An update in this direction should be available sometime in November.