Skip to content

Commit

Permalink
feat(frontend): rsc i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
Vibes-INS committed Jul 12, 2024
1 parent 1260ed7 commit ba8272a
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 37 deletions.
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 { 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
}
}

0 comments on commit ba8272a

Please sign in to comment.