From ba8272acf1d2da00bde14e83063163a36b39b5e1 Mon Sep 17 00:00:00 2001 From: INS Date: Fri, 12 Jul 2024 10:24:33 +0800 Subject: [PATCH 1/5] feat(frontend): rsc i18n --- frontend/src/app/[lang]/appRouterI18n.ts | 5 ++--- frontend/src/app/[lang]/layout.tsx | 14 +++++++------- frontend/src/app/[lang]/page.tsx | 8 +++++++- frontend/src/app/layout.tsx | 22 ---------------------- frontend/src/locales/en/messages.po | 4 ++++ frontend/src/locales/zh-cn/messages.po | 4 ++++ frontend/src/locales/zh-tw/messages.po | 4 ++++ frontend/src/middleware.ts | 6 ++---- frontend/src/{app => styles}/globals.css | 0 frontend/src/types/BaseAppRouterProps.ts | 7 +++++++ 10 files changed, 37 insertions(+), 37 deletions(-) delete mode 100644 frontend/src/app/layout.tsx rename frontend/src/{app => styles}/globals.css (100%) create mode 100644 frontend/src/types/BaseAppRouterProps.ts diff --git a/frontend/src/app/[lang]/appRouterI18n.ts b/frontend/src/app/[lang]/appRouterI18n.ts index a33a2b22..8353a848 100644 --- a/frontend/src/app/[lang]/appRouterI18n.ts +++ b/frontend/src/app/[lang]/appRouterI18n.ts @@ -2,8 +2,7 @@ import 'server-only' import type { LinguiConfig } from '@lingui/conf' import { I18n, Messages, setupI18n } from '@lingui/core' - -import linguiConfig from '../../../lingui.config.mjs' +import linguiConfig from 'lingui.config.mjs' const { locales } = linguiConfig as LinguiConfig type SupportedLocales = string @@ -34,5 +33,5 @@ export const allI18nInstances: AllI18nInstances = locales.reduce((acc, locale) = }, {}) export function getI18nInstance(locale: string) { - return allI18nInstances[locale] + return allI18nInstances[locale] ?? allI18nInstances[linguiConfig.sourceLocale!] } diff --git a/frontend/src/app/[lang]/layout.tsx b/frontend/src/app/[lang]/layout.tsx index e66e5a06..b3615bef 100644 --- a/frontend/src/app/[lang]/layout.tsx +++ b/frontend/src/app/[lang]/layout.tsx @@ -1,17 +1,17 @@ +import '@/styles/globals.css' + import { setI18n } from '@lingui/react/server' -import { ReactNode } from 'react' +import type { Metadata } from 'next' import { getI18nInstance } from '@/app/[lang]/appRouterI18n' import { LinguiClientProvider } from '@/app/[lang]/LinguiClientProvider' +import { BaseAppRouterProps } from '@/types/BaseAppRouterProps' -interface Props { - params: { - lang: string - } - children: ReactNode +export const metadata: Metadata = { + title: 'UTXO Stack Explorer', } -export default function RootLayout({ params: { lang }, children }: Props) { +export default function RootLayout({ params: { lang }, children }: BaseAppRouterProps) { const i18n = getI18nInstance(lang) setI18n(i18n) diff --git a/frontend/src/app/[lang]/page.tsx b/frontend/src/app/[lang]/page.tsx index ad11603d..f842ff9f 100644 --- a/frontend/src/app/[lang]/page.tsx +++ b/frontend/src/app/[lang]/page.tsx @@ -1,8 +1,14 @@ +import { t } from '@lingui/macro' + +import { getI18nInstance } from '@/app/[lang]/appRouterI18n' import { Link } from '@/components/ui/link' +import { BaseAppRouterProps } from '@/types/BaseAppRouterProps' -export default function Home() { +export default function Home({ params: { lang } }: BaseAppRouterProps) { + const i18n = getI18nInstance(lang) return ( + {t(i18n)`Test`} /About ) diff --git a/frontend/src/app/layout.tsx b/frontend/src/app/layout.tsx deleted file mode 100644 index d5ad7940..00000000 --- a/frontend/src/app/layout.tsx +++ /dev/null @@ -1,22 +0,0 @@ -import '@/app/globals.css' - -import type { Metadata } from 'next' -import { Inter } from 'next/font/google' - -const inter = Inter({ subsets: ['latin'] }) - -export const metadata: Metadata = { - title: 'UTXO Stack Explorer', -} - -export default function RootLayout({ - children, -}: Readonly<{ - children: React.ReactNode -}>) { - return ( - - {children} - - ) -} diff --git a/frontend/src/locales/en/messages.po b/frontend/src/locales/en/messages.po index 1a32a931..f817aa2b 100644 --- a/frontend/src/locales/en/messages.po +++ b/frontend/src/locales/en/messages.po @@ -12,3 +12,7 @@ msgstr "" "Last-Translator: \n" "Language-Team: \n" "Plural-Forms: \n" + +#: src/app/[lang]/page.tsx:11 +msgid "Test" +msgstr "Test" diff --git a/frontend/src/locales/zh-cn/messages.po b/frontend/src/locales/zh-cn/messages.po index b9816859..0bb6c01b 100644 --- a/frontend/src/locales/zh-cn/messages.po +++ b/frontend/src/locales/zh-cn/messages.po @@ -12,3 +12,7 @@ msgstr "" "Last-Translator: \n" "Language-Team: \n" "Plural-Forms: \n" + +#: src/app/[lang]/page.tsx:11 +msgid "Test" +msgstr "测试" diff --git a/frontend/src/locales/zh-tw/messages.po b/frontend/src/locales/zh-tw/messages.po index 1dd2d1a0..df43e075 100644 --- a/frontend/src/locales/zh-tw/messages.po +++ b/frontend/src/locales/zh-tw/messages.po @@ -12,3 +12,7 @@ msgstr "" "Last-Translator: \n" "Language-Team: \n" "Plural-Forms: \n" + +#: src/app/[lang]/page.tsx:11 +msgid "Test" +msgstr "測試" diff --git a/frontend/src/middleware.ts b/frontend/src/middleware.ts index 3c72e834..4f88a5da 100644 --- a/frontend/src/middleware.ts +++ b/frontend/src/middleware.ts @@ -1,10 +1,8 @@ -import type { LinguiConfig } from '@lingui/conf' +import linguiConfig from 'lingui.config.mjs' import Negotiator from 'negotiator' import { type NextRequest, NextResponse } from 'next/server' -import linguiConfig from '../lingui.config.mjs' - -const { locales } = linguiConfig as LinguiConfig +const { locales } = linguiConfig export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)'], diff --git a/frontend/src/app/globals.css b/frontend/src/styles/globals.css similarity index 100% rename from frontend/src/app/globals.css rename to frontend/src/styles/globals.css diff --git a/frontend/src/types/BaseAppRouterProps.ts b/frontend/src/types/BaseAppRouterProps.ts new file mode 100644 index 00000000..d84ccccb --- /dev/null +++ b/frontend/src/types/BaseAppRouterProps.ts @@ -0,0 +1,7 @@ +import type { PropsWithChildren } from 'react' + +export interface BaseAppRouterProps extends PropsWithChildren { + params: { + lang: string + } +} From a5c8fb1309fc2e407a11ab8d0fe7b82b9d0e2384 Mon Sep 17 00:00:00 2001 From: INS Date: Fri, 12 Jul 2024 10:28:19 +0800 Subject: [PATCH 2/5] chore(frontend): add lint --- .github/workflows/frontend-lint.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/workflows/frontend-lint.yml diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml new file mode 100644 index 00000000..8eee9c3c --- /dev/null +++ b/.github/workflows/frontend-lint.yml @@ -0,0 +1,26 @@ +name: Linter + +on: [pull_request, push] + + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + submodules: 'true' + + - uses: actions/checkout@v2 + - uses: actions/setup-node@v2 + with: + node-version: '20' + + - uses: pnpm/action-setup@v4 + - name: Install dependency + run: pnpm install + + - name: Build + run: npm run lint From f75eea424c5c83a446f0231740bb22c376ce40d4 Mon Sep 17 00:00:00 2001 From: INS Date: Fri, 12 Jul 2024 10:29:48 +0800 Subject: [PATCH 3/5] chore(frontend): add lint --- .github/workflows/frontend-lint.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml index 8eee9c3c..7863ed44 100644 --- a/.github/workflows/frontend-lint.yml +++ b/.github/workflows/frontend-lint.yml @@ -22,5 +22,6 @@ jobs: - name: Install dependency run: pnpm install - - name: Build + - name: Run Lint run: npm run lint + working-directory: frontend From 5020fb3e02c8df108e2b2afac0931361d5ad0406 Mon Sep 17 00:00:00 2001 From: INS Date: Fri, 12 Jul 2024 10:36:32 +0800 Subject: [PATCH 4/5] chore(frontend): lint name --- .github/workflows/frontend-lint.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml index 7863ed44..62954cce 100644 --- a/.github/workflows/frontend-lint.yml +++ b/.github/workflows/frontend-lint.yml @@ -1,4 +1,4 @@ -name: Linter +name: Frontend Linter on: [pull_request, push] From c3a3c1098a8aeb2402639dd5ca38af0628d8c23e Mon Sep 17 00:00:00 2001 From: INS Date: Mon, 15 Jul 2024 08:42:01 +0800 Subject: [PATCH 5/5] chore(frontend): fix lint --- .github/workflows/frontend-lint.yml | 3 +-- frontend/src/app/[lang]/page.tsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml index 62954cce..1546fa4f 100644 --- a/.github/workflows/frontend-lint.yml +++ b/.github/workflows/frontend-lint.yml @@ -9,11 +9,10 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: submodules: 'true' - - uses: actions/checkout@v2 - uses: actions/setup-node@v2 with: node-version: '20' diff --git a/frontend/src/app/[lang]/page.tsx b/frontend/src/app/[lang]/page.tsx index f842ff9f..f6926e29 100644 --- a/frontend/src/app/[lang]/page.tsx +++ b/frontend/src/app/[lang]/page.tsx @@ -2,7 +2,7 @@ import { t } from '@lingui/macro' import { getI18nInstance } from '@/app/[lang]/appRouterI18n' import { Link } from '@/components/ui/link' -import { BaseAppRouterProps } from '@/types/BaseAppRouterProps' +import type { BaseAppRouterProps } from '@/types/BaseAppRouterProps' export default function Home({ params: { lang } }: BaseAppRouterProps) { const i18n = getI18nInstance(lang)