Skip to content

Commit

Permalink
fix: langdict import
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Sep 24, 2023
1 parent 4fe8427 commit 6c31398
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 11 additions & 3 deletions src/locale/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { readdirSync } from "fs";
import en from "./en.json";
import zhCN from "./zh-CN.json";
import zhTW from "./zh-TW.json";

export const langList = readdirSync(`${__dirname}`).filter(fileName => fileName.endsWith(".json")).map(fileName => fileName.replace(".json", ""));
export const langList = ["en", "zh-CN", "zh-TW"];

export type langDict = {
runnning: string,
Expand All @@ -19,5 +21,11 @@ export type langDict = {
export async function getLangDict(language: string): Promise<langDict>
{
if(!langList.includes(language)) throw new Error(`Illegal language ${language}, the allowed languages are ${langList}`);
return import(`./${language}.json`);
switch (language)
{
case "en": return en;
case "zh-CN": return zhCN;
case "zh-TW": return zhTW;
default: return en;
}
}
3 changes: 1 addition & 2 deletions vercel.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"functions": {
"api/index.ts": {
"maxDuration": 10,
"includeFiles": "src/locale/*.json"
"maxDuration": 10
}
},
"rewrites": [
Expand Down

0 comments on commit 6c31398

Please sign in to comment.