vuestorefront / vue-storefront

Alokai is a Frontend as a Service solution that simplifies composable commerce. It connects all the technologies needed to build and deploy fast & scalable ecommerce frontends. It guides merchants to deliver exceptional customer experiences quickly and easily.
https://www.alokai.com
MIT License
10.59k stars 2.08k forks source link

feat: allow overwriting i18n configuration through plugins #6850

Closed lsliwaradioluz closed 1 year ago

lsliwaradioluz commented 1 year ago

Description

As a developer, I want to be able to change the default currency and locale at runtime. An example might be a multistore setup where I might have a plugin loading the store configuration including default language and currency for the store (which is a pretty common scenario).

Unfortunately, the current implementation of the i18n-cookies plugin only relies on properties provided in nuxt.config.js. Therefore, influencing the outcome of this plugin at runtime is rather impossible - not good in a multistore setup where we have a single Vue Storefront application displaying several separate stores with different locale/currency settings.

This PR creates a gateway for Nuxt plugins to add defaultLocale, defaultCurrency and defaultCountry to the context object so that the i18n-cookies plugin picks these values up and does its job the usual way. An example of a flow supported by this PR could be:

  1. Plugin A loads store configuration from Commerce API. The configuration contains default language and currency for the store. The plugin writes these values to the application context object.
  2. Plugin b (i18n-cookies) reads these values from the context. If it does not find them, it falls back to the configuration defined in nuxt.config.js.

Related Issue

IN-1576

Types of changes

Checklist:

Changelog