8000 add i18n support in LiveCodes · seanpm2001/TheAlgorithms_Website@4c4cb6d · GitHub
[go: up one dir, main page]

Skip to content

Commit 4c4cb6d

Browse files
committed
add i18n support in LiveCodes
1 parent c6357c2 commit 4c4cb6d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

components/playgroundEditor/LiveCodes.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Config, Playground } from "livecodes";
33
import LiveCodesPlayground from "livecodes/react";
44
import { luaTestRunner, type Language } from "lib/playground/livecodes";
55
import { useDarkTheme } from "hooks/darkTheme";
6+
import { useRouter } from "next/router";
67

78
export default function LiveCodes({
89
language,
@@ -15,6 +16,14 @@ export default function LiveCodes({
1516
}) {
1617
const [playground, setPlayground] = useState<Playground | undefined>();
1718
const [darkTheme] = useDarkTheme();
19+
const { locale } = useRouter();
20+
21+
const getLanguageFromLocale = (locale_: string | undefined) =>
22+
!locale_
23+
? "en"
24+
: locale_ === "zh_Hans"
25+
? "zh-CN"
26+
: (locale_.split("_")[0] as Config["appLanguage"]);
1827

1928
const onReady = (sdk: Playground) => {
2029
setPlayground(sdk);
@@ -31,6 +40,7 @@ export default function LiveCodes({
3140
}, [playground, darkTheme]);
3241

3342
const baseConfig: Partial<Config> = {
43+
appLanguage: getLanguageFromLocale(locale),
3444
autoupdate: true,
3545
languages: [language === "jupyter" ? "python-wasm" : language],
3646
script: {
@@ -224,7 +234,7 @@ ${test.replace(pattern, "\n")}`.trimStart();
224234

225235
return (
226236
<LiveCodesPlayground
227-
appUrl="https://v37.livecodes.io/"
237+
appUrl="https://v38.livecodes.io/"
228238
loading="eager"
229239
config={config}
230240
style={{ borderRadius: "0", resize: "none" }}

0 commit comments

Comments
 (0)
0