搜尋套件、儲存庫與 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 項

原始碼儲存庫

使用此套件的專案