Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i18n - sync language change on custom element #236

Open
pawepaw opened this issue Dec 9, 2020 · 2 comments
Open

i18n - sync language change on custom element #236

pawepaw opened this issue Dec 9, 2020 · 2 comments

Comments

@pawepaw
Copy link

pawepaw commented Dec 9, 2020

Hi,

I've configured to pass i18n to my web component but when I change language on page where I have this web component embedded it's not synced with language on web component. How can I keep it in sync?

beforeCreateVueInstance: rootElement => {
    rootElement.i18n = i18n
    return rootElement
  }

and i18n

const i18n = new VueI18n({
  locale: 'en',
  fallbackLocale: 'en',
  messages,
  silentTranslationWarn: true
})

export default i18n

Where messages is just traditional json with translations.

The only way I figured out is to just pass language via binding but it seems to be stupid.

@karol-f
Copy link
Owner

karol-f commented Dec 9, 2020

Can You please prepare CodeSandbox?

@tmcdos
Copy link

tmcdos commented Nov 8, 2023

In your parent web page (where the Web Component is being used) when you change the locale - you should also update the locale attribute of the HTML tag for your Web Component. In your Vue app you should declare locale as a String prop on your App.vue and add a watcher for it. The watcher should change the locale of your Vue-i18n inside the Web Component. IF you want a two-way sync - you should emit an event from your App.vue whenever the locale is changed from inside your WebComponent as opposed to the wrapping web page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants