easy_localization icon indicating copy to clipboard operation
easy_localization copied to clipboard

Allow audit command verify unused keys on json

Open deandreamatias opened this issue 4 months ago • 1 comments

Thank you for the really helpful https://github.com/aissat/easy_localization/pull/763!

I really loved if can extend the audit command to use for verify unused translations on json file.

I experimented and maybe this is a way:

  1. Using audit_command.dart base file, modify this lines
const _preservedKeywords = [
  'few',
  'many',
  'one',
  'other',
  'two',
  'zero',
  'male',
  'female',
];

class AuditCommand {
...
      final missing = keysInFile.difference(usedKeys);
      final preserved = missing
          .where((key) => !_preservedKeywords.any(key.contains))
          .toList();
      final missingWithVariables = preserved
          .where((key) => key.contains('\$'))
          .toList();
      final missingWithoutVariables = preserved
          .where((key) => !key.contains('\$'))
          .toList();
...
}

Need to improve to handle better the plurals, gender and also some false positives like when the key and tr isn't on same line:

Text(
      context.tr(
        position.nameTranslated,
        gender: gender.name,
      ),
)
...
extension PositionExtension on Position {
  String get nameTranslated {
    return switch (this) {
      Position.manager => 'teams.manager_staff_label',
      Position.assistantManager => 'teams.assistant_manager_staff_label',
      Position.goalkeeperManager => 'teams.goalkeeper_manager_staff_label',
      Position.physio => 'teams.physio_staff_label',
      Position.doctor => 'teams.doctor_staff_label',
      Position.delegate => 'teams.delegate_staff_label',
      Position.other => 'teams.other_staff_label',
    };
  }
}

deandreamatias avatar Jul 31 '25 11:07 deandreamatias

Hello,

I will explore this possibility when i have some time. It was part of the command at start but because of the false positives i stripped it to only handle missing keys as i was missing free time to do it !

Feel free to contribute if you have the time ! ;)

JavedNicolas avatar Dec 02 '25 15:12 JavedNicolas