generated from template/astro-template
init 新范式
This commit is contained in:
27
src/astro/i18n/index.tsx
Normal file
27
src/astro/i18n/index.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import i18n from 'i18next';
|
||||
import { initReactI18next } from 'react-i18next';
|
||||
import LanguageDetector from 'i18next-browser-languagedetector';
|
||||
|
||||
// 导入你的翻译资源
|
||||
import enTranslation from './locales/en/translation.json';
|
||||
import zhTranslation from './locales/zh/translation.json';
|
||||
|
||||
i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
resources: {
|
||||
en: {
|
||||
translation: enTranslation,
|
||||
},
|
||||
zh: {
|
||||
translation: zhTranslation,
|
||||
},
|
||||
},
|
||||
fallbackLng: 'en',
|
||||
interpolation: {
|
||||
escapeValue: false, // React 已经处理了转义
|
||||
},
|
||||
});
|
||||
|
||||
export default i18n;
|
||||
4
src/astro/i18n/locales/en/translation.json
Normal file
4
src/astro/i18n/locales/en/translation.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"welcome": "Welcome to our site",
|
||||
"about": "About us"
|
||||
}
|
||||
4
src/astro/i18n/locales/zh/translation.json
Normal file
4
src/astro/i18n/locales/zh/translation.json
Normal file
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"welcome": "欢迎来到我们的网站",
|
||||
"about": "关于我们"
|
||||
}
|
||||
36
src/astro/layouts/mdx/main.astro
Normal file
36
src/astro/layouts/mdx/main.astro
Normal file
@@ -0,0 +1,36 @@
|
||||
---
|
||||
export interface Props {
|
||||
children: any;
|
||||
}
|
||||
---
|
||||
|
||||
<html lang='zh'>
|
||||
<header>
|
||||
<meta charset='UTF-8' />
|
||||
<title>Docs</title>
|
||||
<link
|
||||
rel='stylesheet'
|
||||
href='https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.8.1/github-markdown-light.min.css'
|
||||
integrity='sha512-X175XRJAO6PHAUi8AA7GP8uUF5Wiv+w9bOi64i02CHKDQBsO1yy0jLSKaUKg/NhRCDYBmOLQCfKaTaXiyZlLrw=='
|
||||
crossorigin='anonymous'
|
||||
referrerpolicy='no-referrer'
|
||||
/>
|
||||
</header>
|
||||
<body>
|
||||
<header>
|
||||
<slot name='header'>
|
||||
<h1>My Site Header</h1>
|
||||
</slot>
|
||||
</header>
|
||||
<main class='markdown-body' style='padding: 1rem'>
|
||||
<slot />
|
||||
</main>
|
||||
<footer>
|
||||
<slot name='footer'>
|
||||
<p>Copyrignt © 2025</p>
|
||||
</slot>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
|
||||
</html>
|
||||
Reference in New Issue
Block a user