Files
cutdex/test/localization_resources_test.dart
T
lingjhf 27e77fff39 feat: initial Cutdex application
Add the Flutter video editing application with project management, media
import, timeline editing, preview, AI assistance, diagnostics and settings.

Include shared UI and native host packages, platform runners, application
tests and release tooling.

Provide usage and contribution guides, the MIT license and third-party
notices. Exclude local credentials, build outputs and validation data.
2026-10-05 23:36:23 +08:00

94 lines
2.6 KiB
Dart

import 'dart:convert';
import 'dart:io';
import 'package:cutdex/features/settings/language_settings.dart';
import 'package:cutdex/l10n/app_localizations.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final template = _read('en');
final keys = template.keys.where((key) => !key.startsWith('@')).toSet();
final locales = [
'en',
'zh',
'zh_Hans',
'zh_Hant',
'ja',
'ko',
'fr',
'de',
'es',
'pt',
'it',
'ru',
];
for (final locale in locales) {
test(
'$locale has complete nonempty translations and unchanged parameters',
() {
final translations = _read(locale);
expect(translations['@@locale'], locale);
expect(
translations.keys.where((key) => !key.startsWith('@')).toSet(),
keys,
);
for (final key in keys) {
final value = translations[key] as String;
expect(value.trim(), isNotEmpty, reason: '$locale:$key');
expect(value, isNot(contains('ZXQ')), reason: '$locale:$key');
expect(
_parameters(value),
_parameters(template[key] as String),
reason: '$locale:$key',
);
// Preserve the names of formats, models, and diagnostic codes.
for (final term in [
'MCP',
'MP4',
'SRT',
'iTT',
'CEA-608',
'SCC',
'SubRip',
'Rec.709',
'HDR',
'SDR',
'MelBand',
'Whisper Turbo',
'notConfigured',
'noAudio',
'invalidResult',
'workerExited',
'processingFailed',
]) {
if ((template[key] as String).contains(term)) {
expect(value, contains(term), reason: '$locale:$key');
}
}
}
},
);
}
test('all eleven selectable locales have generated resource support', () {
final choices = AppLanguage.values.where(
(language) => language != AppLanguage.system,
);
expect(choices.length, 11);
for (final choice in choices) {
expect(AppLocalizations.supportedLocales, contains(choice.locale));
}
expect(AppLocalizations.supportedLocales.first.languageCode, 'en');
});
}
Map<String, dynamic> _read(String locale) =>
jsonDecode(File('lib/l10n/app_$locale.arb').readAsStringSync())
as Map<String, dynamic>;
Set<String> _parameters(String value) =>
RegExp(r'\{(\w+)(?:\}|,)')
.allMatches(value)
.map((match) => match[1]!)
.toSet();