Skip to content

Instantly share code, notes, and snippets.

@stevenosse
Last active June 20, 2023 07:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenosse/64d863d0eb1ea8275eaec0f32d44e2a7 to your computer and use it in GitHub Desktop.
Save stevenosse/64d863d0eb1ea8275eaec0f32d44e2a7 to your computer and use it in GitHub Desktop.
I18n Checker
import 'dart:io';
void main(List<String> arguments) {
if (arguments.length < 2) {
// ignore: avoid_print
print('Usage: dart i18n_checker.dart <arb_folder> <reference_file>');
return;
}
final arbFolder = arguments[0];
final referenceFile = arguments[1];
checkFiles(arbFolder, referenceFile);
}
void checkFiles(String arbFolder, String referenceFile) {
final referenceContent = File(referenceFile).readAsLinesSync()
..removeLast()
..removeAt(0);
final i18nDir = Directory(arbFolder);
final files = i18nDir.listSync();
bool mismatchFound = false;
for (var line in referenceContent) {
final key = extractKeyFromLine(line);
for (var fileEntity in files) {
final file = File(fileEntity.path);
final found = file.readAsLinesSync().any((line) => line.contains(key));
if (!found) {
mismatchFound = true;
Logger.red.log('⚠️ - Key $key was not found in ${file.path}');
}
}
}
if (!mismatchFound) {
Logger.green.log('✅ - No difference detected');
}
}
String extractKeyFromLine(String line) {
return line.split(':').first.trim();
}
// From SO: https://stackoverflow.com/a/73988921
enum Logger {
red('31'),
green('32'),
yellow('33');
final String code;
const Logger(this.code);
// ignore: avoid_print
void log(dynamic text) => print('\x1B[${code}m$text\x1B[0m');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment