Files
plezy/test/i18n/app_locale_utils_test.dart
T
ad7ef112fc feat(i18n): add Hungarian and Traditional Chinese locales
Complete and revise every shipped locale against the current English source, preserve locale-specific plurals, and map script-specific Chinese locales through device, Intl, duration, and Plex boundaries.

Co-authored-by: emgeje <mgj@mgj.hu>

Co-authored-by: junyou1998 <junyou1998@gmail.com>
2026-07-24 07:30:43 +02:00

66 lines
2.2 KiB
Dart

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plezy/i18n/app_locale_utils.dart';
import 'package:plezy/i18n/strings.g.dart';
void main() {
group('resolvePreferredAppLocale', () {
test('uses explicit Chinese scripts before regions', () {
expect(
resolvePreferredAppLocale([
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant', countryCode: 'TW'),
]),
AppLocale.zhHant,
);
expect(
resolvePreferredAppLocale([
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans', countryCode: 'TW'),
]),
AppLocale.zh,
);
});
test('maps region-only Chinese locales to the expected script', () {
for (final region in const ['TW', 'HK', 'MO']) {
expect(resolvePreferredAppLocale([Locale('zh', region)]), AppLocale.zhHant, reason: region);
}
for (final region in const ['CN', 'SG']) {
expect(resolvePreferredAppLocale([Locale('zh', region)]), AppLocale.zh, reason: region);
}
});
test('preserves device preference order', () {
expect(
resolvePreferredAppLocale(const [
Locale('fr', 'FR'),
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant'),
]),
AppLocale.fr,
);
expect(
resolvePreferredAppLocale(const [Locale('xx'), Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant')]),
AppLocale.zhHant,
);
expect(
resolvePreferredAppLocale(const [Locale('zh'), Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hant')]),
AppLocale.zh,
);
});
});
group('AppLocaleExternalFormats', () {
test('preserves Traditional Chinese for downstream formatters and Plex', () {
expect(AppLocale.zhHant.intlLocaleName, 'zh_TW');
expect(AppLocale.zhHant.durationLocaleName, 'zh_Hant');
expect(AppLocale.zhHant.plexLanguageCode, 'zh-TW');
});
test('keeps existing locales on their language code', () {
expect(AppLocale.hu.intlLocaleName, 'hu');
expect(AppLocale.hu.durationLocaleName, 'hu');
expect(AppLocale.hu.plexLanguageCode, 'hu');
expect(AppLocale.zh.plexLanguageCode, 'zh');
});
});
}