import 'package:flutter/widgets.dart'; /// 轻量 i18n:键值表 + 运行时切换,和后端 `GC/src/Assets/i18n/*.json` 的键保持一致。 class I18n { I18n._(); static const List supported = ['zh-CN', 'en']; static final ValueNotifier language = ValueNotifier('zh-CN'); static const Map> _tables = >{ 'zh-CN': { 'app.name': 'Morris GC', 'app.tagline': '天文教学模型 · 可视化启动器', 'nav.home': '主页', 'nav.download': '下载', 'nav.settings': '设置', 'nav.about': '关于', 'home.title': '模型库', 'home.subtitle': '选择模型,用可交互的三维演示讲清自转、公转与四季成因。', 'home.launch': '启动模型', 'home.download': '下载模型', 'home.settings': '设置', 'home.installed': '已安装模型', 'home.count': '{0} 个模型', 'home.noDescription': '暂无简介', 'home.empty': '模型库还是空的', 'home.emptyHint': '启动时会自动检查并下载模型。若当前断网:可把模型文件夹放进 .GC/model/ 后重新打开,或联网后在「下载」页点重试。', 'home.emptyAction': '去下载模型', 'home.open': '打开目录', 'home.delete': '删除', 'home.deleteConfirm': '删除模型「{0}」?模型文件会从本地模型库移除。', 'home.stats.models': '已安装', 'home.stats.sources': '模型源', 'home.stats.memory': '内存预算', 'home.recent': '选择模型后点击「启动模型」', 'home.launchHint': '模型在自己的窗口里运行,可播放/暂停、切换视角并使用教学要点。', 'dl.title': '下载模型', 'dl.subtitle': '从内置模型源读取可下载模型;模型源在「设置」里查看。', 'dl.sources': '模型源', 'dl.refresh': '刷新', 'dl.available': '可用模型', 'dl.download': '下载', 'dl.installed': '已安装', 'dl.reinstall': '重新下载', 'dl.background': '后台任务', 'dl.bgEmpty': '暂无后台任务', 'dl.cancel': '取消', 'dl.retry': '重试', 'dl.clearDone': '清除已完成', 'dl.removeTask': '移除', 'dl.status.queued': '排队中', 'dl.status.downloading': '下载中', 'dl.status.done': '已完成', 'dl.status.failed': '失败', 'dl.status.canceled': '已取消', 'dl.empty': '这个源里没有模型', 'dl.emptyHint': '仓库需要包含 model/<模型ID>/<模型ID>.json 结构', 'dl.syncing': '正在读取模型源…', 'dl.ready': '共 {0} 个模型', 'dl.fromCache': '本地缓存', 'dl.pickSource': '选择一个模型源,查看可下载的模型', 'set.title': '设置', 'set.subtitle': '模型源、启动时内存分配与本地存储。', 'set.general': '通用', 'set.appearance': '外观', 'set.theme': '主题模式', 'set.theme.desc': '深色、浅色,或跟随系统设置。', 'set.theme.dark': '深色', 'set.theme.light': '浅色', 'set.theme.system': '跟随系统', 'set.accent': '主题颜色', 'set.accent.desc': '选择启动器的主色调,按钮、滑块与高亮会同步换色。', 'set.accent.custom': '自定义颜色', 'set.accent.hexHint': '格式 #RRGGBB,例如 #8FB6FF', 'set.accent.invalid': '颜色格式无效,请使用 #RRGGBB', 'set.language': '界面语言', 'set.language.auto': '跟随系统', 'set.fps': '渲染帧率', 'set.fps.desc': '越高越顺滑,CPU 占用也越高。', 'set.memory': '启动时运行内存分配', 'set.memory.desc': '启动器把这份预算交给模型:模型自己决定用它缓存多少数据(贴图分辨率、缓冲等)。', 'set.memory.current': '当前占用', 'set.memory.auto': '自动(根据设备内存分配)', 'set.memory.hint': '建议 2048 MB 以上,低配设备可选 1024 MB。', 'set.sources': '模型源', 'set.sources.desc': '停用的模型源不会出现在下载页。', 'set.sourceEnabled': '启用', 'set.storage': '存储', 'set.modelDir': '模型库目录', 'set.dataDir': '数据目录', 'set.openFolder': '打开文件夹', 'set.clearCache': '清理缓存', 'set.cacheCleared': '缓存已清理', 'set.about': '关于', 'set.version': '版本', 'set.platform': '平台', 'set.license': '许可', 'set.licenseValue': 'MIT', 'set.checkUpdate': '检查更新', 'set.checkUpdate.desc': '启动时自动检查模型与启动器是否为最新版。', 'set.backend': '后端服务', 'set.backend.desc': '界面(Flutter)与后端(.NET)分离,后端只监听本机回环地址。', 'set.backend.ui': '模型窗口宿主', 'set.backend.uiOk': '可用', 'set.backend.uiBad': '不可用', 'update.title': '自动更新', 'update.auto': '启动时自动检查更新', 'update.checkNow': '检查更新', 'update.source': '更新源', 'update.lastCheck': '上次检查', 'update.never': '尚未检查', 'update.none': '无', 'update.checking': '正在检查更新…', 'update.offline': '暂时无法连接更新服务器,继续使用本地模型', 'update.noChange': '模型与启动器均为最新版', 'update.applied': '已更新 {0} 个模型,立即生效', 'update.done': '更新检查完成', 'update.pendingReady': '启动器新版 {0} 已就绪,下次启动生效', 'common.cancel': '取消', 'common.confirm': '确定', 'common.delete': '删除', 'common.close': '关闭', 'common.open': '打开', 'common.applied': '已应用', 'common.confirmTitle': '请确认', 'common.retry': '重试', 'common.loading': '加载中…', 'common.error': '出错了', 'common.refresh': '刷新', 'about.developers': '开发者', 'about.contributorsHint': '来自仓库提交记录', 'about.repository': '仓库', 'about.openRepository': '打开仓库', 'about.contributions': '{0} 次提交', 'about.noContributors': '暂无贡献者信息', 'about.architecture': '架构', 'about.architectureValue': 'Flutter 前端 + .NET 后端(本地 HTTP)', 'about.sourceLanguage': '源码语言', 'about.frontend': '前端', 'about.gitService': 'Git 服务', 'about.thanks': '感谢', 'about.thanksHint': '特别感谢以下朋友的支持', 'about.thanksGit': 'Git 服务与部署支持', 'about.thanksGeo': '地理学科内容指导', }, 'en': { 'app.name': 'Morris GC', 'app.tagline': 'Astronomy teaching models · visual launcher', 'nav.home': 'Home', 'nav.download': 'Download', 'nav.settings': 'Settings', 'nav.about': 'About', 'home.title': 'Model library', 'home.subtitle': 'Pick a model and explain rotation, revolution and the seasons with an interactive 3D scene.', 'home.launch': 'Launch model', 'home.download': 'Get models', 'home.settings': 'Settings', 'home.installed': 'Installed models', 'home.count': '{0} models', 'home.noDescription': 'No description', 'home.empty': 'No models yet', 'home.emptyHint': 'Models are checked and downloaded on startup. Offline: drop model folders into .GC/model/ and reopen, or retry from the Download page once online.', 'home.emptyAction': 'Get models', 'home.open': 'Open folder', 'home.delete': 'Delete', 'home.deleteConfirm': 'Delete the model "{0}"? Its files will be removed from the local library.', 'home.stats.models': 'Installed', 'home.stats.sources': 'Sources', 'home.stats.memory': 'Memory budget', 'home.recent': 'Select a model, then press Launch', 'home.launchHint': 'Models open in their own window with play/pause, view controls and teaching notes.', 'dl.title': 'Download', 'dl.subtitle': 'Read downloadable models from the built-in sources; manage sources in Settings.', 'dl.sources': 'Sources', 'dl.refresh': 'Refresh', 'dl.available': 'Available models', 'dl.download': 'Download', 'dl.installed': 'Installed', 'dl.reinstall': 'Re-download', 'dl.background': 'Background tasks', 'dl.bgEmpty': 'No background tasks', 'dl.cancel': 'Cancel', 'dl.retry': 'Retry', 'dl.clearDone': 'Clear finished', 'dl.removeTask': 'Remove', 'dl.status.queued': 'Queued', 'dl.status.downloading': 'Downloading', 'dl.status.done': 'Completed', 'dl.status.failed': 'Failed', 'dl.status.canceled': 'Canceled', 'dl.empty': 'No models in this source', 'dl.emptyHint': 'A source needs model//.json layout', 'dl.syncing': 'Reading model source…', 'dl.ready': '{0} models', 'dl.fromCache': 'cached', 'dl.pickSource': 'Select a source to see available models', 'set.title': 'Settings', 'set.subtitle': 'Model sources, startup memory allocation and local storage.', 'set.general': 'General', 'set.appearance': 'Appearance', 'set.theme': 'Theme mode', 'set.theme.desc': 'Dark, light, or follow the system setting.', 'set.theme.dark': 'Dark', 'set.theme.light': 'Light', 'set.theme.system': 'System', 'set.accent': 'Theme color', 'set.accent.desc': 'Pick the launcher accent color; buttons, sliders and highlights follow it.', 'set.accent.custom': 'Custom color', 'set.accent.hexHint': 'Format #RRGGBB, e.g. #8FB6FF', 'set.accent.invalid': 'Invalid color, use #RRGGBB', 'set.language': 'Language', 'set.language.auto': 'System', 'set.fps': 'Render frame rate', 'set.fps.desc': 'Higher is smoother but uses more CPU.', 'set.memory': 'Startup memory allocation', 'set.memory.desc': 'The launcher hands this budget to each model; models decide how much data to cache with it.', 'set.memory.current': 'In use', 'set.memory.auto': 'Auto (allocate based on device memory)', 'set.memory.hint': '2048 MB or more is recommended; 1024 MB for low-end devices.', 'set.sources': 'Model sources', 'set.sources.desc': 'Disabled sources are hidden from the Download page.', 'set.sourceEnabled': 'Enabled', 'set.storage': 'Storage', 'set.modelDir': 'Model library', 'set.dataDir': 'Data folder', 'set.openFolder': 'Open folder', 'set.clearCache': 'Clear cache', 'set.cacheCleared': 'Cache cleared', 'set.about': 'About', 'set.version': 'Version', 'set.platform': 'Platform', 'set.license': 'License', 'set.licenseValue': 'MIT', 'set.checkUpdate': 'Check for updates', 'set.checkUpdate.desc': 'Check on startup whether models and the launcher are up to date.', 'set.backend': 'Backend service', 'set.backend.desc': 'The UI (Flutter) and the backend (.NET) are separate; the backend only listens on loopback.', 'set.backend.ui': 'Model window host', 'set.backend.uiOk': 'available', 'set.backend.uiBad': 'unavailable', 'update.title': 'Auto update', 'update.auto': 'Check for updates on startup', 'update.checkNow': 'Check now', 'update.source': 'Update source', 'update.lastCheck': 'Last check', 'update.never': 'Never', 'update.none': 'None', 'update.checking': 'Checking for updates…', 'update.offline': 'Update server unavailable — continuing with local models', 'update.noChange': 'Models and launcher are up to date', 'update.applied': 'Updated {0} models, applied now', 'update.done': 'Update check complete', 'update.pendingReady': 'Launcher {0} is ready, applies on next start', 'common.cancel': 'Cancel', 'common.confirm': 'Confirm', 'common.delete': 'Delete', 'common.close': 'Close', 'common.open': 'Open', 'common.applied': 'Applied', 'common.confirmTitle': 'Please confirm', 'common.retry': 'Retry', 'common.loading': 'Loading…', 'common.error': 'Something went wrong', 'common.refresh': 'Refresh', 'about.developers': 'Developers', 'about.contributorsHint': 'From repository commits', 'about.repository': 'Repository', 'about.openRepository': 'Open repository', 'about.contributions': '{0} commits', 'about.noContributors': 'No contributor information', 'about.architecture': 'Architecture', 'about.architectureValue': 'Flutter frontend + .NET backend (local HTTP)', 'about.sourceLanguage': 'Source language', 'about.frontend': 'Frontend', 'about.gitService': 'Git hosting', 'about.thanks': 'Thanks', 'about.thanksHint': 'Special thanks to', 'about.thanksGit': 'Git hosting and deployment', 'about.thanksGeo': 'Geography content guidance', }, }; /// 取一条文案;`{0}` 这类占位符用 [args] 填充。 static String t(String key, [List args = const []]) { final table = _tables[language.value] ?? _tables['zh-CN']!; var text = table[key] ?? _tables['zh-CN']![key] ?? key; for (var i = 0; i < args.length; i++) { text = text.replaceAll('{$i}', '${args[i]}'); } return text; } /// 把后端语言设置(auto / zh-CN / en)解析成实际语言。 static String resolve(String? preference) { if (preference != null && preference.isNotEmpty && preference != 'auto') { return preference.startsWith('en') ? 'en' : 'zh-CN'; } final locale = WidgetsBinding.instance.platformDispatcher.locale; return locale.languageCode == 'zh' ? 'zh-CN' : 'en'; } static void setLanguage(String code) { final resolved = resolve(code); if (language.value != resolved) language.value = resolved; } } /// 便捷取词:`T('nav.home')`。 String T(String key, [List args = const []]) => I18n.t(key, args);