mirror of
https://github.com/chenasraf/pantry-flutter.git
synced 2026-05-17 17:28:03 +00:00
34 lines
924 B
Dart
34 lines
924 B
Dart
// ignore_for_file: avoid_print
|
|
|
|
import 'dart:io';
|
|
|
|
/// Replaces YAML unicode escape sequences (\uXXXX, \xXX) with actual UTF-8
|
|
/// characters in all messages*.i18n.yaml files.
|
|
void main() {
|
|
final yamlFiles = Directory('lib').listSync().whereType<File>().where(
|
|
(f) => RegExp(r'messages.*\.i18n\.yaml$').hasMatch(f.path),
|
|
);
|
|
|
|
final uEscape = RegExp(r'\\u([0-9a-fA-F]{4})');
|
|
final xEscape = RegExp(r'\\x([0-9a-fA-F]{2})');
|
|
|
|
for (final file in yamlFiles) {
|
|
var content = file.readAsStringSync();
|
|
final original = content;
|
|
|
|
content = content.replaceAllMapped(
|
|
uEscape,
|
|
(m) => String.fromCharCode(int.parse(m.group(1)!, radix: 16)),
|
|
);
|
|
content = content.replaceAllMapped(
|
|
xEscape,
|
|
(m) => String.fromCharCode(int.parse(m.group(1)!, radix: 16)),
|
|
);
|
|
|
|
if (content != original) {
|
|
file.writeAsStringSync(content);
|
|
print('Fixed: ${file.path}');
|
|
}
|
|
}
|
|
}
|