import re with open('src/router/index.tsx', 'r', encoding='utf-8') as f: content = f.read() # Replace routeMeta titles with i18n keys replacements = { "title: '\u603b\u89c8\u9996\u9875'": "title: 'router.overview'", "title: '\u8bbe\u5907\u7ba1\u7406'": "title: 'router.devices'", "title: '\u5728\u7ebf\u89c6\u9891'": "title: 'router.video'", "title: '\u5b9e\u65f6\u76d1\u63a7'": "title: 'router.monitor'", "title: '\u544a\u8b66\u4e2d\u5fc3'": "title: 'router.alerts'", "title: 'AI\u8bca\u65ad\u5206\u6790'": "title: 'router.aiAnalysis'", "title: '\u6e05\u6d17\u4f18\u5316'": "title: 'router.clean'", "title: '\u5de5\u5355\u4efb\u52a1'": "title: 'router.task'", "title: '\u62a5\u8868\u4e2d\u5fc3'": "title: 'router.table'", "title: '\u7cfb\u7edf\u8bbe\u7f6e'": "title: 'router.systemSetting'", "title: '\u65e5\u5fd7\u7ba1\u7406'": "title: 'router.log'", "title: '\u89c6\u9891\u7ba1\u7406'": "title: 'router.videoManage'", "title: '\u89c6\u9891\u4e0b\u8f7d'": "title: 'router.downloads'", "title: '\u7528\u6237\u7ba1\u7406'": "title: 'router.users'", "title: '\u89d2\u8272\u7ba1\u7406'": "title: 'router.roles'", "title: '\u83dc\u5355\u7ba1\u7406'": "title: 'router.menuList'", "title: '\u7ec4\u7ec7\u7ba1\u7406'": "title: 'router.organization'", "title: '\u573a\u7ad9\u7ba1\u7406'": "title: 'router.station'", "title: '\u4e2a\u4eba\u4e2d\u5fc3'": "title: 'router.profile'", } for old, new in replacements.items(): content = content.replace(old, new) # Replace 404 page text content = content.replace( '

\u6a21\u5757\u5f00\u53d1\u4e2d

', '

{t("router.moduleDeveloping")}

' ) # Replace placeholder pages content = content.replace( '

\u901a\u77e5\u7b56\u7565\u9875\u9762

', '

{t("router.noticePolicy")}

' ) content = content.replace( '

\u6570\u636e\u4e0e\u5b89\u5168\u9875\u9762

', '

{t("router.dataSafety")}

' ) # Add useTranslation import and helper components add_after_imports = """ import { useTranslation } from 'react-i18next'; function ModuleDeveloping() { \tconst { t } = useTranslation(); \treturn ( \t\t
\t\t\t\ud83c\udde7 \t\t\t

{t('router.moduleDeveloping')}

\t\t
\t); } function NoticePolicyPage() { \tconst { t } = useTranslation(); \treturn

{t('router.noticePolicy')}

; } function DataSafetyPage() { \tconst { t } = useTranslation(); \treturn

{t('router.dataSafety')}

; } """ # Insert after the Profile import line content = re.sub( r"(import Profile from '.*?';\n)", r"\1" + add_after_imports, content, count=1 ) # Replace the inline 404 element with component old_404 = '
\n\t\t\t\t\t\t\t\ud83c\udde7\n\t\t\t\t\t\t\t

{t("router.moduleDeveloping")}

\n\t\t\t\t\t\t
' content = content.replace(old_404, '') # Replace the inline notice/dataSafety elements old_notice = '

{t("router.noticePolicy")}

' content = content.replace(old_notice, '') old_datasafety = '

{t("router.dataSafety")}

' content = content.replace(old_datasafety, '') with open('src/router/index.tsx', 'w', encoding='utf-8') as f: f.write(content) print("router/index.tsx updated successfully")