UnusedL10nCommand class
Analyzes unused localization keys across all packages in the project.
The UnusedL10nCommand scans all ARB (Application Resource Bundle) files to extract localization keys, then searches through all Dart files in parallel to identify which keys are not being used in the codebase. It respects concurrency settings from morpheme.yaml for optimal performance.
Usage
Basic unused localization analysis (with presentation folder filtering):
morpheme unused-l10n
Search all Dart files without filtering:
morpheme unused-l10n --no-filter-presentation
Automatically remove unused keys from ARB files:
morpheme unused-l10n --auto-remove
Auto-remove with backup files:
morpheme unused-l10n --auto-remove --backup
Auto-remove without confirmation prompt:
morpheme unused-l10n --auto-remove --confirm
With custom configuration:
morpheme unused-l10n --morpheme-yaml custom/path/morpheme.yaml
Configuration
The command reads concurrency settings from morpheme.yaml:
concurrent: 4 # Number of parallel file processing tasks
Auto-Remove Feature
When --auto-remove is enabled, the command will:
- Show a confirmation prompt (unless --confirm is used)
- Optionally create backup files with .backup extension (if --backup is used)
- Remove unused keys from all ARB files
- Preserve all metadata entries (@-prefixed keys)
- Report the number of files modified and keys removed
Safety Considerations
- By default, no backup files are created to avoid cluttering the workspace
- Use
--backupflag when you want to preserve original ARB files - Backup files use
.arb.backupextension and can be restored if needed
Backup files can be restored using:
find . -name "*.arb.backup" -exec sh -c 'mv "$1" "${1%.backup}"' _ {} \;
Filtering Behavior
By default, the command filters feature packages to only search in presentation folders (lib/presentation/**), while searching all files in non-feature packages. This optimization focuses on UI-related code where localization is typically used.
Feature packages are identified by having lib/presentation, lib/data, or lib/domain directories. Use --no-filter-presentation to disable this behavior.
Output
- Displays progress of file analysis
- Reports unused localization keys with counts
- Shows detailed analysis results
- If --auto-remove is used, shows removal progress and results
Performance
- Uses parallel processing for scanning Dart files
- Searches all .dart files in the project (not just lib/**)
- Optimized regex patterns for localization usage detection
- True isolate-based parallelism for handling 15k+ files
Dependencies
- Uses ModularHelper for package discovery
- Requires valid ARB files for localization keys
- Supports both modular and traditional project structures
Exceptions
Throws FileSystemException if ARB files cannot be read or modified. Throws FormatException if ARB files contain invalid JSON. Throws ProcessException if file processing fails.
Constructors
- UnusedL10nCommand()
- Creates a new instance of UnusedL10nCommand.
Properties
-
aliases
→ List<
String> -
Alternate names for this command.
no setterinherited
- argParser → ArgParser
-
The argument parser for this command.
no setterinherited
- argResults → ArgResults?
-
The parsed argument results for this command.
no setterinherited
- category → String
-
The command's category.
no setteroverride
- description → String
-
A description of this command, included in usage.
no setteroverride
- globalResults → ArgResults?
-
The parsed global argument results.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
-
Whether or not this command should be hidden from help listings.
no setterinherited
- invocation → String
-
A single-line template for how to invoke this command (e.g.
"pub getpackage").no setterinherited - name → String
-
The name of this command.
no setteroverride
- parent → Command?
-
The command's parent command, if this is a subcommand.
no setterinherited
- runner → CommandRunner?
-
The command runner for this command.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
subcommands
→ Map<
String, Command> -
An unmodifiable view of all sublevel commands of this command.
no setterinherited
-
suggestionAliases
→ List<
String> -
Alternate non-functional names for this command.
no setterinherited
- summary → String
-
A short description of this command, included in parent's
CommandRunner.usage.
no setterinherited
- takesArguments → bool
-
Whether or not this command takes positional arguments in addition to
options.
no setterinherited
- usage → String
-
Generates a string displaying usage information for this command.
no setterinherited
-
An optional footer for usage.
no setterinherited
Methods
-
addSubcommand(
Command command) → void -
Adds Command as a subcommand of this.
inherited
-
calculateOptimalConcurrency(
int fileCount, int requestedConcurrency) → int -
combineResults(
Set< String> translationTerms, List<ProcessingResult> results) → Set<String> -
compileRegexPatterns(
Set< String> translationTerms) → Map<String, RegExp> -
createOptimizedChunks(
List< String> files, int chunkCount) → List<List< String> > -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
printUsage(
) → void -
Prints the usage information for this command.
inherited
-
run(
) → void -
Runs this command.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
usageException(
String message) → Never -
Throws a UsageException with
message.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited