Skip to content

Commit

Permalink
fix(vue-demo-store): extract lang code from accept-language header (#307
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mkucmus authored Jul 13, 2023
1 parent 1c56f31 commit b3d391b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/itchy-kiwis-sin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"vue-demo-store": patch
---

Extract lang code from accept-language header in SSR for Intl.NumberFormat purposes
10 changes: 8 additions & 2 deletions templates/vue-demo-store/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,18 @@ sessionContextData.value = await getSessionContext(apiInstance);
// }
// );
// read the locale from accept-language header (i.e. en-GB or de-DE)
// read the locale/lang code from accept-language header (i.e. en, en-GB or de-DE)
// and set configuration for price formatting globally
const headers = useRequestHeaders();
// Extract the first (with highest priority order) locale or lang code from accept-language header
// for example: "en-US;q=0.7,en;q=0.3" will return "en-US"
const localeFromHeader = headers?.["accept-language"]
?.split(",")
?.find((languageConfig) => languageConfig.match(/([a-z]){2}\-([A-Z]{2})/));
?.map(
(languageConfig) => languageConfig.match(/^([a-z]{2}(?:-[A-Z]{2})?)/)?.[0],
)
.find(Boolean);
usePrice({
currencyCode: sessionContextData.value?.currency?.isoCode || "",
localeCode: localeFromHeader,
Expand Down

2 comments on commit b3d391b

@vercel
Copy link

@vercel vercel bot commented on b3d391b Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo.vercel.app
frontends-demo-shopware-frontends.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app

@vercel
Copy link

@vercel vercel bot commented on b3d391b Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.