generated from yunsii/lingui-examples-nextjs-swc-1793
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.page.tsx
96 lines (86 loc) · 2.62 KB
/
index.page.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { Plural, t, Trans } from '@lingui/macro'
import path from 'path'
import { GetStaticProps, NextPage } from 'next'
import Head from 'next/head'
import { AboutText } from '../components/AboutText'
import Developers from '../components/Developers'
import { Switcher } from '../components/Switcher'
import styles from '../styles/Index.module.css'
import { loadCatalog } from '../utils'
import { useLingui } from '@lingui/react'
import { curringFoo } from '../helpers/currying'
export const getStaticProps: GetStaticProps = async (ctx) => {
const fileName = __filename
const cwd = process.cwd()
const { locale } = ctx
const pathname = path
.relative(cwd, fileName)
.replace('.next/server/pages/', '')
.replace('.js', '')
const translation = await loadCatalog(locale || 'en', pathname)
return {
props: {
translation
}
}
}
const Index: NextPage = () => {
/**
* This hook is needed to subscribe your
* component for changes if you use t`` macro
*/
useLingui()
const result = curringFoo()()
console.log('curringFoo', result)
return (
<div className={styles.container}>
<Head>
{/*
The Next Head component is not being rendered in the React
component tree and React Context is not being passed down to the components placed in the <Head>.
That means we cannot use the <Trans> component here and instead have to use `t` macro.
*/}
<title>{t`Translation Demo`}</title>
<link rel="icon" href="/favicon.ico" />
</Head>
<main className={styles.main}>
<Switcher />
<h1 className={styles.title}>
<Trans>
Welcome to <a href="https://nextjs.org">Next.js!</a>
</Trans>
</h1>
<h2>
<Trans>Plain text</Trans>
</h2>
<h2>{t`Plain text`}</h2>
<h2>
<Trans>
<a href="https://nextjs.org">Next.js</a> say hi.
</Trans>
</h2>
<h2>
<Trans>
Wonderful framework <a href="https://nextjs.org">Next.js</a> say hi.
</Trans>
</h2>
<h2>
<Trans>
Wonderful framework <a href="https://nextjs.org">Next.js</a> say hi.
And <a href="https://nextjs.org">Next.js</a> say hi.
</Trans>
</h2>
<div className={styles.description}>
<AboutText />
</div>
<Developers />
<div>
<Plural value={1} one={'# Person'} other={`# Persons`} />
<br />
<Plural value={2} one={'# Person'} other={`# Persons`} />
</div>
</main>
</div>
)
}
export default Index