-
-
Notifications
You must be signed in to change notification settings - Fork 10k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat(i18n): Add i18next and lobe-i18n internationalization configur…
…ation files and update dependencies This commit introduces new configuration files for internationalization, deletes one file, modifies existing files, and adds new files. The changes also involve importing dependencies and updating app and document pages. Additional libraries and modules are used in a React application. The Header component is modified, the index page is updated for server-side translations, and the tsconfig.json file is modified. Description: - Added configuration files for internationalization - Deleted one file - Modified existing files - Added new files - Imported dependencies - Updated app and document pages - Used additional libraries and modules in a React application - Modified the Header component - Updated the index page for server-side translations - Modified the tsconfig.json file.
- Loading branch information
1 parent
4e522a6
commit 53cd87c
Showing
19 changed files
with
181 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const { description } = require('./package.json'); | ||
|
||
module.exports = { | ||
reference: description, | ||
entry: 'public/locales/zh_CN', | ||
entryLocale: 'zh_CN', | ||
output: 'public/locales', | ||
outputLocales: ['zh_HK', 'en_US', 'ja_JP', 'ko_KR'], | ||
splitToken: 2500, | ||
temperature: 0, | ||
modelName: 'gpt-3.5-turbo', | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const i18n = require('./.i18nrc'); | ||
|
||
/** @type {import('next-i18next').UserConfig} */ | ||
module.exports = { | ||
debug: process.env.NODE_ENV === 'development', | ||
i18n: { | ||
defaultLocale: i18n.entryLocale, | ||
locales: [i18n.entryLocale, i18n.outputLocales], | ||
}, | ||
localePath: | ||
typeof window === 'undefined' ? require('node:path').resolve('./', i18n.output) : '/locales', | ||
reloadOnPrerender: process.env.NODE_ENV === 'development', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const pc = require('picocolors'); | ||
|
||
const nextUtilsConfig = () => { | ||
const trueEnv = ['true', '1', 'yes']; | ||
const esmExternals = trueEnv.includes(process.env?.NEXTJS_ESM_EXTERNALS ?? 'false'); | ||
const tsconfigPath = process.env.NEXTJS_TSCONFIG_PATH | ||
? process.env.NEXTJS_TSCONFIG_PATH | ||
: './tsconfig.json'; | ||
|
||
// eslint-disable-next-line no-console | ||
console.warn( | ||
`${pc.green('warn -')} experimental.esmExternals is ${esmExternals ? 'enabled' : 'disabled'}`, | ||
); | ||
return { | ||
esmExternals, | ||
tsconfigPath, | ||
}; | ||
}; | ||
|
||
module.exports = { | ||
loadCustomBuildParams: nextUtilsConfig, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setting": "Setting", | ||
"share": "Share" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setting": "設定", | ||
"share": "共有する" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setting": "설정", | ||
"share": "공유" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setting": "设置", | ||
"share": "分享" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"setting": "設置", | ||
"share": "分享" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import type { Namespace } from 'i18next'; | ||
import type { SSRConfig, UserConfig } from 'next-i18next'; | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; | ||
|
||
import nextI18nextConfig from '@/../next-i18next.config'; | ||
|
||
type ArrayElementOrSelf<T> = T extends Array<infer U> ? U[] : T[]; | ||
|
||
export const getServerTranslations = async ( | ||
locale: string, | ||
namespacesRequired?: ArrayElementOrSelf<Namespace> | undefined, | ||
configOverride?: UserConfig, | ||
extraLocales?: string[] | false, | ||
): Promise<SSRConfig> => { | ||
const config = configOverride ?? nextI18nextConfig; | ||
// @ts-ignore | ||
return serverSideTranslations(locale, namespacesRequired, config, extraLocales); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import { Analytics } from '@vercel/analytics/react'; | ||
import { appWithTranslation } from 'next-i18next'; | ||
import type { AppProps } from 'next/app'; | ||
import { Suspense } from 'react'; | ||
|
||
import Layout from '@/layout'; | ||
|
||
function MyApp({ Component, pageProps }: AppProps) { | ||
return ( | ||
<Layout> | ||
<Component {...pageProps} /> | ||
<Analytics /> | ||
</Layout> | ||
<Suspense fallback="loading"> | ||
<Layout> | ||
<Component {...pageProps} /> | ||
<Analytics /> | ||
</Layout> | ||
</Suspense> | ||
); | ||
} | ||
|
||
export default MyApp; | ||
export default appWithTranslation(MyApp); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
export { default } from './chat/index.page'; | ||
import type { GetStaticProps, InferGetStaticPropsType } from 'next'; | ||
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'; | ||
|
||
import Chat from './chat/index.page'; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const Index = (_props: InferGetStaticPropsType<typeof getStaticProps>) => { | ||
return <Chat />; | ||
}; | ||
|
||
export const getStaticProps: GetStaticProps = async ({ locale }) => ({ | ||
props: { | ||
...(await serverSideTranslations(locale ?? 'zh_CN', ['common'])), | ||
}, | ||
}); | ||
|
||
export default Index; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import resources from '@/types/resources'; | ||
|
||
declare module 'i18next' { | ||
interface CustomTypeOptions { | ||
defaultNS: 'common'; | ||
resources: typeof resources; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import common from '@/../public/locales/zh_CN/common.json'; | ||
|
||
const resources = { | ||
common, | ||
} as const; | ||
|
||
export default resources; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters