一个 Xcode 和 Android 本地化文件验证器。确保您的 .strings
、.stringsdict
和 strings.xml
文件没有任何错误!
Locheck 可以对本地化文件执行多种检查。最简单的一种是确保所有字符串都出现在基本语言和翻译中,但它也可以确保您的所有格式说明符都一致,即使在 .stringsdict
文件中也是如此。
考虑以下字符串
"Send %d donuts to %@" = "%@ to donuts %d send";
<!-- values/strings.xml -->
<string name="send_donuts">Send %d donuts to %s</string>
<!-- values-translation/strings.xml -->
<string name="send_donuts">%s to donuts %d send</string>
翻译本身读起来很自然,但是当 iOS 或 Android 尝试将数字格式化为字符串,并将字符串格式化为数字时,这会使您的应用程序崩溃。相反,翻译应该像这样
"Send %d donuts to %@" = "%2$@ to donuts %1$d send";
<!-- values-translation/strings.xml -->
<string name="send_donuts">%2$s to donuts %1$d send</string>
Locheck 将确保您做对。
在上面的示例中,键恰好等于基本翻译。但是您可能有特殊情况,您在 Localizable.strings
中手动定义字符串,因此键的格式字符串与值不匹配
// in en.lproj/Localizable.strings:
"send-donuts" = "Send %d donuts to %@";
// in backwards.lproj/Localizable.strings:
"send-donuts" = "%@ to donuts %d send";
在这些情况下,Locheck 将使用基本翻译的值(而不是其键)作为权威字符串,并会捕获上面示例中的错误。
git clone git@github.com:Asana/locheck.git
cd locheck
make install
mint install Asana/locheck
mint run locheck [...]
# or link it to /usr/local/bin
mint install Asana/locheck --link
locheck [...]
Locheck 尚未流行到足以进入 homebrew/core
,我们尚未创建 tap。
根据您想要的魔法程度,有几种调用 locheck
的方法。在所有情况下,Locheck 都会写入 stderr 以进行 Xcode 集成,并写入 stdout 以获得人类可读的摘要。可能会接受针对其他输出格式的拉取请求。
将 Locheck 与 Xcode 一起使用的最简单方法是使用 discoverlproj
并指向包含所有 .lproj
文件的目录
locheck discoverlproj "MyApp/Supporting Files" --base en # use English as the base language
如果您使用英语以外的语言作为基本语言,则需要将其作为参数传递,如示例所示。Locheck 不会尝试读取您的 xcodeproj 文件来弄清楚它。
在 Android 上使用 Locheck 的最简单方法是使用 discovervalues
并指向包含所有 values[-*]
目录的目录,即您的 res/
目录。
locheck discovervalues ./app/src/main/res
运行 locheck --help
以查看所有命令的列表。其余命令只允许您直接比较不同类型的单个文件。
> locheck discovervalues $ANDROID/app/src/main/res --ignore key_missing_from_translation --ignore key_missing_from_base
Discovering values[-*]/strings.xml files in /.../app/src/main/res
Source of truth: /.../app/src/main/res/values/strings.xml
Translations to check: 12
/.../app/src/main/res/values-de/strings.xml:242: error: Translation of 'could_not_mark_as_milestone' includes arguments that don't exist in the source: task_name (string_has_extra_arguments)
/.../app/src/main/res/values-de/strings.xml:899: warning: 'organization_required_mfa_help_text' does not include argument(s): authy_url, duo_mobile_url, microsoft_authenticator_url (phrase_has_missing_arguments)
/.../app/src/main/res/values-ko/strings.xml:1403: error: Translation of 'what_are_a_few_tasks_you_have_to_do_for_project_name' includes arguments that don't exist in the source: projectName (string_has_extra_arguments)
/.../app/src/main/res/values-ko/strings.xml:1426: warning: 'created_video_phrase_template' does not include argument(s): author_name (phrase_has_missing_arguments)
[...]
Summary:
/.../app/src/main/res/values-ko/strings.xml
could_not_mark_as_milestone:
ERROR: Translation of 'could_not_mark_as_milestone' includes arguments that don't exist in the source: task_name
created_video_phrase_template:
WARNING: 'created_video_phrase_template' does not include argument(s): author_name
ERROR: Translation of 'created_video_phrase_template' includes arguments that don't exist in the source: userName1
organization_required_mfa_help_text:
WARNING: 'organization_required_mfa_help_text' does not include argument(s): authy_url, duo_mobile_url, microsoft_authenticator_url
what_are_a_few_tasks_you_have_to_do_for_project_name:
WARNING: 'what_are_a_few_tasks_you_have_to_do_for_project_name' does not include argument(s): project_name
ERROR: Translation of 'what_are_a_few_tasks_you_have_to_do_for_project_name' includes arguments that don't exist in the source: projectName
[...]
20 warnings, 29 errors
Ignored key_missing_from_translation, key_missing_from_base
Errors found
非常欢迎 GitHub 问题和拉取请求!在打开您的 PR 之前,请使用 swiftformat Sources Tests
格式化您的代码,否则测试将失败,我们无法合并您的分支。我们还运行 SwiftLint 以帮助确保最佳实践。
安装 SwiftFormat 和 SwiftLint 的最简单方法是使用 Mint
brew install mint
mint bootstrap --link`
然后您可以在本地运行这两个工具
swiftformat Sources Tests
swiftlint lint --quiet