Skip to content

Allow audit command verify unused keys on json #767

@deandreamatias

Description

@deandreamatias

Thank you for the really helpful #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',
    };
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions