应用国际化
本例在启动时设置应用语言,并通过命令、Chromium 和原生菜单观察这一设置。它展示框架语言配置;应用自身的文本仍需由应用提供翻译。
56_i18n · 关键文件:main.mbt, app.html
行为
应用选择 zh-CN,同时显示后端语言偏好、navigator.language 和 navigator.languages。
实现说明
以下为入口中的节选,完整上下文见本页源码链接。
async fn main {
let locale = @proton.Locale::parse("zh-CN") catch {
error => abort(error.message())
}
@proton.html("Proton 国际化", resource, width=860, height=600, debug=true)
..locale(locale)
..capability(@proton_extension.capability(i18n_extension()))
..identifier("dev.proton.56-i18n")
.run_or_abort()
}
应用显式解析 zh-CN 并传给 locale()。扩展从命令上下文读取解析后的语言偏好,Chromium 与原生框架标签使用相同的启动选择。Windows 有独立入口变体,不创建其他宿主使用的菜单。
这选择框架/浏览器语言,不会翻译任意应用文本;应用字符串需要自己的 catalog。此例配置启动语言,不实现运行中切换语言。
运行
完成源码检出与运行时安装后,在仓库根目录执行:
moon -C examples run 56_i18n --target native
限制与使用边界
Proton 传递语言环境,不翻译业务文案。此示例在 Windows 上省略原生菜单,不能由其他平台的表现推断其菜单一致性。