From 02cf76aca599c736e24ba20592740090886c993b Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 22 Nov 2026 23:19:37 +1100 Subject: [PATCH] Fix hard-coded strings (#938) --- lib/api_form.dart | 6 +-- lib/inventree/stock.dart | 6 +-- lib/l10n/app_en.arb | 68 +++++++++++++++++++++++++++++- lib/settings/about.dart | 4 +- lib/widget/fields.dart | 2 +- lib/widget/order/po_line_list.dart | 2 +- lib/widget/order/so_line_list.dart | 2 +- lib/widget/part/image_cropper.dart | 6 +-- test/model_json_test.dart | 15 +++++++ 9 files changed, 97 insertions(+), 14 deletions(-) diff --git a/lib/api_form.dart b/lib/api_form.dart index 6c4c959c..f7c786b5 100644 --- a/lib/api_form.dart +++ b/lib/api_form.dart @@ -315,7 +315,7 @@ class APIFormField { default: return ListTile( title: Text( - "Unsupported field type: '${type}' for field '${name}'", + L10().unsupportedFieldType(type, name), style: TextStyle(color: COLOR_DANGER, fontStyle: FontStyle.italic), ), ); @@ -833,10 +833,10 @@ class APIFormField { default: return ListTile( title: Text( - "Unsupported model", + L10().unsupportedModel, style: TextStyle(fontWeight: FontWeight.bold, color: COLOR_DANGER), ), - subtitle: Text("Model '${model}' rendering not supported"), + subtitle: Text(L10().unsupportedModelDetail(model)), ); } } diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index a84de769..d9e29793 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -470,7 +470,7 @@ class InvenTreeStockItem extends InvenTreeModel { String serialOrQuantityDisplay() { if (isSerialized()) { - return "SN ${serialNumber}"; + return L10().serialNumberShort(serialNumber); } else if (allocated > 0) { return "${available} / ${quantity}"; } else { @@ -480,7 +480,7 @@ class InvenTreeStockItem extends InvenTreeModel { String get locationName { if (locationId == -1 || !jsondata.containsKey("location_detail")) { - return "Unknown Location"; + return L10().locationUnknown; } String loc = getString("name", subKey: "location_detail"); @@ -656,7 +656,7 @@ class InvenTreeStockLocation extends InvenTreeModel { String p = psplit.join("/"); if (p.isEmpty) { - p = "Top level stock location"; + p = L10().stockTopLevel; } return p; diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index 4e4fdbe8..04d41e95 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -2119,5 +2119,71 @@ "@currency": {}, "priceBreaks": "Price Breaks", - "@priceBreaks": {} + "@priceBreaks": {}, + + "appBuild": "Build", + "@appBuild": { + "description": "Application build number label (e.g. 1.2.3 - Build 45)" + }, + + "locationUnknown": "Unknown Location", + "@locationUnknown": {}, + + "partDetailMissing": "Missing part detail", + "@partDetailMissing": {}, + + "quantityExceedsMax": "Quantity must not exceed {max}", + "@quantityExceedsMax": { + "placeholders": { + "max": { + "type": "String" + } + } + }, + + "reset": "Reset", + "@reset": {}, + + "serialNumberShort": "SN {serial}", + "@serialNumberShort": { + "description": "Abbreviated serial number", + "placeholders": { + "serial": { + "type": "String" + } + } + }, + + "supplierPartMissing": "Supplier part not defined", + "@supplierPartMissing": {}, + + "unsupportedFieldType": "Unsupported field type: '{type}' for field '{field}'", + "@unsupportedFieldType": { + "placeholders": { + "type": { + "type": "String" + }, + "field": { + "type": "String" + } + } + }, + + "unsupportedModel": "Unsupported model", + "@unsupportedModel": {}, + + "unsupportedModelDetail": "Rendering not supported for model '{model}'", + "@unsupportedModelDetail": { + "placeholders": { + "model": { + "type": "String" + } + } + }, + + "zoomIn": "Zoom In", + "@zoomIn": {}, + + "zoomOut": "Zoom Out", + "@zoomOut": {} } diff --git a/lib/settings/about.dart b/lib/settings/about.dart index ff5a151c..5dba07f2 100644 --- a/lib/settings/about.dart +++ b/lib/settings/about.dart @@ -208,7 +208,9 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( title: Text(L10().version), - subtitle: Text("${info.version} - Build ${info.buildNumber}"), + subtitle: Text( + "${info.version} - ${L10().appBuild} ${info.buildNumber}", + ), leading: Icon(TablerIcons.info_circle), trailing: UpdateChecker().newVersionAvailable ? Icon(TablerIcons.alert_circle, color: COLOR_WARNING) diff --git a/lib/widget/fields.dart b/lib/widget/fields.dart index ac51f90d..354c7888 100644 --- a/lib/widget/fields.dart +++ b/lib/widget/fields.dart @@ -208,7 +208,7 @@ class QuantityField extends TextFormField { if (quantity <= 0) return L10().quantityPositive; if ((max != null) && (quantity > max)) { - return "Quantity must not exceed ${max}"; + return L10().quantityExceedsMax(max.toString()); } return null; diff --git a/lib/widget/order/po_line_list.dart b/lib/widget/order/po_line_list.dart index 7dbafd5a..2c2d9c36 100644 --- a/lib/widget/order/po_line_list.dart +++ b/lib/widget/order/po_line_list.dart @@ -101,7 +101,7 @@ class _PaginatedPOLineListState return ListTile( title: Text(L10().error), subtitle: Text( - "supplier part not defined", + L10().supplierPartMissing, style: TextStyle(color: COLOR_DANGER), ), ); diff --git a/lib/widget/order/so_line_list.dart b/lib/widget/order/so_line_list.dart index acadfeb1..c928c050 100644 --- a/lib/widget/order/so_line_list.dart +++ b/lib/widget/order/so_line_list.dart @@ -86,7 +86,7 @@ class _PaginatedSOLineListState return ListTile( title: Text(L10().error), subtitle: Text( - "Missing part detail", + L10().partDetailMissing, style: TextStyle(color: COLOR_DANGER), ), ); diff --git a/lib/widget/part/image_cropper.dart b/lib/widget/part/image_cropper.dart index a3236d2a..58644ada 100644 --- a/lib/widget/part/image_cropper.dart +++ b/lib/widget/part/image_cropper.dart @@ -69,7 +69,7 @@ class _ImageCropperWidgetState extends State { IconButton( icon: Icon(TablerIcons.refresh), onPressed: () => cropController.reset(), - tooltip: "Reset", + tooltip: L10().reset, ), // Zoom out button - scales to 75% of current size @@ -77,7 +77,7 @@ class _ImageCropperWidgetState extends State { icon: Icon(TablerIcons.zoom_out), onPressed: () => cropController.addTransition(CropImageData(scale: 0.75)), - tooltip: "Zoom Out", + tooltip: L10().zoomOut, ), // Zoom in button - scales to 133% of current size @@ -85,7 +85,7 @@ class _ImageCropperWidgetState extends State { icon: Icon(TablerIcons.zoom_in), onPressed: () => cropController.addTransition(CropImageData(scale: 1.33)), - tooltip: "Zoom In", + tooltip: L10().zoomIn, ), // Rotate button diff --git a/test/model_json_test.dart b/test/model_json_test.dart index 1a179cc5..7b2cb763 100644 --- a/test/model_json_test.dart +++ b/test/model_json_test.dart @@ -238,6 +238,21 @@ void main() { }); }); + group("Stock Location:", () { + test("Path", () async { + var location = InvenTreeStockLocation.fromJson({ + "pathstring": "Warehouse/Shelf/Bin", + }); + + expect(location.parentPathString, equals("Warehouse/Shelf")); + + location = InvenTreeStockLocation.fromJson({"pathstring": "Warehouse"}); + + // Translated string (previously hard-coded) + expect(location.parentPathString, equals(L10().stockTopLevel)); + }); + }); + group("Part:", () { test("Full Name", () async { expect(