edit html title for each lang

This commit is contained in:
feie9454 2025-08-22 11:57:21 +08:00
parent 4c9a7ae41c
commit 072e7aa892
2 changed files with 16 additions and 2 deletions

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" /> <link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>5大潜能测试</title> <title>5 大潜能测试</title>
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>

View File

@ -10,7 +10,18 @@
* HTML文档的lang属性 * HTML文档的lang属性
* @param locale - i18n的locale值 ( 'zh_CN', 'en', 'ja' ) * @param locale - i18n的locale值 ( 'zh_CN', 'en', 'ja' )
*/ */
export function setHtmlLang(locale: string): void { export const setHtmlLang = (locale: string) => {
setHtmlLang_(locale, {
'zh_CN': '5 大潜能测试',
'zh_TW': '5 大潛能測試',
'ja': `L'Oréal 5 Potential Self-test`,
'ko': `L'Oréal 5 Potential Self-test`,
'en': `L'Oréal 5 Potential Self-test`
})
}
function setHtmlLang_(locale: string, title?: Record<string, string>): void {
const langMap: Record<string, string> = { const langMap: Record<string, string> = {
'zh_CN': 'zh-CN', 'zh_CN': 'zh-CN',
'zh_TW': 'zh-TW', 'zh_TW': 'zh-TW',
@ -19,6 +30,9 @@ export function setHtmlLang(locale: string): void {
'en': 'en' 'en': 'en'
}; };
document.documentElement.lang = langMap[locale] || 'en'; document.documentElement.lang = langMap[locale] || 'en';
if (title) {
document.title = title[locale] || title['en'] || 'Default Title';
}
} }
/** /**