@graphcommerce/lingui-next 1.3.1 β†’ 2.1.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,88 @@
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.1.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
+ ### Minor 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
+ - [#1274](https://github.com/ho-nl/m2-pwa/pull/1274)
8
+ [`b08a8eb1d`](https://github.com/ho-nl/m2-pwa/commit/b08a8eb1d024b9d3e7712ef034029151670db275)
9
+ Thanks [@paales](https://github.com/paales)! - Fixed extraction of translations and updated
10
+ various translations for english πŸ‡ΊπŸ‡ΈπŸ‡¬πŸ‡§ and dutch πŸ‡³πŸ‡±
12
11
 
12
+ ### Patch Changes
13
13
 
14
+ - [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
15
+ [`ce09388e0`](https://github.com/ho-nl/m2-pwa/commit/ce09388e0d7ef33aee660612340f6fbae15ceec2)
16
+ Thanks [@paales](https://github.com/paales)! - We've moved lots of internal packages from
17
+ `dependencies` to `peerDependencies`. The result of this is that there will be significantly less
18
+ duplicate packages in the node_modules folders.
14
19
 
20
+ * [#1276](https://github.com/ho-nl/m2-pwa/pull/1276)
21
+ [`52a45bba4`](https://github.com/ho-nl/m2-pwa/commit/52a45bba4dc6dd6df3c81f5023df7d23ed8a534d)
22
+ Thanks [@paales](https://github.com/paales)! - Upgraded to
23
+ [NextJS 12.1](https://nextjs.org/blog/next-12-1)! This is just for compatibility, but we'll be
24
+ implementing
25
+ [On-demand Incremental Static Regeneration](https://nextjs.org/blog/next-12-1#on-demand-incremental-static-regeneration-beta)
26
+ soon.
15
27
 
28
+ This will greatly reduce the requirement to rebuid stuff and we'll add a management UI on the
29
+ frontend to be able to revalidate pages manually.
16
30
 
17
- # [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)
31
+ ## 2.0.1
18
32
 
33
+ ### Patch Changes
19
34
 
20
- ### Features
35
+ - [`0cbaa878b`](https://github.com/ho-nl/m2-pwa/commit/0cbaa878b8a844d5abbeb1797b625a33130e6514)
36
+ Thanks [@paales](https://github.com/paales)! - Added homepage and repository package.json files,
37
+ so that the packages link to back to the website and repository
21
38
 
22
- * **framer-next-pages:** reduce rerenders when navigating to a new page ([5cf3301](https://github.com/ho-nl/m2-pwa/commit/5cf330130bb3527057da015e3c4a6fa295d7262e))
39
+ ## 2.0.0
23
40
 
41
+ ### Major Changes
24
42
 
43
+ - [#1258](https://github.com/ho-nl/m2-pwa/pull/1258)
44
+ [`ad36382a4`](https://github.com/ho-nl/m2-pwa/commit/ad36382a4d55d83d9e47b7eb6a02671a2a631a05)
45
+ Thanks [@paales](https://github.com/paales)! - Upgraded to Material UI 5
25
46
 
47
+ All notable changes to this project will be documented in this file. See
48
+ [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
26
49
 
50
+ ## [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)
27
51
 
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)
52
+ ### Bug Fixes
29
53
 
54
+ - pages would be blank because the locale couldn't properly be loaded
55
+ ([5fe9ecd](https://github.com/ho-nl/m2-pwa/commit/5fe9ecd204c3f9efddcf95d54464b1b931ef682e))
30
56
 
31
- ### Bug Fixes
57
+ # [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)
32
58
 
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))
59
+ ### Features
34
60
 
61
+ - **framer-next-pages:** reduce rerenders when navigating to a new page
62
+ ([5cf3301](https://github.com/ho-nl/m2-pwa/commit/5cf330130bb3527057da015e3c4a6fa295d7262e))
35
63
 
64
+ ## [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)
36
65
 
66
+ ### Bug Fixes
37
67
 
68
+ - make sure we're not throwing a generic 'No locales specified' when there is a generic error
69
+ ([fd3dd23](https://github.com/ho-nl/m2-pwa/commit/fd3dd233fb293f6afc08636316a34d2a2db4bbc3))
38
70
 
39
71
  # [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
72
 
41
-
42
73
  ### Bug Fixes
43
74
 
44
- * error in cli about missing plurals ([fedde70](https://github.com/ho-nl/m2-pwa/commit/fedde70012b0b5694114a0f5c3ab0f7d5c8cd276))
45
-
75
+ - error in cli about missing plurals
76
+ ([fedde70](https://github.com/ho-nl/m2-pwa/commit/fedde70012b0b5694114a0f5c3ab0f7d5c8cd276))
46
77
 
47
78
  ### Features
48
79
 
49
- * added tons of translations ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
50
-
51
-
52
-
53
-
80
+ - added tons of translations
81
+ ([9bb0ac7](https://github.com/ho-nl/m2-pwa/commit/9bb0ac709b58df6ea6141e92e4923a5ca9ae2963))
54
82
 
55
83
  # 1.1.0 (2021-11-11)
56
84
 
57
-
58
85
  ### Features
59
86
 
60
- * lingui configuration and integration greatly simplified and fixed ssr ([d8ec22a](https://github.com/ho-nl/m2-pwa/commit/d8ec22a80295af854a4cf6f357c4fb137c5b550d))
87
+ - lingui configuration and integration greatly simplified and fixed ssr
88
+ ([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/config.js CHANGED
@@ -20,7 +20,19 @@ function linguiNextConfig(config) {
20
20
  exclude: ['**/node_modules/!(@graphcommerce)/**'],
21
21
  },
22
22
  ],
23
- extractors: [require.resolve('@lingui/cli/api/extractors/typescript')],
23
+ extractBabelOptions: {
24
+ presets: [
25
+ [
26
+ 'next/babel',
27
+ {
28
+ 'preset-react': {
29
+ runtime: 'automatic',
30
+ importSource: '@emotion/react',
31
+ },
32
+ },
33
+ ],
34
+ ],
35
+ },
24
36
  sourceLocale: 'en',
25
37
  ...otherConfig,
26
38
  }
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,13 @@
1
1
  {
2
2
  "name": "@graphcommerce/lingui-next",
3
- "version": "1.3.1",
3
+ "homepage": "https://www.graphcommerce.org/",
4
+ "repository": "github:graphcommerce-org/graphcommerce",
5
+ "version": "2.1.0",
4
6
  "sideEffects": false,
5
7
  "scripts": {
6
8
  "dev": "tsc -W"
7
9
  },
8
10
  "prettier": "@graphcommerce/prettier-config-pwa",
9
- "browserslist": [
10
- "extends @graphcommerce/browserslist-config-pwa"
11
- ],
12
11
  "eslintConfig": {
13
12
  "extends": "@graphcommerce/eslint-config-pwa",
14
13
  "parserOptions": {
@@ -16,21 +15,20 @@
16
15
  }
17
16
  },
18
17
  "dependencies": {
19
- "@lingui/core": "^3.13.0",
20
- "@lingui/macro": "^3.13.0",
21
- "@lingui/react": "^3.13.0"
18
+ "@lingui/core": "^3.13.2",
19
+ "@lingui/macro": "^3.13.2",
20
+ "@lingui/react": "^3.13.2",
21
+ "babel-plugin-macros": "^3.1.0"
22
22
  },
23
23
  "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"
24
+ "@graphcommerce/eslint-config-pwa": "^4.0.2",
25
+ "@graphcommerce/prettier-config-pwa": "^4.0.1",
26
+ "@graphcommerce/typescript-config-pwa": "^4.0.1",
27
+ "@playwright/test": "^1.19.1"
29
28
  },
30
29
  "peerDependencies": {
31
- "next": "^12.0.7",
30
+ "next": "^12.0.10",
32
31
  "react": "^17.0.2",
33
32
  "react-dom": "^17.0.2"
34
- },
35
- "gitHead": "dce525a80fd42cebe9af0b207c3bd27f89be9543"
33
+ }
36
34
  }
@@ -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
- }