edit html title for each lang
This commit is contained in:
parent
4c9a7ae41c
commit
072e7aa892
@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<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">
|
||||
<title>5大潜能测试</title>
|
||||
<title>5 大潜能测试</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
|
||||
16
src/utils.ts
16
src/utils.ts
@ -10,7 +10,18 @@
|
||||
* 设置HTML文档的lang属性
|
||||
* @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> = {
|
||||
'zh_CN': 'zh-CN',
|
||||
'zh_TW': 'zh-TW',
|
||||
@ -19,6 +30,9 @@ export function setHtmlLang(locale: string): void {
|
||||
'en': 'en'
|
||||
};
|
||||
document.documentElement.lang = langMap[locale] || 'en';
|
||||
if (title) {
|
||||
document.title = title[locale] || title['en'] || 'Default Title';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user