Skip to content

Commit

Permalink
Merge pull request #32 from hamster1963/default_locale
Browse files Browse the repository at this point in the history
feat: add DefaultLocale config
  • Loading branch information
hamster1963 authored Sep 29, 2024
2 parents b3f8e8c + 9d02f35 commit c2fd0ab
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NezhaBaseUrl=http://124.XX.XX.XX:8008
NezhaAuth=your-nezha-api-token
DefaultLocale=zh
NEXT_PUBLIC_NezhaFetchInterval=5000
NEXT_PUBLIC_ShowFlag=true
NEXT_PUBLIC_DisableCartoon=true
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@

#### 环境变量

| 变量名 | 含义 | 示例 |
| ------------------------------ | -------------------- | -------------------------------- |
| NezhaBaseUrl | nezha 面板地址 | http://120.x.x.x:8008 |
| NezhaAuth | nezha 面板 API Token | 5hAY3QX6Nl9B3Uxxxx26KMvOMyXS1Udi |
| NEXT_PUBLIC_NezhaFetchInterval | 获取数据间隔(毫秒) | **默认**:2000 |
| NEXT_PUBLIC_ShowFlag | 是否显示旗帜 | **默认**:false |
| NEXT_PUBLIC_DisableCartoon | 是否禁用卡通人物 | **默认**:false |
| 变量名 | 含义 | 示例 |
| ------------------------------ | -------------------------------- | -------------------------------- |
| NezhaBaseUrl | nezha 面板地址 | http://120.x.x.x:8008 |
| NezhaAuth | nezha 面板 API Token | 5hAY3QX6Nl9B3Uxxxx26KMvOMyXS1Udi |
| DefaultLocale | 面板默认显示语言(代码参考下表) | **默认**:en |
| NEXT_PUBLIC_NezhaFetchInterval | 获取数据间隔(毫秒) | **默认**:2000 |
| NEXT_PUBLIC_ShowFlag | 是否显示旗帜 | **默认**:false |
| NEXT_PUBLIC_DisableCartoon | 是否禁用卡通人物 | **默认**:false |

#### 多语言支持

Expand Down
1 change: 1 addition & 0 deletions docker/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
NezhaBaseUrl=http://124.XX.XX.XX:8008
NezhaAuth=your-nezha-api-token
DefaultLocale=zh
NEXT_PUBLIC_NezhaFetchInterval=5000
NEXT_PUBLIC_ShowFlag=true
NEXT_PUBLIC_DisableCartoon=true
4 changes: 3 additions & 1 deletion i18n-metadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// @auto-i18n-check. Please do not delete the line.

import getEnv from "./lib/env-entry";

export const localeItems = [
{ code: "en", name: "English" },
{ code: "ja", name: "日本語" },
Expand All @@ -21,4 +23,4 @@ export const localeItems = [
];

export const locales = localeItems.map((item) => item.code);
export const defaultLocale = "en";
export const defaultLocale = getEnv("DefaultLocale") || "en";
4 changes: 2 additions & 2 deletions middleware.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// @auto-i18n-check. Please do not delete the line.

import createMiddleware from "next-intl/middleware";
import { locales } from "./i18n-metadata";
import { defaultLocale, locales } from "./i18n-metadata";

export default createMiddleware({
// A list of all locales that are supported
locales: locales,

// Used when no locale matches
defaultLocale: "en",
defaultLocale: defaultLocale,

// 'always': This is the default, The home page will also be redirected to the default language, such as www.abc.com to www.abc.com/en
// 'as-needed': The default page is not redirected. For example, if you open www.abc.com, it is still www.abc.com
Expand Down

0 comments on commit c2fd0ab

Please sign in to comment.