kazupon / vue-i18n

:globe_with_meridians: Internationalization plugin for Vue.js
https://kazupon.github.io/vue-i18n/
MIT License
7.25k stars 860 forks source link

[Feature Request] Animations on locale change #538

Open JakubKoralewski opened 5 years ago

JakubKoralewski commented 5 years ago

The idea is to allow creating animations on locale changes. Right now if you click on a language the new text just snaps into place, but if you could somehow provide a function that would get ran on every locale change it would open doors to things previously unfathomable. Dramatic beginning...

I am not familiar with the codebase so take these suggestions with a grain of salt, but here's how I'd do it. I see two ways:

1. A global localeChanged hook

Would be useful for creating whole page animations.

Examples:

The function hook should provide the new locale, but maybe someone finds use for the old locale too, so let's not rule that out.

2. A mutation function

For more intricate effects to somehow animate the specific HTMLElement/VNode the internationalized vue-i18n data sits on.

Examples:

You would be able to add CSS classes and let CSS transitions and animations do the work. Or maybe it would be even better if this was somehow integrated with transition or/and transition-group in Vue. However, maybe someone could find a different application for being able to inject their own logic on locale change, so this may not be the best idea. How I'd see it: the function will give you the VNode, old locale's value and new locale's value. You'll have to return a new value. Not sure how that would work with some asynchronous animations (like the Matrix one) that last for a longer period of time.

I don't know if I'd be embarrassed or happy if it turns out that this API is already provided.

ekil1100 commented 5 years ago

Agree ! I was looking for the solution to animation the locale change, if there is a localeChange hook would be nice.

you06 commented 5 years ago

Looking for locale change event and find this issue, great feature! watch the locale variable would be a solution, but not good

watch: {
  '$i18n.locale': function(newVal, oldVal) {
    console.log('locale change', newVal)
  }
}
ipluser commented 4 years ago

Looking for locale change event and find this issue, great feature! watch the locale variable would be a solution, but not good

watch: {
  '$i18n.locale': function(newVal, oldVal) {
    console.log('locale change', newVal)
  }
}

Not Vue file, how to listen for the locale change in normal javascript file.

JakubKoralewski commented 4 years ago

watch the locale variable would be a solution, but not good

watch: {
  '$i18n.locale': function(newVal, oldVal) {
    console.log('locale change', newVal)
  }
}

That's possible, but the idea for me was mostly being able to detect which nodes changed on locale change as well as having the option to intercept an incoming change for a particular node and react however you want enabling custom animations or built-in ones.

HiHub-Online commented 3 years ago

Where can I vote for an idea? There is a great lack of smoothness when changing the language.