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:
Tizian 「ティツィアーン」 2026-10-19 18:47:25 +02:00
commit 96f2d14618
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64
2 changed files with 616 additions and 49 deletions

View file

@ -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);
});
}

View file

@ -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',
);
});
}