diff --git a/.github/workflows/frontend-lint.yml b/.github/workflows/frontend-lint.yml new file mode 100644 index 00000000..1546fa4f --- /dev/null +++ b/.github/workflows/frontend-lint.yml @@ -0,0 +1,26 @@ +name: Frontend Linter + +on: [pull_request, push] + + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: 'true' + + - uses: actions/setup-node@v2 + with: + node-version: '20' + + - uses: pnpm/action-setup@v4 + - name: Install dependency + run: pnpm install + + - name: Run Lint + run: npm run lint + working-directory: frontend 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..f6926e29 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 type { 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 + } +}