@graphcommerce/lingui-next 8.0.5 → 8.0.6-canary.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Change Log
2
2
 
3
+ ## 8.0.6-canary.0
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2196](https://github.com/graphcommerce-org/graphcommerce/pull/2196) [`84c50e4`](https://github.com/graphcommerce-org/graphcommerce/commit/84c50e49a1a7f154d4a8f4045c37e773e20283ad) - Allow Lingui to use linguiLocale with country identifiers like `en-us`, it would always load `en` in this case. Introced a new `useLocale` hook to use the correct locale string to use in Intl methods.
8
+ ([@paales](https://github.com/paales))
9
+
3
10
  ## 8.0.5
4
11
 
5
12
  ## 8.0.5-canary.10
package/Config.graphqls CHANGED
@@ -1,6 +1,8 @@
1
1
  extend input GraphCommerceStorefrontConfig {
2
2
  """
3
- Specify a custom locale for to load translations.
3
+ Specify a custom locale for to load translations. Must be lowercase valid locale.
4
+
5
+ This value is also used for the Intl.
4
6
  """
5
7
  linguiLocale: String
6
8
  }
@@ -1,23 +1,29 @@
1
- import { storefrontConfig, storefrontConfigDefault } from '@graphcommerce/next-ui'
1
+ import { useLocale } from '@graphcommerce/next-ui'
2
2
  import { i18n, Messages } from '@lingui/core'
3
3
  import { I18nProvider, I18nProviderProps } from '@lingui/react'
4
4
  import React, { useMemo } from 'react'
5
5
  import { MessageLoader, SyncMessageLoader } from '../types'
6
+ import { normalizeLocale } from '../lib/normalizeLocale'
6
7
 
7
8
  export type LinguiProviderProps = Omit<I18nProviderProps, 'i18n'> & {
8
9
  children: React.ReactNode
9
10
  loader: MessageLoader
10
11
  ssrLoader: SyncMessageLoader
11
- locale: string
12
+ /**
13
+ * @deprecated not necessary anumore
14
+ */
15
+ locale?: string
12
16
  }
13
17
 
14
- export const localeConfig = (locale: string = storefrontConfigDefault().locale) =>
15
- storefrontConfig(locale)?.linguiLocale ?? locale?.split('-')[0]
18
+ /**
19
+ * @deprecated use normalizeLocale
20
+ */
21
+ export const localeConfig = normalizeLocale
16
22
 
17
23
  export function LinguiProvider(props: LinguiProviderProps) {
18
24
  const { loader, ssrLoader, locale, ...i18nProviderProps } = props
19
25
 
20
- const localeOnly = localeConfig(locale)
26
+ const localeOnly = useLocale()
21
27
 
22
28
  useMemo(() => {
23
29
  const data = globalThis.document?.getElementById('lingui')
package/config.js CHANGED
@@ -15,9 +15,7 @@ function linguiNextConfig(config) {
15
15
  const { locales, ...otherConfig } = config
16
16
  return {
17
17
  orderBy: 'messageId',
18
- locales: isMonorepo()
19
- ? ['en', 'nl', 'fr', 'de', 'es', 'it']
20
- : config.locales.map((l) => l?.split('-')[0]),
18
+ locales: isMonorepo() ? ['en', 'nl', 'fr', 'de', 'es', 'it'] : config.locales,
21
19
  // formatOptions: { lineNumbers: false, origins: false, explicitIdAsDefault: true },
22
20
  format: formatter({ explicitIdAsDefault: true, lineNumbers: false, origins: false }),
23
21
  catalogs: [
@@ -4,6 +4,7 @@ import { DocumentContext, DocumentInitialProps } from 'next/document'
4
4
  // eslint-disable-next-line @next/next/no-document-import-in-page
5
5
  import type NextDocument from 'next/document'
6
6
  import React from 'react'
7
+ import { normalizeLocale } from '../lib/normalizeLocale'
7
8
  import { MessageLoader } from '../types'
8
9
 
9
10
  export type LinguiDocumentProps = { linguiScriptTag: React.ReactNode }
@@ -16,7 +17,7 @@ export function withLingui(
16
17
  static async getInitialProps(ctx: DocumentContext) {
17
18
  const initial = await Document.getInitialProps(ctx)
18
19
 
19
- const locale = ctx.locale?.split('-')?.[0]
20
+ const locale = normalizeLocale(ctx.locale)
20
21
 
21
22
  if (!locale) return initial
22
23
  try {
@@ -1,3 +1,5 @@
1
+ import { storefrontConfig, storefrontConfigDefault } from '@graphcommerce/next-ui'
2
+
1
3
  /**
2
4
  * To support using multiple storefronts using the same language locale (which
3
5
  * next.js does not support), we use an additional 'tag' in the locale code in
@@ -9,16 +11,16 @@
9
11
  * Use this method to get a 'normalized' locale that can safely be used in such
10
12
  * places.
11
13
  */
12
- export function normalizeLocale(locale: string | undefined) {
13
- if (!locale) return locale
14
+ export function normalizeLocale(locale: string | undefined = storefrontConfigDefault().locale) {
15
+ const linguiLocale = storefrontConfig(locale)?.linguiLocale
16
+ if (linguiLocale) return linguiLocale
14
17
 
15
18
  // Specifically match the xx-yy-storecode format, so we don't accidently 'fix'
16
19
  // valid locales such as he-Hebr-IL or zh-Hans-CN. This this isn't perfect and
17
20
  // we should consider a more formalized way to use such pseudo-locales, which
18
21
  // can be matched more precisely.
22
+
19
23
  const matches = locale?.match(/([a-z]{2})-([a-z]{2})-([a-z]+)/i)
20
- if (matches) {
21
- return `${matches[1]}-${matches[2]}`
22
- }
24
+ if (matches) return `${matches[1]}-${matches[2]}`
23
25
  return locale
24
26
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/lingui-next",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.0.5",
5
+ "version": "8.0.6-canary.0",
6
6
  "sideEffects": false,
7
7
  "scripts": {
8
8
  "dev": "tsc -W"
@@ -18,11 +18,11 @@
18
18
  "@lingui/conf": "4.7.0"
19
19
  },
20
20
  "peerDependencies": {
21
- "@graphcommerce/eslint-config-pwa": "^8.0.5",
22
- "@graphcommerce/next-config": "^8.0.5",
23
- "@graphcommerce/next-ui": "^8.0.5",
24
- "@graphcommerce/prettier-config-pwa": "^8.0.5",
25
- "@graphcommerce/typescript-config-pwa": "^8.0.5",
21
+ "@graphcommerce/eslint-config-pwa": "^8.0.6-canary.0",
22
+ "@graphcommerce/next-config": "^8.0.6-canary.0",
23
+ "@graphcommerce/next-ui": "^8.0.6-canary.0",
24
+ "@graphcommerce/prettier-config-pwa": "^8.0.6-canary.0",
25
+ "@graphcommerce/typescript-config-pwa": "^8.0.6-canary.0",
26
26
  "@lingui/core": "^4.2.1",
27
27
  "@lingui/macro": "^4.2.1",
28
28
  "@lingui/react": "^4.2.1",