forked from fatwang2/search4all
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request fatwang2#12 from 6drf21e/feature/add-multilingual-…
…support
- Loading branch information
Showing
13 changed files
with
210 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
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
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
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,36 @@ | ||
const cn = { | ||
Err: { | ||
429: "请求过于频繁,请稍后再试", | ||
500: "抱歉,我们可能负载过重,请稍后再试。", | ||
}, | ||
Title: { | ||
rewrite: "重写", | ||
}, | ||
Search: { | ||
placeholder: "有问必答...", | ||
}, | ||
Footer: { | ||
statement: "这是由大语言模型提供的答案, 请务必核实正确性。", | ||
}, | ||
Relates: { | ||
no_related_questions: "没有相关问题。", | ||
related: "相关", | ||
}, | ||
Answer: { | ||
answer: "答案", | ||
}, | ||
Sources: { | ||
sources: "来源", | ||
}, | ||
}; | ||
|
||
type DeepPartial<T> = T extends object | ||
? { | ||
[P in keyof T]?: DeepPartial<T[P]>; | ||
} | ||
: T; | ||
|
||
export type LocaleType = typeof cn; | ||
export type PartialLocaleType = DeepPartial<typeof cn>; | ||
|
||
export default cn; |
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,30 @@ | ||
import { LocaleType } from "./index"; | ||
|
||
const en: LocaleType = { | ||
Err: { | ||
429: "Sorry, you have made too many requests recently, try again later.", | ||
500: "Sorry, we might be overloaded, try again later.", | ||
}, | ||
Title: { | ||
rewrite: "Rewrite", | ||
}, | ||
Search: { | ||
placeholder: "Ask me anything ...", | ||
}, | ||
Footer: { | ||
statement: | ||
"Answer generated by large language models, plz double check for correctness.", | ||
}, | ||
Relates: { | ||
no_related_questions: "No related questions.", | ||
related: "Related", | ||
}, | ||
Answer: { | ||
answer: "Answer", | ||
}, | ||
Sources: { | ||
sources: "Sources", | ||
}, | ||
}; | ||
|
||
export default en; |
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,75 @@ | ||
// reference source: https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web/blob/main/app/locales/index.ts | ||
import cn from "./cn"; | ||
import en from "./en"; | ||
import jp from "./jp"; | ||
|
||
import type { LocaleType } from "./cn"; | ||
export type { LocaleType, PartialLocaleType } from "./cn"; | ||
|
||
const ALL_LANGS = { | ||
en, | ||
cn, | ||
jp, | ||
}; | ||
|
||
export type Lang = keyof typeof ALL_LANGS; | ||
|
||
export const AllLangs = Object.keys(ALL_LANGS) as Lang[]; | ||
|
||
export const ALL_LANG_OPTIONS: Record<Lang, string> = { | ||
en: "English", | ||
cn: "简体中文", | ||
jp: "日本語", | ||
}; | ||
|
||
const LANG_KEY = "lang"; | ||
const DEFAULT_LANG = "en"; | ||
|
||
const targetLang = ALL_LANGS[getLang()] as LocaleType; | ||
|
||
export default targetLang as LocaleType; | ||
|
||
function getItem(key: string) { | ||
try { | ||
return localStorage.getItem(key); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
function setItem(key: string, value: string) { | ||
try { | ||
localStorage.setItem(key, value); | ||
} catch {} | ||
} | ||
|
||
function getLanguage() { | ||
try { | ||
return navigator.language.toLowerCase(); | ||
} catch { | ||
return DEFAULT_LANG; | ||
} | ||
} | ||
|
||
export function getLang(): Lang { | ||
const savedLang = getItem(LANG_KEY); | ||
|
||
if (AllLangs.includes((savedLang ?? "") as Lang)) { | ||
return savedLang as Lang; | ||
} | ||
|
||
const lang = getLanguage(); | ||
|
||
for (const option of AllLangs) { | ||
if (lang.includes(option)) { | ||
return option; | ||
} | ||
} | ||
|
||
return DEFAULT_LANG; | ||
} | ||
|
||
export function changeLang(lang: Lang) { | ||
setItem(LANG_KEY, lang); | ||
location.reload(); | ||
} |
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,30 @@ | ||
import { LocaleType } from "./index"; | ||
|
||
const jp: LocaleType = { | ||
Err: { | ||
429: "申し訳ありませんが、最近のリクエストが多すぎます。後ほど再試行してください。", | ||
500: "申し訳ありませんが、サーバーが過負荷の可能性があります。後ほど再試行してください。", | ||
}, | ||
Title: { | ||
rewrite: "書き直し", | ||
}, | ||
Search: { | ||
placeholder: "何でも聞いてください...", | ||
}, | ||
Footer: { | ||
statement: | ||
"回答は大規模な言語モデルによって生成されます。正確性を再確認してください。", | ||
}, | ||
Relates: { | ||
no_related_questions: "関連する質問はありません。", | ||
related: "関連性", | ||
}, | ||
Answer: { | ||
answer: "回答", | ||
}, | ||
Sources: { | ||
sources: "情報源", | ||
}, | ||
}; | ||
|
||
export default jp; |
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