@graphcommerce/lingui-next 1.3.1 → 2.0.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,60 +1,52 @@
1
1
  # Change Log
2
2
 
3
- All notable changes to this project will be documented in this file.
4
- See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
3
+ ## 2.0.0
5
4
 
6
- ## [1.3.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/lingui-next@1.3.0...@graphcommerce/lingui-next@1.3.1) (2022-01-04)
7
-
8
-
9
- ### Bug Fixes
5
+ ### Major Changes
10
6
 
11
- * pages would be blank because the locale couldn't properly be loaded ([5fe9ecd](https://github.com/ho-nl/m2-pwa/commit/5fe9ecd204c3f9efddcf95d54464b1b931ef682e))
7
+ - [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
8
+ [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
9
+ Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
12
10
 
11
+ All notable changes to this project will be documented in this file. See
12
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
13
13
 
14
+ ## [1.3.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/lingui-next@1.3.0...@graphcommerce/lingui-next@1.3.1) (2022-01-04)
14
15
 
16
+ ### Bug Fixes
15
17
 
18
+ - pages would be blank because the locale couldn't properly be loaded
19
+ ([5fe9ecd](https://github.com/ho-nl/m2-pwa/commit/5fe9ecd204c3f9efddcf95d54464b1b931ef682e))
16
20
 
17
21
  # [1.3.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/lingui-next@1.2.4...@graphcommerce/lingui-next@1.3.0) (2022-01-03)
18
22
 
19
-
20
23
  ### Features
21
24
 
22
- * **framer-next-pages:** reduce rerenders when navigating to a new page ([5cf3301](https://github.com/ho-nl/m2-pwa/commit/5cf330130bb3527057da015e3c4a6fa295d7262e))
23
-
24
-
25
-
26
-
25
+ - **framer-next-pages:** reduce rerenders when navigating to a new page
26
+ ([5cf3301](https://github.com/ho-nl/m2-pwa/commit/5cf330130bb3527057da015e3c4a6fa295d7262e))
27
27
 
28
28
  ## [1.2.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/lingui-next@1.2.0...@graphcommerce/lingui-next@1.2.1) (2021-12-03)
29
29
 
30
-
31
30
  ### Bug Fixes
32
31
 
33
- * make sure we're not throwing a generic 'No locales specified' when there is a generic error ([fd3dd23](https://github.com/ho-nl/m2-pwa/commit/fd3dd233fb293f6afc08636316a34d2a2db4bbc3))
34
-
35
-
36
-
37
-
32
+ - make sure we're not throwing a generic 'No locales specified' when there is a generic error
33
+ ([fd3dd23](https://github.com/ho-nl/m2-pwa/commit/fd3dd233fb293f6afc08636316a34d2a2db4bbc3))
38
34
 
39
35
  # [1.2.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/lingui-next@1.1.0...@graphcommerce/lingui-next@1.2.0) (2021-11-12)
40
36
 
41
-
42
37
  ### Bug Fixes
43
38
 
44
- * error in cli about missing plurals ([fedde70](https://github.com/ho-nl/m2-pwa/commit/fedde70012b0b5694114a0f5c3ab0f7d5c8cd276))
45
-
39
+ - error in cli about missing plurals
40
+ ([fedde70](https://github.com/ho-nl/m2-pwa/commit/fedde70012b0b5694114a0f5c3ab0f7d5c8cd276))
46
41
 
47
42
  ### Features
48
43
 
49
- * added tons of translations ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
50
-
51
-
52
-
53
-
44
+ - added tons of translations
45
+ ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
54
46
 
55
47
  # 1.1.0 (2021-11-11)
56
48
 
57
-
58
49
  ### Features
59
50
 
60
- * lingui configuration and integration greatly simplified and fixed ssr ([d8ec22a](https://github.com/ho-nl/m2-pwa/commit/d8ec22a80295af854a4cf6f357c4fb137c5b550d))
51
+ - lingui configuration and integration greatly simplified and fixed ssr
52
+ ([d8ec22a](https://github.com/ho-nl/m2-pwa/commit/d8ec22a80295af854a4cf6f357c4fb137c5b550d))
@@ -1,7 +1,6 @@
1
1
  import { i18n, Messages } from '@lingui/core'
2
2
  import { I18nProvider, I18nProviderProps } from '@lingui/react'
3
3
  import { nl, en, fr } from 'make-plural/plurals'
4
- import { useRouter } from 'next/router'
5
4
  import React, { useMemo } from 'react'
6
5
  import { MessageLoader, SyncMessageLoader } from '../types'
7
6
 
@@ -9,20 +8,21 @@ type LinguiProviderProps = Omit<I18nProviderProps, 'i18n'> & {
9
8
  children: React.ReactNode
10
9
  loader: MessageLoader
11
10
  ssrLoader: SyncMessageLoader
12
- locale?: string
11
+ locale: string
13
12
  }
14
13
 
14
+ // todo: Load these plurals with a loader, however dynamic imports doesn't support tree shaking so loading them dynamically will load all locales.
15
15
  i18n.loadLocaleData({
16
16
  nl: { plurals: nl },
17
17
  fr: { plurals: fr },
18
18
  en: { plurals: en },
19
19
  })
20
20
 
21
- export default function LinguiProvider(props: LinguiProviderProps) {
21
+ export function LinguiProvider(props: LinguiProviderProps) {
22
22
  const { loader, ssrLoader, locale, ...i18nProviderPRops } = props
23
23
 
24
24
  useMemo(() => {
25
- const localeOnly = locale?.split('-')?.[0] ?? 'en'
25
+ const localeOnly = locale?.split('-')[0]
26
26
  const data = globalThis.document?.getElementById('lingui')
27
27
 
28
28
  if (data?.lang === localeOnly && data.textContent) {
@@ -44,16 +44,18 @@ export default function LinguiProvider(props: LinguiProviderProps) {
44
44
  } catch (e) {
45
45
  if (process.env.NODE_ENV !== 'production')
46
46
  throw new Error(
47
- `Can not find the .po file for the locale '${localeOnly}'. Possible reasons:
48
- - If you've added a new locale, please run 'yarn lingui:extact' to generate the .po file.
49
- - Make sure the passed load function is correct.`,
47
+ `Could not load locale. Can't find the .po file for the locale '${localeOnly}'. Possible reasons:
48
+ - You have configured a new locale in the .env and there is no .po file for it. Please run 'yarn lingui:extact' to generate the .po file or duplicate an existing one.
49
+ - The load function you passed to is incorrect.`,
50
50
  )
51
51
  if (process.env.NODE_ENV === 'production') console.error(e)
52
52
  }
53
53
  })()
54
54
  }
55
55
  }
56
- }, [locale, loader])
56
+ // We dont want to call this when the loader/ssrLoader changes, because it will cause a re-render.
57
+ // eslint-disable-next-line react-hooks/exhaustive-deps
58
+ }, [locale])
57
59
 
58
60
  return <I18nProvider i18n={i18n} {...i18nProviderPRops} />
59
61
  }
package/index.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { default as LinguiProvider } from './components/LinguiProvider'
2
- export * from './utils/linguiWrapGetInitialProps'
1
+ export { LinguiProvider } from './components/LinguiProvider'
2
+ export * from './utils/withLingui'
3
3
  export * from './types'
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@graphcommerce/lingui-next",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "sideEffects": false,
5
5
  "scripts": {
6
6
  "dev": "tsc -W"
7
7
  },
8
8
  "prettier": "@graphcommerce/prettier-config-pwa",
9
- "browserslist": [
10
- "extends @graphcommerce/browserslist-config-pwa"
11
- ],
12
9
  "eslintConfig": {
13
10
  "extends": "@graphcommerce/eslint-config-pwa",
14
11
  "parserOptions": {
@@ -16,21 +13,19 @@
16
13
  }
17
14
  },
18
15
  "dependencies": {
19
- "@lingui/core": "^3.13.0",
20
- "@lingui/macro": "^3.13.0",
21
- "@lingui/react": "^3.13.0"
16
+ "@lingui/core": "^3.13.2",
17
+ "@lingui/macro": "^3.13.2",
18
+ "@lingui/react": "^3.13.2"
22
19
  },
23
20
  "devDependencies": {
24
- "@graphcommerce/browserslist-config-pwa": "^3.0.3",
25
- "@graphcommerce/eslint-config-pwa": "^3.1.10",
26
- "@graphcommerce/prettier-config-pwa": "^3.0.5",
27
- "@graphcommerce/typescript-config-pwa": "^3.1.2",
28
- "@playwright/test": "^1.17.1"
21
+ "@graphcommerce/eslint-config-pwa": "^4.0.0",
22
+ "@graphcommerce/prettier-config-pwa": "^4.0.0",
23
+ "@graphcommerce/typescript-config-pwa": "^4.0.0",
24
+ "@playwright/test": "^1.18.1"
29
25
  },
30
26
  "peerDependencies": {
31
- "next": "^12.0.7",
27
+ "next": "^12.0.10",
32
28
  "react": "^17.0.2",
33
29
  "react-dom": "^17.0.2"
34
- },
35
- "gitHead": "dce525a80fd42cebe9af0b207c3bd27f89be9543"
30
+ }
36
31
  }
@@ -0,0 +1,46 @@
1
+ import { i18n } from '@lingui/core'
2
+ // eslint-disable-next-line @next/next/no-document-import-in-page
3
+ import { DocumentContext } from 'next/document'
4
+ // eslint-disable-next-line @next/next/no-document-import-in-page
5
+ import type NextDocument from 'next/document'
6
+ import React from 'react'
7
+ import { MessageLoader } from '../types'
8
+
9
+ export function withLingui(
10
+ Document: typeof NextDocument,
11
+ load: MessageLoader,
12
+ ): typeof NextDocument {
13
+ return class DocumentWithEmotionCache extends Document {
14
+ static async getInitialProps(ctx: DocumentContext) {
15
+ const initial = await Document.getInitialProps(ctx)
16
+
17
+ const locale = ctx.locale?.split('-')?.[0]
18
+
19
+ if (!locale) return initial
20
+ try {
21
+ const { messages } = await load(locale)
22
+
23
+ i18n.load(locale, messages)
24
+ i18n.activate(locale)
25
+
26
+ return {
27
+ ...initial,
28
+ head: [
29
+ ...(React.Children.toArray(initial.head) as Array<JSX.Element | null>),
30
+ <script
31
+ key='lingui'
32
+ type='application/json'
33
+ id='lingui'
34
+ lang={locale}
35
+ // eslint-disable-next-line react/no-danger
36
+ dangerouslySetInnerHTML={{ __html: JSON.stringify(messages) }}
37
+ />,
38
+ ],
39
+ }
40
+ } catch (e) {
41
+ if (process.env.NODE_ENV !== 'production') console.error(e)
42
+ return initial
43
+ }
44
+ }
45
+ }
46
+ }
@@ -1,42 +0,0 @@
1
- import { i18n } from '@lingui/core'
2
- // eslint-disable-next-line @next/next/no-document-import-in-page
3
- import { DocumentContext, DocumentInitialProps } from 'next/document'
4
- import React from 'react'
5
- import { MessageLoader } from '../types'
6
-
7
- export function linguiWrapGetInitialProps(
8
- getInitialProps: (ctx: DocumentContext) => Promise<DocumentInitialProps>,
9
- load: MessageLoader,
10
- ): (ctx: DocumentContext) => Promise<DocumentInitialProps> {
11
- return async (ctx: DocumentContext) => {
12
- const initial = await getInitialProps(ctx)
13
-
14
- const locale = ctx.locale?.split('-')?.[0]
15
-
16
- if (!locale) return initial
17
- try {
18
- const { messages } = await load(locale)
19
-
20
- i18n.load(locale, messages)
21
- i18n.activate(locale)
22
-
23
- return {
24
- ...initial,
25
- head: [
26
- ...(React.Children.toArray(initial.head) as Array<JSX.Element | null>),
27
- <script
28
- key='lingui'
29
- type='application/json'
30
- id='lingui'
31
- lang={locale}
32
- // eslint-disable-next-line react/no-danger
33
- dangerouslySetInnerHTML={{ __html: JSON.stringify(messages) }}
34
- />,
35
- ],
36
- }
37
- } catch (e) {
38
- if (process.env.NODE_ENV !== 'production') console.error(e)
39
- return initial
40
- }
41
- }
42
- }