translations_cleaner
すべての翻訳にわたってARBファイル内の未使用キーを削除するパッケージ
ARB ファイルから未使用の翻訳を削除するためのDartパッケージ。
以下は英語原文のスナップショットです。最新版は GitHub をご覧ください。
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_localizationspackage in mind, which uses.arbfiles for all translations.
Package in action
# 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]
clean-translations - Search all the translations listed in arb files and delete the unused translationslist-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.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.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.
translations_cleaner looks for all the .arb files located in the directory, and fetches all the translations, from all the languages..dart files..arb files, including any attributes as wellUnused 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.
lib/**/*.dart is scanned. On large projects you may notice a few extra seconds; list-unused-terms prints timing so you can compare.flutter_localizations, which uses .arb files..json and .yaml for saving translations. These are not supported currentlyIf you run into bugs or unexpected behavior, please open an issue: github.com/Chinmay-KB/translations_cleaner/issues