Skip to content

Commit f4560f4

Browse files
committed
Get minimal application running
1 parent 375453f commit f4560f4

File tree

16 files changed

+9523
-5508
lines changed

16 files changed

+9523
-5508
lines changed

lingui.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const nextConfig = require('./next.config')
22

3+
console.log('nextConfig', nextConfig)
4+
35
/** @type {import('@lingui/conf').LinguiConfig} */
46
module.exports = {
57
locales: nextConfig.i18n.locales,
@@ -10,7 +12,8 @@ module.exports = {
1012
},
1113
catalogs: [
1214
{
13-
path: 'src/locales/{locale}',
15+
path: 'src/locales/{locale}/messages',
16+
// path: 'src/locales/{locale}',
1417
include: ['src/'],
1518
},
1619
],

next.config.mjs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,10 @@ export default withMDX({
1818
images: {
1919
domains: ["raw.githubusercontent.com", "numpy.org", "dask.org", "chainer.org", ],
2020
},
21-
})
22-
23-
/** @type {import('next').NextConfig} */
24-
module.exports = {
2521
i18n: {
2622
// These are all the locales you want to support in
2723
// your application
28-
locales: ["en", "es"],
24+
locales: ["en", "es", "pt"],
2925
defaultLocale: "en",
3026
},
31-
}
27+
})

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"scripts": {
66
"build-cards": "node build-cards.js",
77
"extract": "lingui extract",
8+
"compile": "lingui compile",
89
"dev": "next dev",
910
"build": "yarn extract && next build",
1011
"start": "next start",

src/components/layout.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { Header } from '@/components/header'
44
import { Link } from '@/components/mdx'
55
import { Box, Flex } from '@chakra-ui/react'
66
import Head from 'next/head'
7+
import { Trans, useLingui } from '@lingui/react/macro'
8+
import { useRouter } from 'next/router'
79

810
export const Layout = ({
911
title,
@@ -13,7 +15,15 @@ export const Layout = ({
1315
url = 'https://xarray.dev',
1416
enableBanner = false,
1517
}) => {
16-
const bannerTitle = 'Check out the new blog post on DataTree!'
18+
/**
19+
* This macro hook is needed to get `t` which
20+
* is bound to i18n from React.Context
21+
*/
22+
const { t } = useLingui()
23+
const router = useRouter()
24+
const { pathname, asPath, query } = router
25+
26+
const bannerTitle = t`Check out the new blog post on DataTree!`
1727
const bannerDescription = ''
1828
const bannerChildren = (
1929
<Link href='/blog/datatree'>

src/en/messages.po

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
msgid ""
2+
msgstr ""
3+
"POT-Creation-Date: 2020-04-04 13:38+0200\n"
4+
"MIME-Version: 1.0\n"
5+
"Content-Type: text/plain; charset=utf-8\n"
6+
"Content-Transfer-Encoding: 8bit\n"
7+
"X-Generator: @lingui/cli\n"
8+
"Language: en\n"
9+
"Project-Id-Version: \n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"PO-Revision-Date: \n"
12+
"Last-Translator: \n"
13+
"Language-Team: \n"
14+
"Plural-Forms: \n"
15+
16+
#: src/pages/examples.tsx:36
17+
#: src/pages/examples.tsx:48
18+
msgid "{value, plural, one {There's one book} other {There are # books}}"
19+
msgstr "{value, plural, one {There's one book} other {There are # books}}"
20+
21+
#: src/pages/examples.tsx:18
22+
msgid "Black"
23+
msgstr "Black"
24+
25+
#: src/pages/index.tsx:50
26+
msgid "Checkout LinguiJS examples and usecases."
27+
msgstr "Checkout LinguiJS examples and usecases."
28+
29+
#: src/pages/examples.tsx:18
30+
msgid "Cyan"
31+
msgstr "Cyan"
32+
33+
#: src/pages/index.tsx:36
34+
msgid "Documentation →"
35+
msgstr "Documentation →"
36+
37+
#: src/components/Layout.tsx:23
38+
msgid "Example project using LinguiJS"
39+
msgstr "Example project using LinguiJS"
40+
41+
#: src/pages/examples.tsx:26
42+
msgid "Examples"
43+
msgstr "Examples"
44+
45+
#: src/pages/index.tsx:47
46+
msgid "Examples →"
47+
msgstr "Examples →"
48+
49+
#: src/pages/index.tsx:39
50+
msgid "Find in-depth information about LinguiJS features and API."
51+
msgstr "Find in-depth information about LinguiJS features and API."
52+
53+
#: pages/index.tsx:13
54+
#~ msgid "Get started by editing <0>locale/en/messages.po</0>"
55+
#~ msgstr "Get started by editing <0>locale/en/messages.po</0>"
56+
57+
#: src/pages/index.tsx:28
58+
msgid "Get started by editing <0>locales/en.po</0>"
59+
msgstr "Get started by editing <0>locales/en.po</0>"
60+
61+
#: src/pages/examples.tsx:18
62+
msgid "Magenta"
63+
msgstr "Magenta"
64+
65+
#: src/pages/examples.tsx:30
66+
msgid "Plurals"
67+
msgstr "Plurals"
68+
69+
#: src/components/Layout.tsx:41
70+
msgid "Powered by <0/>"
71+
msgstr "Powered by <0/>"
72+
73+
#: src/pages/examples.tsx:57
74+
msgid "Translation outside of React components"
75+
msgstr "Translation outside of React components"
76+
77+
#: src/pages/index.tsx:23
78+
msgid "Welcome to <0>LinguiJS!</0>"
79+
msgstr "Welcome to <0>LinguiJS!</0>"
80+
81+
#: src/pages/examples.tsx:18
82+
msgid "Yellow"
83+
msgstr "Yellow"

src/i18n.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { useEffect } from 'react'
88
* many ways how to load messages — from REST API, from file, from cache, etc.
99
*/
1010
export async function loadCatalog(locale: string) {
11-
const catalog = await import(`@lingui/loader!./locales/${locale}.po`)
11+
const catalog = await import(`@lingui/loader!./locales/${locale}/messages.po`)
1212
return catalog.messages
1313
}
1414

src/locales/en/messages.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/en/messages.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"POT-Creation-Date: 2025-05-01 08:03-0500\n"
4+
"MIME-Version: 1.0\n"
5+
"Content-Type: text/plain; charset=utf-8\n"
6+
"Content-Transfer-Encoding: 8bit\n"
7+
"X-Generator: @lingui/cli\n"
8+
"Language: en\n"
9+
"Project-Id-Version: \n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"PO-Revision-Date: \n"
12+
"Last-Translator: \n"
13+
"Language-Team: \n"
14+
"Plural-Forms: \n"
15+
16+
#: src/components/layout.js:26
17+
msgid "Check out the new blog post on DataTree!"
18+
msgstr "Check out the new blog post on DataTree!"

src/locales/es/messages.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/es/messages.mo

420 Bytes
Binary file not shown.

src/locales/es/messages.po

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
msgid ""
2+
msgstr ""
3+
"Project-Id-Version: \n"
4+
"Report-Msgid-Bugs-To: \n"
5+
"POT-Creation-Date: 2025-05-01 08:03-0500\n"
6+
"PO-Revision-Date: \n"
7+
"Last-Translator: \n"
8+
"Language-Team: \n"
9+
"Language: es\n"
10+
"MIME-Version: 1.0\n"
11+
"Content-Type: text/plain; charset=utf-8\n"
12+
"Content-Transfer-Encoding: 8bit\n"
13+
"Plural-Forms: \n"
14+
"X-Generator: Poedit 3.6\n"
15+
16+
#: src/components/layout.js:26
17+
msgid "Check out the new blog post on DataTree!"
18+
msgstr "¡Consulta la nueva publicación del blog sobre DataTree!"

src/locales/pt/messages.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/locales/pt/messages.po

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
msgid ""
2+
msgstr ""
3+
"POT-Creation-Date: 2025-05-01 08:04-0500\n"
4+
"MIME-Version: 1.0\n"
5+
"Content-Type: text/plain; charset=utf-8\n"
6+
"Content-Transfer-Encoding: 8bit\n"
7+
"X-Generator: @lingui/cli\n"
8+
"Language: pt\n"
9+
10+
#: src/components/layout.js:26
11+
msgid "Check out the new blog post on DataTree!"
12+
msgstr ""

src/pages/_app.js

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
import { I18nProvider } from '@lingui/react'
2+
import { i18n } from '@lingui/core'
3+
14
import * as gtag from '@/lib/ga'
25
import { customTheme } from '@/theme'
36
import { ChakraProvider } from '@chakra-ui/react'
47
import { useRouter } from 'next/router'
8+
import { useLinguiInit } from '../i18n'
59
import Script from 'next/script'
610
import { useEffect } from 'react'
711

812
function MyApp({ Component, pageProps }) {
13+
useLinguiInit(pageProps.translation)
914
const router = useRouter()
1015
useEffect(() => {
1116
const handleRouteChange = (url) => {
@@ -20,29 +25,32 @@ function MyApp({ Component, pageProps }) {
2025
}, [router.events])
2126

2227
return (
23-
<ChakraProvider resetCSS theme={customTheme}>
24-
{/* Google Tag Manager - Global base code */}
25-
<Script
26-
strategy='afterInteractive'
27-
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
28-
/>
29-
<Script
30-
id='gtag-init'
31-
strategy='afterInteractive'
32-
dangerouslySetInnerHTML={{
33-
__html: `
34-
window.dataLayer = window.dataLayer || [];
35-
function gtag(){dataLayer.push(arguments);}
36-
gtag('js', new Date());
37-
gtag('config', '${gtag.GA_TRACKING_ID}', {
38-
page_path: window.location.pathname,
39-
});
40-
`,
41-
}}
42-
/>
43-
44-
<Component {...pageProps} />
45-
</ChakraProvider>
28+
<>
29+
<I18nProvider i18n={i18n}>
30+
<ChakraProvider resetCSS theme={customTheme}>
31+
{/* Google Tag Manager - Global base code */}
32+
<Script
33+
strategy='afterInteractive'
34+
src={`https://www.googletagmanager.com/gtag/js?id=${gtag.GA_TRACKING_ID}`}
35+
/>
36+
<Script
37+
id='gtag-init'
38+
strategy='afterInteractive'
39+
dangerouslySetInnerHTML={{
40+
__html: `
41+
window.dataLayer = window.dataLayer || [];
42+
function gtag(){dataLayer.push(arguments);}
43+
gtag('js', new Date());
44+
gtag('config', '${gtag.GA_TRACKING_ID}', {
45+
page_path: window.location.pathname,
46+
});
47+
`,
48+
}}
49+
/>
50+
<Component {...pageProps} />
51+
</ChakraProvider>
52+
</I18nProvider>
53+
</>
4654
)
4755
}
4856

src/pages/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,22 @@ import {
77
Sponsors,
88
} from '@/components'
99

10+
import { useLingui } from '@lingui/react/macro'
11+
1012
import { Layout } from '@/components/layout'
1113

14+
import { loadCatalog } from '../i18n'
15+
16+
export const getStaticProps = async (ctx) => {
17+
const translation = await loadCatalog(ctx.locale)
18+
return {
19+
props: {
20+
translation,
21+
},
22+
}
23+
}
1224
export default function IndexPage() {
25+
const { t } = useLingui()
1326
return (
1427
<Layout
1528
url={`/`}

0 commit comments

Comments
 (0)