Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(frontend): rsc i18n #2

Merged
merged 5 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/frontend-lint.yml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions frontend/src/app/[lang]/appRouterI18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!]
}
14 changes: 7 additions & 7 deletions frontend/src/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 7 additions & 1 deletion frontend/src/app/[lang]/page.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<Link href="/about" bg="#000" color="white" locale="en">
{t(i18n)`Test`}
/About
</Link>
)
Expand Down
22 changes: 0 additions & 22 deletions frontend/src/app/layout.tsx

This file was deleted.

4 changes: 4 additions & 0 deletions frontend/src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ msgstr ""
"Last-Translator: \n"
"Language-Team: \n"
"Plural-Forms: \n"

#: src/app/[lang]/page.tsx:11
msgid "Test"
msgstr "Test"
4 changes: 4 additions & 0 deletions frontend/src/locales/zh-cn/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ msgstr ""
"Last-Translator: \n"
"Language-Team: \n"
"Plural-Forms: \n"

#: src/app/[lang]/page.tsx:11
msgid "Test"
msgstr "测试"
4 changes: 4 additions & 0 deletions frontend/src/locales/zh-tw/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ msgstr ""
"Last-Translator: \n"
"Language-Team: \n"
"Plural-Forms: \n"

#: src/app/[lang]/page.tsx:11
msgid "Test"
msgstr "測試"
6 changes: 2 additions & 4 deletions frontend/src/middleware.ts
Original file line number Diff line number Diff line change
@@ -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)$).*)'],
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions frontend/src/types/BaseAppRouterProps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { PropsWithChildren } from 'react'

export interface BaseAppRouterProps extends PropsWithChildren {
params: {
lang: string
}
}
Loading