File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed
Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { askAI } from "@/app/actions/chatActions";
55import { StyledMarkdown } from "./markdown" ;
66import useSWR from "swr" ;
77import { getQuestionExample } from "../actions/questionExample" ;
8+ import { getLanguageName } from "../pagesList" ;
89
910export function ChatForm ( {
1011 docs_id,
@@ -18,7 +19,7 @@ export function ChatForm({
1819 const [ isLoading , setIsLoading ] = useState ( false ) ;
1920 const [ isFormVisible , setIsFormVisible ] = useState ( false ) ;
2021
21- const lang = docs_id . split ( "-" ) [ 0 ] ;
22+ const lang = getLanguageName ( docs_id ) ;
2223 const { data : exampleData , error : exampleError } = useSWR (
2324 // 質問フォームを開いたときだけで良い
2425 isFormVisible ? { lang, documentContent } : null ,
Original file line number Diff line number Diff line change @@ -30,3 +30,13 @@ export const pagesList = [
3030 ] ,
3131 } ,
3232] as const ;
33+
34+ // ${lang_id}-${page_id} から言語名を取得
35+ export function getLanguageName ( docs_id : string ) {
36+ const lang_id = docs_id . split ( "-" ) [ 0 ] ;
37+ const lang = pagesList . find ( ( lang ) => lang . id === lang_id ) ?. lang ;
38+ if ( ! lang ) {
39+ throw new Error ( `Unknown language id: ${ lang_id } ` ) ;
40+ }
41+ return lang ;
42+ }
You can’t perform that action at this time.
0 commit comments