搜索插件、代码仓与 APP 分类

插件详情v0.2.1

translations_cleaner

用于删除所有翻译中未使用的键的包

macOSWindowsLinux
近 30 天下载
1.8万
喜欢数
42
Pub 分数
150

安装插件

flutter pub add translations_cleaner

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个专为 Flutter/Dart 设计的包,用于清理 ARB(App Resource Bundle)文件中多个语言翻译的未使用翻译键。它通过识别并删除代码库中不再引用的键,帮助保持本地化工作流程的整洁和高效。适用于管理大规模国际化应用的团队,可减少杂乱,并防止过时的翻译持续存在。该工具作为命令行实用程序运行,兼容 macOS、Windows 和 Linux。

适合场景

  • 删除过时的翻译键
  • 维护干净的 ARB 文件
  • 简化本地化工作流程
  • 防止翻译膨胀
  • 在CI/CD流水线中自动化清理

主要特点

  • 扫描所有 ARB 文件以查找未使用的键
  • 支持多语言 ARB 文件
  • 命令行界面
  • 跨平台兼容性
  • 与Flutter项目集成

适合对象

  • Flutter 开发人员管理翻译
  • 本地化团队
  • CI/CD 流水线
  • 频繁更改UI的项目
  • 使用 ARB 进行国际化的企业团队

使用建议

  • 删除前需要人工审核
  • 不处理动态键
  • 无 GUI 界面
  • 最佳用于开发或预发布环境
  • 在运行前备份 ARB 文件

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

translations_cleaner

Dart package to search and delete unused translations from .arb files, for all languages, all in one go.

NOTE : This package has been developed keeping flutter_localizations package in mind, which uses .arb files for all translations.

Package in action

Usage

# Add translations_cleaner as a dev dependency
dart pub add --dev translations_cleaner

dart run translations_cleaner <command> [arguments]
# OR
flutter pub run translations_cleaner <command> [arguments]

Commands Available
  • clean-translations - Search all the translations listed in arb files and delete the unused translations
  • list-unused-terms - Search all the translations listed in arb files and print/save a list of unused translations.
  • sort-translations - Sorts all the translations in arb files alphabetically.
Options Available

Available only for list-unused-terms

  • -a, --[no-]abort-on-unused - Abort execution if unused translations are found. This can be helpful in CI, if you don't want to proceed if a build should fail.

Available for clean-translations and list-unused-terms

  • -h, --help - Print this usage information.
  • -o, --output-path - Path for saving exported file, defaults to root path of the folder
  • -e, --[no-]export - Save unused keys as a .txt file in the path provided
  • -s, --include-subpackages - Include arb files from subpackages (directories with their own pubspec.yaml). By default, subpackages are excluded to avoid false positives in monorepo setups.

Why 🤔

Translations can be a very time consuming process when the app starts to scale and there are lots of translations. It is a good practice to clean out translations that are not being used. Checking for unused translations is tedious, hence this package.

How 🤖

  • translations_cleaner looks for all the .arb files located in the directory, and fetches all the translations, from all the languages.
  • Then it looks for all the .dart files.
  • It parses Dart files with AST and detects key usage from localization-style member access and matching top-level functions.
  • The translations not found in the dart files are removed from the corresponding .arb files, including any attributes as well
Detection: regex → AST

Unused keys used to be detected by scanning Dart files as raw text with word-boundary regex. That often marked keys as "used" when they only appeared in comments, string literals, or generated code (e.g. AppLocalizations getters). Detection is now AST-based: we parse each Dart file and only count a key as used when it appears as a member on a localization-like target (e.g. context.l10n.someKey, AppLocalizations.of(context).someKey) or as a top-level function call with the same name. That reduces false positives and aligns results with actual usage.

Performance
  • Regex (old): Single pass over file contents with precompiled patterns; very fast but prone to false positives.
  • AST (current): Each Dart file is parsed once; more work per file but only lib/**/*.dart is scanned. On large projects you may notice a few extra seconds; list-unused-terms prints timing so you can compare.

Limitations 😔

  • This package currently works only for l10n achieved via flutter_localizations, which uses .arb files.
  • There are other l10n packages which use .json and .yaml for saving translations. These are not supported currently

Bugs / issues

If you run into bugs or unexpected behavior, please open an issue: github.com/Chinmay-KB/translations_cleaner/issues

所属分类

依赖

依赖清单 4 项

源码仓库

使用此插件的项目