L10nLint

Localizable.strings 的 Lint 工具

Lint 命令

基于你的 .l10nlint.yml 进行 Lint

l10nlint

当使用 Xcode 预构建脚本运行时,显示警告和错误。

规则

duplicate_key     Duplicated key should be resolved.
empty_key         Empty localized key should be resolved.
empty_value       Empty localized value should be resolved.
key_order         Between Base and each language file's key should be same order.
mark_syntax       Annotation should have around one space.
mixed_chinese     The mixing of traditional and simplified chinese characters should be resolved.
multi_linefeed    Linefeed should be one.
space_in_key      Key should not have space.
todo              TODOs and FIXMEs should be resolved.

复制命令

这是一个有用的功能!✨

基于你的 .l10nlint.yml 将键复制到每个 strings 文件

l10nlint copy [--delete-marker]
usage.mov

在你的 Base.lproj/Localizable.strings 中定义标记。用 // @copy// @end 关键字包围要复制的内容。--delete-marker 选项会删除你的 Base.lproj/Localizable.strings 中的标记

如果你的标记上方的行是注释,则检测相等的行;如果你的标记上方的行是键,则检测相等的键。

// MARK: Main
"MainKey" = "Main value";
// @copy
"SecondGen1" = "Second gen value 1";
"SecondGen2" = "Second gen value 2";
// @end

安装

Homebrew

brew install s2mr/tap/l10nlint

Swift Package Manager

将以下内容添加到你的 Package.swift 的 dependencies 中

dependencies: [
    .package(url: "https://github.com/s2mr/L10nLint.git", from: "L10nLint version"),
]

运行命令

swift run -c release l10nlint [COMMAND] [OPTIONS]

Mint

按照以下命令使用 Mint 安装

mint install s2mr/l10nlint

运行命令

mint run s2mr/l10nlint [COMMAND] [OPTIONS]

使用预构建的二进制文件

你也可以通过从最新的 GitHub 版本下载 l10nlint.zip 来安装 l10nlint。

设置

.l10nlint.yml 文件放在你的仓库根目录。base_path 是包含 Localizable.strings 的目录路径

示例

base_path: YourApp/Resources/

disabled_rules:
  - empty_value

todo:
  is_summary_enabled: true
  summary_violation_limit: 20

命令补全

此命令构建于 swift-argument-parser 之上。

请参考这篇文章

example 替换为 l10nlint

帮助

l10nlint --help

---
OVERVIEW: Lint tool for your Localizable.strings

USAGE: l10nlint [--config <config>] <subcommand>

OPTIONS:
  --config <config>       Custom config file path
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  lint (default)          Lint your Localizable.strings
  rules                   Show all rules whether enabled or disabled
  copy                    Copy keys your Base Localizable.strings

  See 'l10nlint help <subcommand>' for detailed help.
l10nlint rules --help

---
OVERVIEW: Show all rules whether enabled or disabled

USAGE: l10nlint rules [--config <config>] [--print-parameters]

OPTIONS:
  --config <config>       Custom config file path
  --print-parameters      Show your rule's parameters in config
  -h, --help              Show help information.