Lingo.dev + .strings(Xcode)
Lingo.dev CLI 翻译 Xcode 的 .strings 文件,同时保留键值结构、注释和 iOS 本地化约定。CLI 支持旧版 Xcode 项目和工作流,保留开发者上下文和注释中的说明,保持 iOS 格式说明符(如 %@
和 %d
),正确处理 UTF-16 和 UTF-8 编码,并与标准 iOS 本地化流程集成。
快速设置
为旧版 Xcode strings 文件配置:
{
"locale": {
"source": "en",
"targets": ["es", "fr", "de", "ja"]
},
"buckets": {
"xcode-strings": {
"include": ["Resources/[locale].lproj/Localizable.strings"]
}
}
}
提醒:[locale]
是一个占位符,在 CLI 运行时会被实际的语言区域替换,因此应在配置中保持原样。
翻译 Strings 文件
npx lingo.dev@latest i18n
在翻译值的同时保留 strings 文件格式、开发者注释和 iOS 特定约定。
Strings 文件结构
基本键值对
/* 主导航 */
"nav.home" = "Home";
"nav.settings" = "Settings";
"nav.profile" = "Profile";
/* 身份验证 */
"auth.login" = "Log In";
"auth.logout" = "Log Out";
"auth.register" = "Sign Up";
格式说明符
/* 带占位符的用户消息 */
"welcome.user" = "Welcome back, %@!";
"items.count" = "You have %d items in your cart";
"download.progress" = "Downloading... %.1f%% complete";
多行字符串
/* 长内容 */
"terms.agreement" = "By using this app, you agree to our terms of service and privacy policy. Please read them carefully before proceeding.";
"help.description" = "This feature helps you manage your tasks efficiently. You can create, edit, and organize your work items.";
iOS 特定功能
本地化注释
/* 出现在底部标签栏中 */
"tab.home" = "首页";
/* 提交表单的按钮文本 */
"button.submit" = "提交";
/* 网络不可用时的错误消息 */
"error.network" = "请检查您的互联网连接";
开发者注释为翻译人员提供了上下文。
特殊字符
/* 包含引号和特殊字符的字符串 */
"message.quote" = "她说,\"你好!\"";
"path.file" = "Documents\\MyFile.txt";
"symbol.copyright" = "© 2024 公司名称";
正确保留了引号和反斜杠的转义。
Storyboard 集成
/* Storyboard 本地化 */
"A8K-3L-9X7.text" = "欢迎";
"B9M-4N-0Y8.placeholder" = "输入您的姓名";
"C0P-5Q-1Z9.title" = "设置";
正确处理了由 Interface Builder 生成的键。
高级配置
多个字符串文件
"xcode-strings": {
"include": [
"Resources/[locale].lproj/Localizable.strings",
"Resources/[locale].lproj/InfoPlist.strings"
]
}
锁定系统键
"xcode-strings": {
"include": ["Resources/[locale].lproj/Localizable.strings"],
"lockedKeys": ["CFBundleName", "CFBundleDisplayName"]
}