feat(screenshots): localize sample variety & market names per shot language

This commit is contained in:
vjrj 2026-07-15 17:48:44 +02:00
parent 8ed1387792
commit ea17ced152
39 changed files with 68 additions and 39 deletions

View file

@ -71,6 +71,31 @@ Future<void> loadScreenshotFonts() async {
_fontsLoaded = true;
}
/// Localized sample labels so each screenshot reads in its own language. Family
/// names stay botanical Latin; only the human variety/offer names are localized.
/// English is the fallback (e.g. for `ja`, whose UI is itself partly English).
const sampleLabels = <String, Map<AppLocale, String>>{
// Inventory varieties
'maize': {AppLocale.en: 'Painted flint corn', AppLocale.es: 'Maíz rojo', AppLocale.fr: 'Maïs corné rouge', AppLocale.de: 'Roter Hartmais', AppLocale.pt: 'Milho pintado'},
'buckwheat': {AppLocale.en: 'Common buckwheat', AppLocale.es: 'Trigo sarraceno', AppLocale.fr: 'Sarrasin', AppLocale.de: 'Buchweizen', AppLocale.pt: 'Trigo-mourisco'},
'raspberry': {AppLocale.en: 'Wild raspberry', AppLocale.es: 'Frambuesa', AppLocale.fr: 'Framboise sauvage', AppLocale.de: 'Wilde Himbeere', AppLocale.pt: 'Framboesa'},
'tomato': {AppLocale.en: 'Slicing tomato', AppLocale.es: 'Tomate de ensalada', AppLocale.fr: 'Tomate à trancher', AppLocale.de: 'Fleischtomate', AppLocale.pt: 'Tomate para salada'},
'chilli': {AppLocale.en: 'Guajillo chilli', AppLocale.es: 'Chile guajillo', AppLocale.fr: 'Piment guajillo', AppLocale.de: 'Guajillo-Chili', AppLocale.pt: 'Pimenta guajillo'},
'origin': {AppLocale.en: 'Community seed swap', AppLocale.es: 'Intercambio de semillas', AppLocale.fr: 'Troc de graines', AppLocale.de: 'Saatgut-Tausch', AppLocale.pt: 'Troca de sementes'},
// Market offers
'cherryTomato': {AppLocale.en: 'Cherry tomato', AppLocale.es: 'Tomate cherry', AppLocale.fr: 'Tomate cerise', AppLocale.de: 'Kirschtomate', AppLocale.pt: 'Tomate-cereja'},
'bean': {AppLocale.en: 'Climbing bean', AppLocale.es: 'Judía de enrame', AppLocale.fr: 'Haricot à rames', AppLocale.de: 'Stangenbohne', AppLocale.pt: 'Feijão-trepador'},
'sunflower': {AppLocale.en: 'Sunflower', AppLocale.es: 'Girasol', AppLocale.fr: 'Tournesol', AppLocale.de: 'Sonnenblume', AppLocale.pt: 'Girassol'},
'basil': {AppLocale.en: 'Sweet basil', AppLocale.es: 'Albahaca', AppLocale.fr: 'Basilic', AppLocale.de: 'Basilikum', AppLocale.pt: 'Manjericão'},
'carrot': {AppLocale.en: 'Purple carrot', AppLocale.es: 'Zanahoria morada', AppLocale.fr: 'Carotte violette', AppLocale.de: 'Violette Karotte', AppLocale.pt: 'Cenoura roxa'},
};
/// The sample label for [key] in [locale], falling back to English.
String labelFor(String key, AppLocale locale) {
final m = sampleLabels[key]!;
return m[locale] ?? m[AppLocale.en]!;
}
const _fontFallbacks = <String>['Noto Sans JP', 'Noto Sans Arabic'];
/// The real app theme, but with every text style pinned to the bundled
@ -146,7 +171,9 @@ class SeededInventory {
Future<SeededInventory> seedShowcase(
AppDatabase db,
VarietyRepository repo,
AppLocale locale,
) async {
String l(String key) => labelFor(key, locale);
// Sow in spring, harvest seed in late summer visible in the calendar.
final sow = monthsToMask(const [3, 4, 5]);
final harvest = monthsToMask(const [8, 9]);
@ -174,16 +201,12 @@ Future<SeededInventory> seedShowcase(
Future<Uint8List> photo(String name) =>
File('test/screenshots/fixtures/$name.jpg').readAsBytes();
final maize = await add(
'Painted flint corn',
'Poaceae',
photo: await photo('maize'),
);
final maize = await add(l('maize'), 'Poaceae', photo: await photo('maize'));
await repo.addLot(
varietyId: maize,
harvestYear: 2024,
quantity: const Quantity(kind: QuantityKind.cob, count: 6),
originName: 'Community seed swap',
originName: l('origin'),
abundance: Abundance.plentyToShare,
offerStatus: OfferStatus.shared,
);
@ -196,10 +219,10 @@ Future<SeededInventory> seedShowcase(
// The rest sit in families that sort at/after Poaceae, so the maize stays the
// first, top-of-list group in the inventory shot. Each carries a CC0/PD photo.
await add('Common buckwheat', 'Polygonaceae', photo: await photo('buckwheat'));
await add('Wild raspberry', 'Rosaceae', photo: await photo('raspberry'));
await add('Slicing tomato', 'Solanaceae', photo: await photo('tomato'));
await add('Guajillo chilli', 'Solanaceae', photo: await photo('pepper'));
await add(l('buckwheat'), 'Polygonaceae', photo: await photo('buckwheat'));
await add(l('raspberry'), 'Rosaceae', photo: await photo('raspberry'));
await add(l('tomato'), 'Solanaceae', photo: await photo('tomato'));
await add(l('chilli'), 'Solanaceae', photo: await photo('pepper'));
return SeededInventory(maize);
}