feat: add waline i18n & sync comments

This commit is contained in:
radishzzz 2025-03-06 22:19:34 +00:00
parent fa148ca0c5
commit c2ebc78045
12 changed files with 172 additions and 101 deletions

View file

@ -7,6 +7,18 @@ export const langMap: Record<string, string[]> = {
'es': ['es-ES'],
'ru': ['ru-RU'],
}
// Waline Language Map
// see more at https://waline.js.org/guide/i18n.html
export const walineLocaleMap: Record<string, string> = {
'zh': 'zh-CN',
'zh-tw': 'zh-TW',
'ja': 'jp-JP', // Waline uses jp-JP not ja-JP
'en': 'en-US',
'es': 'es-ES',
'ru': 'ru-RU',
}
// Standard Language Code
export const langCode = Object.values(langMap).flat()
// Abbreviated Language Code
@ -44,3 +56,19 @@ export const ui = {
about: 'О себе',
},
}
/**
* Get the language code of Waline
* @param currentPath Current page path
* @param defaultLocale Default language
* @returns Corresponding Waline language code
*/
export function getWalineLang(currentPath: string, defaultLocale: string): string {
// Extract language code from path
const pathLang = Object.keys(walineLocaleMap).find(code =>
currentPath.startsWith(`/${code}/`),
)
// Return found path language or default language
const lang = pathLang || defaultLocale
return walineLocaleMap[lang as keyof typeof walineLocaleMap]
}