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

@@ -55,6 +55,17 @@
// 设置初始语言到全局变量供i18n系统使用
window.__INITIAL_LANGUAGE__ = userLanguage;
// 预设服务端翻译的内容,避免初始渲染时的闪烁
window.__SERVER_TRANSLATIONS__ = {
language: userLanguage,
common: {
loading: '{{ t("common.status.loading") }}',
error: '{{ t("common.status.error") }}',
refresh: '{{ t("common.actions.refresh") }}',
search: '{{ t("common.actions.search") }}'
}
};
// Apply theme immediately based on stored preference
const STORAGE_PREFIX = 'lora_manager_';
@@ -109,6 +120,8 @@
<!-- Load initialization JavaScript -->
<script type="module" src="/loras_static/js/components/initialization.js"></script>
{% else %}
<!-- Load mixed i18n handler first for better coordination -->
<script type="module" src="/loras_static/js/utils/mixedI18n.js"></script>
{% block main_script %}{% endblock %}
{% endif %}