Translate .md files

This commit is contained in:
MartinBraquet
2025-12-27 12:51:47 +02:00
parent b6df79b836
commit c7d58905b5
17 changed files with 593 additions and 112 deletions

43
web/hooks/use-markdown.ts Normal file
View File

@@ -0,0 +1,43 @@
'use client'
import {useEffect, useState} from 'react'
import {useLocale} from 'web/lib/locale'
import {defaultLocale} from 'common/constants'
import {MD_PATHS} from "web/components/markdown";
export function useMarkdown(filename: typeof MD_PATHS[number]) {
const {locale} = useLocale()
const lang = locale ?? defaultLocale
const [content, setContent] = useState<string>('')
useEffect(() => {
let cancelled = false
const loadMarkdown = async () => {
try {
let path = `/md/${lang}/${filename}.md`
let res = await fetch(path)
if (!res.ok) {
// fallback to default locale
path = `/md/${filename}.md`
res = await fetch(path)
}
const text = await res.text()
if (!cancelled) setContent(text)
} catch (e) {
console.error(e)
if (!cancelled) setContent('Error loading content')
}
}
loadMarkdown()
return () => {
cancelled = true
}
}, [filename, lang])
return content
}