feat(i18n): Implement server-side internationalization support

- Added ServerI18nManager to handle translations and locale settings on the server.
- Integrated server-side translations into templates, reducing language flashing on initial load.
- Created API endpoints for setting and getting user language preferences.
- Enhanced client-side i18n handling to work seamlessly with server-rendered content.
- Updated various templates to utilize the new translation system.
- Added mixed i18n handler to coordinate server and client translations, improving user experience.
- Expanded translation files to include initialization messages for various components.
This commit is contained in:
Will Miao
2025-08-30 16:56:56 +08:00
parent 3c9e402bc0
commit 29160bd6e5
14 changed files with 775 additions and 42 deletions

View File

@@ -169,8 +169,19 @@ export function formatNumber(number, options = {}) {
* This should be called after DOM content is loaded
*/
export function initializePageI18n() {
// Translate all elements with data-i18n attributes
translateDOM();
// 优先使用服务端传递的翻译数据,避免闪烁
if (window.__SERVER_TRANSLATIONS__ && window.__SERVER_TRANSLATIONS__.language) {
// 设置客户端i18n的语言为服务端传递的语言
if (window.i18n && window.i18n.setLanguage) {
window.i18n.setLanguage(window.__SERVER_TRANSLATIONS__.language);
}
// 对于剩余的需要动态翻译的元素,仍使用客户端翻译
translateDOM();
} else {
// 回退到完整的客户端翻译
translateDOM();
}
// Update search placeholder based on current page
const currentPath = window.location.pathname;