Replies: 4 comments 7 replies
-
Thank you for your feedback! Unfortunately, in vue-i18n v9, it is not possible to support i18n in Vue applications using both Composition API Style and Legacy API Style at the same time. This is the intention of vue-i18n v9. Several of the reasons for the restriction are as follows:
|
Beta Was this translation helpful? Give feedback.
-
The doc is not really clear that vue-18n composition API mode and legacy API mode are not compatible. |
Beta Was this translation helpful? Give feedback.
-
if it's too difficult for you to move to composition API for an old project, I found a 'magic' way to be compatible with it: install two i18n instances that use different legacy options.
|
Beta Was this translation helpful? Give feedback.
-
I am running into a similar issue while migrating a large project from Vue 2 to Vue 3. Because there are so many existing components, most components will continue to use the Vue Options API, and the app will use the Vue I18n Legacy API: moving all components to the Composition API would make it much harder to migrate to Vue 3, which we want to do sooner rather than later. However, we have run into an issue with the components that we have migrated to the Vue Composition API. There aren't many of these, but some components had to be migrated to the Composition API due to changes in Vue 3. (For example, a component that used The answer above seems to imply that if you have to migrate a single component to the Composition API, then you have to migrate them all. However, that would not be practical for our project. In my opinion, it also doesn't seem consistent with Vue 3's approach to the Composition API, which is opt-in on the component level. While I know that some projects will find it easiest to only use the Options API or only use the Composition API, another strategy is to use the Options API for simple components and use the Composition API for complex components where grouping functionality by concern is especially useful. Our project will mostly continue to use the Options API, but like I said, some components will have to use the Composition API. We will probably also start experimenting with using the Composition API for new components, especially complex new components. Vue 3 seems to support this approach, as do other plugins, including Vue Router and Vuex. However, Vue I18n seems to require that all components use one or the other (at least if you are using local scope). The answer above also seems to say that Vue plans to deprecate the Options API. While that may have been the case at one point, I don't believe that that's the plan right now: https://stackoverflow.com/questions/68611657/do-i-have-to-use-the-composition-api-in-vue-3-or-can-i-still-do-things-the-vue I think that it would be very helpful for Vue I18n to provide a migration path for projects that use a mix of the Options API and the Vue Composition API. We are loving many other features of Vue I18n v9, but we have found this aspect of the migration to be a challenge. At the moment, our plan for components that use export default {
setup() {
let i18n
onBeforeMount(() => { i18n = getCurrentInstance().ctx.$i18n })
}
} This allows us to use the i18n object within any code that is run after the |
Beta Was this translation helpful? Give feedback.
-
It looks like the composition API doesn't work well with legacy when it comes to locale scopes. I have an app where I generally want i18n enabled everywhere with local scopes. So it's common to see a component look like this:
There are a few places where I actually want to use the composition API. Essentially I have a composition function that does some common work and needs it's own translations. About 4-5 components use this composition function.
So the composition function looks like this:
And the component that uses this function looks like this:
My global setup looks like this:
I'm not sure if this is a feature request or bug, but shouldn't this work? Because it definitely doesn't. Now the only translations I can see are global translations in all of my components. Even the components that don't use/have a setup function. Is this a use case not supported or am I doing something wrong.
Module versions:
vue
: 3.0.9vue-i18n
: 9.0.0Beta Was this translation helpful? Give feedback.
All reactions