160 lines
5.6 KiB
Dart
160 lines
5.6 KiB
Dart
import 'app_localizations.dart';
|
|
|
|
extension AppLocalizationsHelpers on AppLocalizations {
|
|
String categoryLabel(String category) {
|
|
return switch (category.trim().toLowerCase()) {
|
|
'bier' || 'beer' => categoryBeer,
|
|
'wijn' || 'wine' => categoryWine,
|
|
'frisdrank' || 'soft drinks' => categorySoftDrinks,
|
|
'cocktails' => categoryCocktails,
|
|
'snacks' => categorySnacks,
|
|
'coffee' || 'koffie' => categoryCoffee,
|
|
'thee' || 'tea' => categoryTea,
|
|
'other' || 'overig' => categoryOther,
|
|
_ => category,
|
|
};
|
|
}
|
|
|
|
String localizedError(String? message) {
|
|
return switch (message) {
|
|
'Could not load bar screen.' => couldNotLoadBar,
|
|
'Could not create tab.' => couldNotCreateTabMessage,
|
|
'Product is out of stock.' => productOutOfStock,
|
|
'Could not add product to tab.' => couldNotAddProductToTab,
|
|
'Could not update item quantity.' => couldNotUpdateQuantity,
|
|
'Could not close tab.' => couldNotCloseTab,
|
|
'Could not rename tab.' => couldNotRenameTab,
|
|
'Could not delete tab.' => couldNotDeleteTab,
|
|
'Could not reload tabs.' => couldNotReloadTabs,
|
|
'Could not load tab history.' => couldNotLoadHistory,
|
|
'Could not load more tabs.' => couldNotLoadMoreTabs,
|
|
'Could not load products.' => couldNotLoadProducts,
|
|
'Could not add product.' => couldNotAddProduct,
|
|
'Could not update product.' => couldNotUpdateProduct,
|
|
'Could not check PIN status.' => couldNotCheckPinStatus,
|
|
'Could not save PIN.' => couldNotSavePin,
|
|
'Incorrect PIN.' => incorrectPin,
|
|
'Could not verify PIN.' => couldNotVerifyPin,
|
|
'Current PIN is incorrect.' => currentPinIncorrect,
|
|
'Could not load settings.' => couldNotLoadSettings,
|
|
'Could not save settings.' => couldNotSaveSettings,
|
|
'Could not load product.' => couldNotLoadProduct,
|
|
'Could not save product.' => couldNotSaveProduct,
|
|
'Could not delete product.' => couldNotDeleteProduct,
|
|
'Update failed' => updateFailed,
|
|
'Download failed' => downloadFailed,
|
|
'Installation failed' => installationFailed,
|
|
'Update already in progress' => updateAlreadyInProgress,
|
|
_ => message ?? genericError,
|
|
};
|
|
}
|
|
|
|
String updateStatus(String status) {
|
|
if (status.startsWith('Downloading ')) {
|
|
return downloading(status.substring('Downloading '.length));
|
|
}
|
|
|
|
return switch (status) {
|
|
'Preparing download…' => preparingDownload,
|
|
'Download failed' => downloadFailed,
|
|
'Installing update…' => installingUpdate,
|
|
'Update installed! Restarting…' => updateInstalledRestarting,
|
|
'Installation failed' => installationFailed,
|
|
'Update already running' => updateAlreadyRunning,
|
|
_ => status,
|
|
};
|
|
}
|
|
|
|
String updateError(String? message) {
|
|
if (message == null) return updateFailed;
|
|
if (message.startsWith('Download failed')) return downloadFailedWithDetail;
|
|
if (message.startsWith('Installation failed')) {
|
|
return installationFailedWithDetail;
|
|
}
|
|
if (message == 'Simulated download error (network timeout)') {
|
|
return simulatedDownloadError;
|
|
}
|
|
if (message == 'Update already in progress') return updateAlreadyInProgress;
|
|
|
|
return localizedError(message);
|
|
}
|
|
|
|
String devAction(String? message) {
|
|
if (message == null) return '';
|
|
|
|
final seeded = RegExp(
|
|
r'Seeded (?:default products )?\((\d+) total\)',
|
|
).firstMatch(message);
|
|
if (seeded != null) {
|
|
return devActionSeededProducts(int.parse(seeded.group(1)!));
|
|
}
|
|
|
|
final reseeded = RegExp(
|
|
r'Cleared and reseeded \((\d+) products\)',
|
|
).firstMatch(message);
|
|
if (reseeded != null) {
|
|
return devActionReseededProducts(int.parse(reseeded.group(1)!));
|
|
}
|
|
|
|
final resetStock = RegExp(
|
|
r'Reset stock for (\d+) products',
|
|
).firstMatch(message);
|
|
if (resetStock != null) {
|
|
return devActionResetStock(int.parse(resetStock.group(1)!));
|
|
}
|
|
|
|
final seededDemo = RegExp(
|
|
r'Seeded (\d+) demo products',
|
|
).firstMatch(message);
|
|
if (seededDemo != null) {
|
|
return devActionSeededProducts(int.parse(seededDemo.group(1)!));
|
|
}
|
|
|
|
final testTab = RegExp(
|
|
r'Created test tab with (\d+) items',
|
|
).firstMatch(message);
|
|
if (testTab != null) {
|
|
return devActionTestTab(int.parse(testTab.group(1)!));
|
|
}
|
|
|
|
final testProducts = RegExp(
|
|
r'Added (\d+) test products',
|
|
).firstMatch(message);
|
|
if (testProducts != null) {
|
|
return devActionTestProducts(int.parse(testProducts.group(1)!));
|
|
}
|
|
|
|
final lowStock = RegExp(
|
|
r'Simulated low stock for (\d+) products',
|
|
).firstMatch(message);
|
|
if (lowStock != null) {
|
|
return devActionLowStock(int.parse(lowStock.group(1)!));
|
|
}
|
|
|
|
final mockOrders = RegExp(
|
|
r'Generated (\d+) mock orders across (\d+) customers',
|
|
).firstMatch(message);
|
|
if (mockOrders != null) {
|
|
return devActionMockOrders(
|
|
int.parse(mockOrders.group(1)!),
|
|
int.parse(mockOrders.group(2)!),
|
|
);
|
|
}
|
|
|
|
return switch (message) {
|
|
'Cleared all open tabs' => devActionClearedOpenTabs,
|
|
'Cleared closed tab history' => devActionClearedHistory,
|
|
'Cleared all products' => devActionClearedProducts,
|
|
'Product images cleared' => devActionImagesCleared,
|
|
'PIN reset (no PIN required)' => devActionResetPin,
|
|
'No products to add to test tab' => devActionNoProducts,
|
|
'No products available — seed demo data first' => devActionNoProducts,
|
|
'Product images reloaded' => devActionImagesReloaded,
|
|
'Image cache cleared (no-op in debug mode)' => devActionCacheCleared,
|
|
_ when message.startsWith('Failed to clear images') =>
|
|
devActionFailedImages,
|
|
_ => message,
|
|
};
|
|
}
|
|
}
|