vue-storefront icon indicating copy to clipboard operation
vue-storefront copied to clipboard

fix(core): allow disabling locale redirects

Open lsliwaradioluz opened this issue 3 years ago • 4 comments

Description

I think it would be a good idea to leave the door open for preventing locale redirects in vsf applications.

Last month we overwrote the default i18n locale redirects logic in the i18nCookiesPlugin. It detects the browser locale and redirects to it unconditionally (provided that it's one of the locales available in the VSF application). It happens even if the detectBrowserLanguage option is set to false.

My proposition here is to give our customers the ability to prevent redirects by setting the detectBrowserLanguage to false. And - to prevent generating the cookies by the i18n library - use the following configuration:

i18n: {
    detectBrowserLanguage: {
      useCookie: false
    }
}

It's the approach suggested by the nuxt-i18n documentation: image

Types of changes

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • [x] I have read the CONTRIBUTING document.

Changelog

  • [z] I have updated the Changelog (V1) v2 and mentioned all breaking changes in the public API.
  • [ ] I have documented all new public APIs and made changes to existing docs mentioning the parts I've changed so they're up to date.

Tests

  • [ ] I have written test cases for my code
  • [x] I have tested my Pull Request on production build and (to my knowledge) it works without any issues
  • [ ] I have added tests to cover my changes.
  • [ ] All new and existing tests passed.

I tested manually my code, and it works well with both:

  • [ ] Default Theme
  • [ ] Capybara Theme

Code standards

  • [ ] My code follows the code style of this project.

Docs

  • [ ] My change requires a change to the documentation.
  • [x] I have updated the documentation accordingly.

lsliwaradioluz avatar Dec 05 '21 19:12 lsliwaradioluz

:blue_heart: vsf-next-demo successfully deployed at

github-actions[bot] avatar Dec 05 '21 19:12 github-actions[bot]

I would like to add the possibility to not update the currency also because the current version is also updating the currency cookie based on the browser locale.

bloodf avatar Dec 06 '21 12:12 bloodf

I would like to add the possibility to not update the currency also because the current version is also updating the currency cookie based on the browser locale.

It will be resolved in another task

dawid-ziobro avatar Dec 06 '21 13:12 dawid-ziobro

Hello, I tried to disable the accepted languages of the browser by adding this in my code : i18n: { localeDetection: false, detectBrowserLanguage: false, }

But it doesn't work

SullyAnn avatar Jun 10 '22 10:06 SullyAnn

The proposed fix seems incomplete to me: Even if no redirect is sent,app.i18n.cookieValues will still store the targetLocale. I think a better approach would be to set targetLocale to i18nOptions.defaultLocale if i18nOptions.detectBrowserLanguage is false and have a different option to disable redirects to i18n targets

Also if (redirectPath && i18nOptions.detectBrowserLanguage) does work as proposed, if it is set to false as it was before

vtoc avatar Dec 07 '22 12:12 vtoc

Closed due to inactivity

filrak avatar Feb 10 '23 11:02 filrak