Skip to content

Commit

Permalink
fix(i18n): language code
Browse files Browse the repository at this point in the history
  • Loading branch information
syfxlin committed Jan 7, 2024
1 parent d40d786 commit b5d5dc6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#COLINE_ANALYZE=true
NEXT_PUBLIC_COLINE_LANGUAGE=zh_Hans
NEXT_PUBLIC_COLINE_LANGUAGE=zh-Hans
NEXT_PUBLIC_COLINE_GOOGLE_ANALYTICS=G-xxxxxxxxxx
NEXT_PUBLIC_COLINE_ARTALK_SITE_NAME=Blog
NEXT_PUBLIC_COLINE_ARTALK_SERVER_URL=https://artalk.example.com
Expand Down
2 changes: 1 addition & 1 deletion src/env/public.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// public
export const IS_DEV = process.env.NODE_ENV === "development" || process.env.NODE_ENV === "test";
export const COLINE_LANGUAGE = process.env.NEXT_PUBLIC_COLINE_LANGUAGE || "zh_Hans";
export const COLINE_LANGUAGE = process.env.NEXT_PUBLIC_COLINE_LANGUAGE || "zh-Hans";
export const COLINE_GITHUB_REPO = process.env.NEXT_PUBLIC_COLINE_GITHUB_REPO;
export const COLINE_GOOGLE_ANALYTICS = process.env.NEXT_PUBLIC_COLINE_GOOGLE_ANALYTICS;
export const COLINE_ARTALK_SITE_NAME = process.env.NEXT_PUBLIC_COLINE_ARTALK_SITE_NAME;
Expand Down
2 changes: 1 addition & 1 deletion src/locales/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import zhHant from "./zh-hant";
import { COLINE_LANGUAGE } from "../env/public";

export const t = (key: keyof typeof en, ...params: any[]) => {
const dictionaries = { en: en, zh_Hans: zhHans, zh_Hant: zhHant }[COLINE_LANGUAGE] ?? zhHans;
const dictionaries = { en: en, "zh-Hans": zhHans, "zh-Hant": zhHant }[COLINE_LANGUAGE] ?? zhHans;
// @ts-ignore
return (dictionaries[key] ?? key).replace(/\{(\d+)}/g, (a, i) => params[parseInt(i)] ?? a);
};

0 comments on commit b5d5dc6

Please sign in to comment.