halkyon_app: data locations as precise as a country or a state
An operator's DATA_LOCATION and BACKUP_LOCATION may name a subdivision
(ISO 3166-2, US-CA, DE-BY) besides the EU or a country. The app adds
"(EU)" to a member country and the country to a subdivision ("Germany
(EU)", "California, United States", "Bavaria, Germany (EU)"), in
English and German, and shows the most specific flag there is: a
subdivision's own where the flag package has one, else its country's.
Subdivision names come from Unicode CLDR 48.2 (tool/subdivision_names.py),
bundled with their licence, which the app registers.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
parent
e23cc77f7c
commit
96f2d14618
5 changed files with 616 additions and 49 deletions
26
packages/halkyon_app/test/instance/cldr_license_test.dart
Normal file
26
packages/halkyon_app/test/instance/cldr_license_test.dart
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
test("Unicode CLDR's notice joins the licence list with the flags', as "
|
||||
'their licences ask', () async {
|
||||
registerHalkyonAppLicenses();
|
||||
|
||||
final notices = {
|
||||
await for (final entry in LicenseRegistry.licenses)
|
||||
for (final package in entry.packages)
|
||||
package: entry.paragraphs
|
||||
.map((paragraph) => paragraph.text)
|
||||
.join('\n'),
|
||||
};
|
||||
expect(notices['Unicode CLDR'], contains('UNICODE LICENSE V3'));
|
||||
expect(notices['Unicode CLDR'], contains('Unicode, Inc.'));
|
||||
expect(
|
||||
notices['flag-icons'],
|
||||
contains('Copyright (c) 2013 Panayiotis Lipiridis'),
|
||||
);
|
||||
});
|
||||
}
|
||||
14
packages/halkyon_app/test/instance/european_union_test.dart
Normal file
14
packages/halkyon_app/test/instance/european_union_test.dart
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
|
||||
void main() {
|
||||
test("the European Union's members are its 27 states, each by the code "
|
||||
"ISO gives it (Greece as GR, not the Union's own EL)", () {
|
||||
expect(europeanUnionMembers, {
|
||||
'AT', 'BE', 'BG', 'CY', 'CZ', 'DE', 'DK', 'EE', 'ES', 'FI', 'FR', //
|
||||
'GR', 'HR', 'HU', 'IE', 'IT', 'LT', 'LU', 'LV', 'MT', 'NL', 'PL', //
|
||||
'PT', 'RO', 'SE', 'SI', 'SK',
|
||||
});
|
||||
expect(europeanUnionMembers, hasLength(27));
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
|
||||
void main() {
|
||||
test('a subdivision is named in the language asked for, else in English, '
|
||||
'and one without a name not at all', () async {
|
||||
const names = MemorySubdivisionNames({
|
||||
'US-CA': {'en': 'California', 'de': 'Kalifornien'},
|
||||
'US-TX': {'en': 'Texas'},
|
||||
});
|
||||
|
||||
expect(await names.nameOf('US-CA', 'de'), 'Kalifornien');
|
||||
expect(await names.nameOf('us-ca', 'de'), 'Kalifornien');
|
||||
expect(await names.nameOf('US-TX', 'de'), 'Texas');
|
||||
expect(await names.nameOf('US-ZZ', 'en'), isNull);
|
||||
});
|
||||
|
||||
testWidgets("Unicode CLDR's names come with the package, in English and "
|
||||
'German', (tester) async {
|
||||
final names = await tester.runAsync(
|
||||
() async => (
|
||||
en: await const AssetSubdivisionNames().nameOf('US-CA', 'en'),
|
||||
de: await const AssetSubdivisionNames().nameOf('US-CA', 'de'),
|
||||
texas: await const AssetSubdivisionNames().nameOf('US-TX', 'de'),
|
||||
scotland: await const AssetSubdivisionNames().nameOf('GB-SCT', 'de'),
|
||||
unknown: await const AssetSubdivisionNames().nameOf('US-ZZ', 'en'),
|
||||
),
|
||||
);
|
||||
|
||||
expect(names?.en, 'California');
|
||||
expect(names?.de, 'Kalifornien');
|
||||
expect(names?.texas, 'Texas', reason: 'German as English, kept once');
|
||||
expect(names?.scotland, 'Schottland');
|
||||
expect(names?.unknown, isNull);
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
import 'package:flag/flag.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:halkyon_app/halkyon_app.dart';
|
||||
import 'package:material_ui/material_ui.dart';
|
||||
|
||||
void main() {
|
||||
test("a place shows the most specific flag there is: a subdivision's own, "
|
||||
"else its country's, and the European Union's", () {
|
||||
expect(flagCodeOf('EU'), 'eu');
|
||||
expect(flagCodeOf('DE'), 'de');
|
||||
expect(flagCodeOf('CH'), 'ch');
|
||||
expect(flagCodeOf('DE-BY'), 'de');
|
||||
expect(flagCodeOf('US-CA'), 'us');
|
||||
expect(flagCodeOf('GB-SCT'), 'gb_sct');
|
||||
expect(flagCodeOf('ES-CT'), 'es_ct');
|
||||
expect(flagCodeOf('DE-ZZ'), 'de');
|
||||
});
|
||||
|
||||
test('a place without a flag shows none', () {
|
||||
expect(flagCodeOf('QQ'), isNull);
|
||||
expect(flagCodeOf('QQ-AB'), isNull);
|
||||
});
|
||||
|
||||
testWidgets("a state shows its country's flag, a place without one "
|
||||
'nothing', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const Directionality(
|
||||
textDirection: TextDirection.ltr,
|
||||
child: Row(
|
||||
children: [InstanceFlag('US-CA'), InstanceFlag('QQ-AB')],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(Flag), findsOne);
|
||||
});
|
||||
}
|
||||
|
|
@ -6,7 +6,15 @@ import 'package:halkyon_app/l10n/halkyon_app_localizations_en.dart';
|
|||
void main() {
|
||||
final en = HalkyonAppLocalizationsEn();
|
||||
final de = HalkyonAppLocalizationsDe();
|
||||
const names = {'CH': 'Switzerland', 'DE': 'Germany'};
|
||||
const names = {
|
||||
'CH': 'Switzerland',
|
||||
'DE': 'Germany',
|
||||
'GB': 'United Kingdom',
|
||||
'US': 'United States',
|
||||
'DE-BY': 'Bavaria',
|
||||
'GB-SCT': 'Scotland',
|
||||
'US-CA': 'California',
|
||||
};
|
||||
String? words(InstanceLocations locations) =>
|
||||
instanceLocationWords(en, locations, names);
|
||||
|
||||
|
|
@ -15,6 +23,10 @@ void main() {
|
|||
words(const InstanceLocations(data: 'EU', backups: 'EU')),
|
||||
'Data and backups: European Union',
|
||||
);
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'DE-BY', backups: 'DE-BY')),
|
||||
'Data and backups: Bavaria, Germany (EU)',
|
||||
);
|
||||
});
|
||||
|
||||
test('data and backups apart are named a line each', () {
|
||||
|
|
@ -24,6 +36,28 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('a member of the European Union says so after its name; another '
|
||||
'country is named alone', () {
|
||||
expect(words(const InstanceLocations(data: 'DE')), 'Data: Germany (EU)');
|
||||
expect(words(const InstanceLocations(data: 'CH')), 'Data: Switzerland');
|
||||
});
|
||||
|
||||
test('a subdivision is named with its country, a member of the European '
|
||||
'Union saying so', () {
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'DE-BY')),
|
||||
'Data: Bavaria, Germany (EU)',
|
||||
);
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'US-CA')),
|
||||
'Data: California, United States',
|
||||
);
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'GB-SCT')),
|
||||
'Data: Scotland, United Kingdom',
|
||||
);
|
||||
});
|
||||
|
||||
test('an instance keeping no backups says so', () {
|
||||
expect(
|
||||
words(
|
||||
|
|
@ -37,7 +71,6 @@ void main() {
|
|||
});
|
||||
|
||||
test('what the instance leaves unsaid is left out', () {
|
||||
expect(words(const InstanceLocations(data: 'DE')), 'Data: Germany');
|
||||
expect(
|
||||
words(const InstanceLocations(backups: 'CH')),
|
||||
'Backups: Switzerland',
|
||||
|
|
@ -45,8 +78,12 @@ void main() {
|
|||
expect(words(const InstanceLocations()), isNull);
|
||||
});
|
||||
|
||||
test('a country without a name here goes by its code', () {
|
||||
test('a country or subdivision without a name here goes by its code', () {
|
||||
expect(words(const InstanceLocations(data: 'XK')), 'Data: XK');
|
||||
expect(
|
||||
words(const InstanceLocations(data: 'DE-ZZ')),
|
||||
'Data: DE-ZZ, Germany (EU)',
|
||||
);
|
||||
});
|
||||
|
||||
test('in German too, without the articles some countries take', () {
|
||||
|
|
@ -58,5 +95,21 @@ void main() {
|
|||
),
|
||||
'Daten: Europäische Union\nSicherungen: Schweiz',
|
||||
);
|
||||
expect(
|
||||
instanceLocationWords(
|
||||
de,
|
||||
const InstanceLocations(data: 'DE-BY', backups: 'FI'),
|
||||
const {'DE': 'Deutschland', 'DE-BY': 'Bayern', 'FI': 'Finnland'},
|
||||
),
|
||||
'Daten: Bayern, Deutschland (EU)\nSicherungen: Finnland (EU)',
|
||||
);
|
||||
expect(
|
||||
instanceLocationWords(
|
||||
de,
|
||||
const InstanceLocations(data: 'US-CA', backups: 'US-CA'),
|
||||
const {'US': 'Vereinigte Staaten', 'US-CA': 'Kalifornien'},
|
||||
),
|
||||
'Daten und Sicherungen: Kalifornien, Vereinigte Staaten',
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue