From 2a3e83509f17fd0df542c1b4d8f234f2b74b4c2e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 19 May 2021 23:33:28 +1000 Subject: [PATCH] Refactor of translation lookup! --- lib/api.dart | 63 ++++++++++----------- lib/barcode.dart | 56 +++++++++---------- lib/inventree/stock.dart | 17 +++--- lib/l10.dart | 9 +++ lib/main.dart | 4 +- lib/settings/about.dart | 37 ++++++------- lib/settings/app_settings.dart | 27 ++++----- lib/settings/login.dart | 31 ++++++----- lib/settings/release.dart | 7 +-- lib/settings/settings.dart | 29 +++++----- lib/widget/category_display.dart | 34 ++++++------ lib/widget/company_detail.dart | 19 +++---- lib/widget/dialogs.dart | 37 ++++++------- lib/widget/drawer.dart | 16 +++--- lib/widget/fields.dart | 21 ++++--- lib/widget/home.dart | 36 ++++++------ lib/widget/location_display.dart | 32 +++++------ lib/widget/paginator.dart | 6 +- lib/widget/part_detail.dart | 48 ++++++++-------- lib/widget/part_notes.dart | 7 +-- lib/widget/search.dart | 32 +++++------ lib/widget/snacks.dart | 5 +- lib/widget/starred_parts.dart | 8 +-- lib/widget/stock_detail.dart | 74 ++++++++++++------------- lib/widget/stock_item_test_results.dart | 31 +++++------ lib/widget/stock_notes.dart | 6 +- 26 files changed, 339 insertions(+), 353 deletions(-) create mode 100644 lib/l10.dart diff --git a/lib/api.dart b/lib/api.dart index a2371014..9a3c9c33 100644 --- a/lib/api.dart +++ b/lib/api.dart @@ -2,16 +2,15 @@ import 'dart:async'; import 'dart:convert'; import 'dart:io'; -import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/user_profile.dart'; import 'package:InvenTree/widget/snacks.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:flutter_cache_manager/flutter_cache_manager.dart'; import 'package:InvenTree/widget/dialogs.dart'; +import 'package:InvenTree/l10.dart'; import 'package:http/http.dart' as http; import 'package:one_context/one_context.dart'; @@ -119,7 +118,7 @@ class InvenTreeAPI { if (!isConnected()) { showSnackIcon( - I18N.of(context).notConnected, + L10().notConnected, success: false, icon: FontAwesomeIcons.server ); @@ -227,8 +226,8 @@ class InvenTreeAPI { if (data == null || !data.containsKey("server") || !data.containsKey("version") || !data.containsKey("instance")) { showServerError( - I18N.of(ctx).missingData, - I18N.of(ctx).serverMissingData, + L10().missingData, + L10().serverMissingData, ); return false; @@ -243,17 +242,17 @@ class InvenTreeAPI { if (_apiVersion < _minApiVersion) { - String message = I18N.of(ctx).serverApiVersion + ": ${_apiVersion}"; + String message = L10().serverApiVersion + ": ${_apiVersion}"; message += "\n"; - message += I18N.of(ctx).serverApiRequired + ": ${_minApiVersion}"; + message += L10().serverApiRequired + ": ${_minApiVersion}"; message += "\n\n"; message += "Ensure your InvenTree server version is up to date!"; showServerError( - I18N.of(OneContext().context).serverOld, + L10().serverOld, message ); @@ -282,8 +281,8 @@ class InvenTreeAPI { case 401: case 403: showServerError( - I18N.of(ctx).serverAuthenticationError, - I18N.of(ctx).invalidUsernamePassword, + L10().serverAuthenticationError, + L10().invalidUsernamePassword, ); break; default: @@ -298,8 +297,8 @@ class InvenTreeAPI { if (data == null || !data.containsKey("token")) { showServerError( - I18N.of(OneContext().context).tokenMissing, - I18N.of(OneContext().context).tokenMissingFromResponse, + L10().tokenMissing, + L10().tokenMissingFromResponse, ); return false; @@ -338,7 +337,7 @@ class InvenTreeAPI { if (profile == null) { showSnackIcon( - I18N.of(OneContext().context).profileSelect, + L10().profileSelect, success: false, icon: FontAwesomeIcons.exclamationCircle ); @@ -355,7 +354,7 @@ class InvenTreeAPI { if (_connected) { showSnackIcon( - I18N.of(OneContext().context).serverConnected, + L10().serverConnected, icon: FontAwesomeIcons.server, success: true, ); @@ -436,14 +435,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N.of(ctx).connectionRefused, + L10().connectionRefused, error.toString(), ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N.of(ctx).serverError, + L10().serverError, error.toString() ); } @@ -477,18 +476,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N - .of(ctx) - .connectionRefused, + L10().connectionRefused, error.toString() ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N - .of(ctx) - .serverError, + L10().serverError, error.toString() ); } @@ -558,14 +553,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N.of(ctx).connectionRefused, + L10().connectionRefused, error.toString() ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N.of(ctx).serverError, + L10().serverError, error.toString() ); } @@ -600,14 +595,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N.of(ctx).connectionRefused, + L10().connectionRefused, error.toString() ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N.of(ctx).serverError, + L10().serverError, error.toString() ); } @@ -643,8 +638,8 @@ class InvenTreeAPI { return true; } else { showServerError( - I18N.of(OneContext().context).serverCertificateError, - I18N.of(OneContext().context).serverCertificateInvalid, + L10().serverCertificateError, + L10().serverCertificateInvalid, ); return false; } @@ -696,14 +691,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N.of(ctx).connectionRefused, + L10().connectionRefused, error.toString() ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N.of(ctx).serverError, + L10().serverError, error.toString() ); } @@ -730,14 +725,14 @@ class InvenTreeAPI { if (error is SocketException) { showServerError( - I18N.of(ctx).connectionRefused, + L10().connectionRefused, error.toString() ); } else if (error is TimeoutException) { showTimeoutError(ctx); } else { showServerError( - I18N.of(ctx).serverError, + L10().serverError, error.toString() ); } @@ -766,8 +761,8 @@ class InvenTreeAPI { print("${body}"); showServerError( - I18N.of(OneContext().context).formatException, - I18N.of(OneContext().context).formatExceptionJson + ":\n${body}" + L10().formatException, + L10().formatExceptionJson + ":\n${body}" ); return null; } diff --git a/lib/barcode.dart b/lib/barcode.dart index 0e5c73ea..d40da535 100644 --- a/lib/barcode.dart +++ b/lib/barcode.dart @@ -11,7 +11,7 @@ import 'package:qr_code_scanner/qr_code_scanner.dart'; import 'package:InvenTree/inventree/stock.dart'; import 'package:InvenTree/inventree/part.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import 'package:InvenTree/api.dart'; @@ -70,7 +70,7 @@ class BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeNoMatch, + L10().barcodeNoMatch, success: false, icon: FontAwesomeIcons.qrcode ); @@ -81,7 +81,7 @@ class BarcodeHandler { failureTone(); // Called when the server returns an unhandled response - showServerError(I18N.of(OneContext().context).responseUnknown, data.toString()); + showServerError(L10().responseUnknown, data.toString()); _controller.resumeCamera(); } @@ -125,7 +125,7 @@ class BarcodeScanHandler extends BarcodeHandler { */ @override - String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanGeneral; + String getOverlayText(BuildContext context) => L10().barcodeScanGeneral; @override Future onBarcodeUnknown(Map data) { @@ -133,7 +133,7 @@ class BarcodeScanHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeNoMatch, + L10().barcodeNoMatch, icon: FontAwesomeIcons.exclamationCircle, success: false, ); @@ -166,7 +166,7 @@ class BarcodeScanHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).invalidStockLocation, + L10().invalidStockLocation, success: false ); } @@ -188,7 +188,7 @@ class BarcodeScanHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).invalidStockItem, + L10().invalidStockItem, success: false ); } @@ -209,7 +209,7 @@ class BarcodeScanHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).invalidPart, + L10().invalidPart, success: false ); } @@ -218,16 +218,16 @@ class BarcodeScanHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeUnknown, + L10().barcodeUnknown, success: false, onAction: () { showDialog( context: _context, child: SimpleDialog( - title: Text(I18N.of(_context).unknownResponse), + title: Text(L10().unknownResponse), children: [ ListTile( - title: Text(I18N.of(_context).responseData), + title: Text(L10().responseData), subtitle: Text(data.toString()), ) ], @@ -250,7 +250,7 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { StockItemBarcodeAssignmentHandler(this.item); @override - String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanAssign; + String getOverlayText(BuildContext context) => L10().barcodeScanAssign; @override Future onBarcodeMatched(Map data) { @@ -259,7 +259,7 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { // If the barcode is known, we can't assign it to the stock item! showSnackIcon( - I18N.of(OneContext().context).barcodeInUse, + L10().barcodeInUse, icon: FontAwesomeIcons.qrcode, success: false ); @@ -271,8 +271,8 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { if (!data.containsKey("hash")) { showServerError( - I18N.of(_context).missingData, - I18N.of(_context).barcodeMissingHash, + L10().missingData, + L10().barcodeMissingHash, ); } else { @@ -292,7 +292,7 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { Navigator.of(_context).pop(); showSnackIcon( - I18N.of(OneContext().context).barcodeAssigned, + L10().barcodeAssigned, success: true, icon: FontAwesomeIcons.qrcode ); @@ -301,7 +301,7 @@ class StockItemBarcodeAssignmentHandler extends BarcodeHandler { successTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeNotAssigned, + L10().barcodeNotAssigned, success: false, icon: FontAwesomeIcons.qrcode ); @@ -325,7 +325,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { StockItemScanIntoLocationHandler(this.item); @override - String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanLocation; + String getOverlayText(BuildContext context) => L10().barcodeScanLocation; @override Future onBarcodeMatched(Map data) async { @@ -346,7 +346,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { Navigator.of(_context).pop(); showSnackIcon( - I18N.of(OneContext().context).barcodeScanIntoLocationSuccess, + L10().barcodeScanIntoLocationSuccess, success: true, ); } else { @@ -354,7 +354,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeScanIntoLocationFailure, + L10().barcodeScanIntoLocationFailure, success: false ); } @@ -363,7 +363,7 @@ class StockItemScanIntoLocationHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).invalidStockLocation, + L10().invalidStockLocation, success: false, ); } @@ -381,7 +381,7 @@ class StockLocationScanInItemsHandler extends BarcodeHandler { StockLocationScanInItemsHandler(this.location); @override - String getOverlayText(BuildContext context) => I18N.of(context).barcodeScanItem; + String getOverlayText(BuildContext context) => L10().barcodeScanItem; @override Future onBarcodeMatched(Map data) async { @@ -398,16 +398,14 @@ class StockLocationScanInItemsHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).invalidStockItem, + L10().invalidStockItem, success: false, ); } else if (item.locationId == location.pk) { failureTone(); showSnackIcon( - I18N - .of(OneContext().context) - .itemInLocation, + L10().itemInLocation, success: true ); } else { @@ -418,7 +416,7 @@ class StockLocationScanInItemsHandler extends BarcodeHandler { successTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeScanIntoLocationSuccess, + L10().barcodeScanIntoLocationSuccess, success: true ); } else { @@ -426,7 +424,7 @@ class StockLocationScanInItemsHandler extends BarcodeHandler { failureTone(); showSnackIcon( - I18N.of(OneContext().context).barcodeScanIntoLocationFailure, + L10().barcodeScanIntoLocationFailure, success: false ); } @@ -437,7 +435,7 @@ class StockLocationScanInItemsHandler extends BarcodeHandler { // Does not match a valid stock item! showSnackIcon( - I18N.of(OneContext().context).invalidStockItem, + L10().invalidStockItem, success: false, ); } diff --git a/lib/inventree/stock.dart b/lib/inventree/stock.dart index e0b15e05..ff8189cd 100644 --- a/lib/inventree/stock.dart +++ b/lib/inventree/stock.dart @@ -1,14 +1,13 @@ import 'package:InvenTree/inventree/part.dart'; -import 'package:InvenTree/widget/dialogs.dart'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart' as http; import 'model.dart'; +import 'package:InvenTree/l10.dart'; import 'dart:async'; import 'dart:io'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:InvenTree/api.dart'; @@ -63,19 +62,19 @@ class InvenTreeStockItem extends InvenTreeModel { switch (status) { case OK: - return I18N.of(context).ok; + return L10().ok; case ATTENTION: - return I18N.of(context).attention; + return L10().attention; case DAMAGED: - return I18N.of(context).damaged; + return L10().damaged; case DESTROYED: - return I18N.of(context).destroyed; + return L10().destroyed; case REJECTED: - return I18N.of(context).rejected; + return L10().rejected; case LOST: - return I18N.of(context).lost; + return L10().lost; case RETURNED: - return I18N.of(context).returned; + return L10().returned; default: return status.toString(); } diff --git a/lib/l10.dart b/lib/l10.dart new file mode 100644 index 00000000..5225a547 --- /dev/null +++ b/lib/l10.dart @@ -0,0 +1,9 @@ +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:one_context/one_context.dart'; + + +// Shortcut function to reduce boilerplate! +I18N L10() +{ + return I18N.of(OneContext().context); +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 2f35e9b9..e9c9a978 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,8 @@ import 'package:InvenTree/inventree/sentry.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'file:///C:/inventree-app/lib/l10.dart'; + import 'package:InvenTree/widget/home.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -57,7 +59,7 @@ class InvenTreeApp extends StatelessWidget { return MaterialApp( builder: OneContext().builder, navigatorKey: OneContext().key, - onGenerateTitle: (BuildContext context) => I18N.of(context).appTitle, + onGenerateTitle: (BuildContext context) => L10().appTitle, theme: ThemeData( primarySwatch: Colors.lightBlue, secondaryHeaderColor: Colors.blueGrey, diff --git a/lib/settings/about.dart b/lib/settings/about.dart index 6d110816..b0dc9090 100644 --- a/lib/settings/about.dart +++ b/lib/settings/about.dart @@ -6,9 +6,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:package_info/package_info.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:package_info/package_info.dart'; +import 'package:InvenTree/l10.dart'; class InvenTreeAboutWidget extends StatelessWidget { @@ -45,7 +44,7 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( title: Text( - I18N.of(context).serverDetails, + L10().serverDetails, style: TextStyle(fontWeight: FontWeight.bold), ), ) @@ -54,33 +53,33 @@ class InvenTreeAboutWidget extends StatelessWidget { if (InvenTreeAPI().isConnected()) { tiles.add( ListTile( - title: Text(I18N.of(context).address), - subtitle: Text(InvenTreeAPI().baseUrl.isNotEmpty ? InvenTreeAPI().baseUrl : I18N.of(context).notConnected), + title: Text(L10().address), + subtitle: Text(InvenTreeAPI().baseUrl.isNotEmpty ? InvenTreeAPI().baseUrl : L10().notConnected), leading: FaIcon(FontAwesomeIcons.globe), ) ); tiles.add( ListTile( - title: Text(I18N.of(context).version), - subtitle: Text(InvenTreeAPI().version.isNotEmpty ? InvenTreeAPI().version : I18N.of(context).notConnected), + title: Text(L10().version), + subtitle: Text(InvenTreeAPI().version.isNotEmpty ? InvenTreeAPI().version : L10().notConnected), leading: FaIcon(FontAwesomeIcons.infoCircle), ) ); tiles.add( ListTile( - title: Text(I18N.of(context).serverInstance), - subtitle: Text(InvenTreeAPI().instance.isNotEmpty ? InvenTreeAPI().instance : I18N.of(context).notConnected), + title: Text(L10().serverInstance), + subtitle: Text(InvenTreeAPI().instance.isNotEmpty ? InvenTreeAPI().instance : L10().notConnected), leading: FaIcon(FontAwesomeIcons.server), ) ); } else { tiles.add( ListTile( - title: Text(I18N.of(context).notConnected), + title: Text(L10().notConnected), subtitle: Text( - I18N.of(context).serverNotConnected, + L10().serverNotConnected, style: TextStyle(fontStyle: FontStyle.italic), ), leading: FaIcon(FontAwesomeIcons.exclamationCircle) @@ -91,7 +90,7 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( title: Text( - I18N.of(context).appDetails, + L10().appDetails, style: TextStyle(fontWeight: FontWeight.bold), ), ) @@ -99,7 +98,7 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( - title: Text(I18N.of(context).packageName), + title: Text(L10().packageName), subtitle: Text("${info.packageName}"), leading: FaIcon(FontAwesomeIcons.box) ) @@ -107,7 +106,7 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( - title: Text(I18N.of(context).version), + title: Text(L10().version), subtitle: Text("${info.version}"), leading: FaIcon(FontAwesomeIcons.infoCircle) ) @@ -115,8 +114,8 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( - title: Text(I18N.of(context).releaseNotes), - subtitle: Text(I18N.of(context).appReleaseNotes), + title: Text(L10().releaseNotes), + subtitle: Text(L10().appReleaseNotes), leading: FaIcon(FontAwesomeIcons.fileAlt), onTap: () { _releaseNotes(context); @@ -126,8 +125,8 @@ class InvenTreeAboutWidget extends StatelessWidget { tiles.add( ListTile( - title: Text(I18N.of(context).credits), - subtitle: Text(I18N.of(context).appCredits), + title: Text(L10().credits), + subtitle: Text(L10().appCredits), leading: FaIcon(FontAwesomeIcons.bullhorn), onTap: () { _credits(context); @@ -137,7 +136,7 @@ class InvenTreeAboutWidget extends StatelessWidget { return Scaffold( appBar: AppBar( - title: Text(I18N.of(context).appAbout), + title: Text(L10().appAbout), ), body: ListView( children: ListTile.divideTiles( diff --git a/lib/settings/app_settings.dart b/lib/settings/app_settings.dart index 355b26cf..f5910dd0 100644 --- a/lib/settings/app_settings.dart +++ b/lib/settings/app_settings.dart @@ -2,7 +2,8 @@ import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; + import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:InvenTree/app_settings.dart'; @@ -82,21 +83,21 @@ class _InvenTreeAppSettingsState extends State { return Scaffold( key: _settingsKey, appBar: AppBar( - title: Text(I18N.of(context).appSettings), + title: Text(L10().appSettings), ), body: Container( child: ListView( children: [ ListTile( title: Text( - I18N.of(context).parts, + L10().parts, style: TextStyle(fontWeight: FontWeight.bold), ), leading: FaIcon(FontAwesomeIcons.shapes), ), ListTile( - title: Text(I18N.of(context).includeSubcategories), - subtitle: Text(I18N.of(context).includeSubcategoriesDetail), + title: Text(L10().includeSubcategories), + subtitle: Text(L10().includeSubcategoriesDetail), leading: FaIcon(FontAwesomeIcons.sitemap), trailing: Switch( value: partSubcategory, @@ -105,14 +106,14 @@ class _InvenTreeAppSettingsState extends State { ), Divider(height: 3), ListTile( - title: Text(I18N.of(context).stock, + title: Text(L10().stock, style: TextStyle(fontWeight: FontWeight.bold), ), leading: FaIcon(FontAwesomeIcons.boxes), ), ListTile( - title: Text(I18N.of(context).includeSublocations), - subtitle: Text(I18N.of(context).includeSublocationsDetail), + title: Text(L10().includeSublocations), + subtitle: Text(L10().includeSublocationsDetail), leading: FaIcon(FontAwesomeIcons.sitemap), trailing: Switch( value: stockSublocation, @@ -122,14 +123,14 @@ class _InvenTreeAppSettingsState extends State { Divider(height: 3), ListTile( title: Text( - I18N.of(context).sounds, + L10().sounds, style: TextStyle(fontWeight: FontWeight.bold), ), leading: FaIcon(FontAwesomeIcons.volumeUp), ), ListTile( - title: Text(I18N.of(context).serverError), - subtitle: Text(I18N.of(context).soundOnServerError), + title: Text(L10().serverError), + subtitle: Text(L10().soundOnServerError), leading: FaIcon(FontAwesomeIcons.server), trailing: Switch( value: serverSounds, @@ -137,8 +138,8 @@ class _InvenTreeAppSettingsState extends State { ), ), ListTile( - title: Text(I18N.of(context).barcodeTones), - subtitle: Text(I18N.of(context).soundOnBarcodeAction), + title: Text(L10().barcodeTones), + subtitle: Text(L10().soundOnBarcodeAction), leading: FaIcon(FontAwesomeIcons.qrcode), trailing: Switch( value: barcodeSounds, diff --git a/lib/settings/login.dart b/lib/settings/login.dart index ff11b14b..13105250 100644 --- a/lib/settings/login.dart +++ b/lib/settings/login.dart @@ -3,9 +3,10 @@ import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/widget/spinner.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:InvenTree/l10.dart'; + import '../api.dart'; import '../preferences.dart'; import '../user_profile.dart'; @@ -53,7 +54,7 @@ class _InvenTreeLoginSettingsState extends State { } showFormDialog( - createNew ? I18N.of(context).profileAdd : I18N.of(context).profileEdit, + createNew ? L10().profileAdd : L10().profileEdit, key: _addProfileKey, callback: () { if (createNew) { @@ -79,29 +80,29 @@ class _InvenTreeLoginSettingsState extends State { }, fields: [ StringField( - label: I18N.of(context).name, + label: L10().name, hint: "Enter profile name", initial: createNew ? '' : profile.name, onSaved: (value) => _name = value, validator: _validateProfileName, ), StringField( - label: I18N.of(context).server, + label: L10().server, hint: "http[s]://:", initial: createNew ? '' : profile.server, validator: _validateServer, onSaved: (value) => _server = value, ), StringField( - label: I18N.of(context).username, - hint: I18N.of(context).enterPassword, + label: L10().username, + hint: L10().enterPassword, initial: createNew ? '' : profile.username, onSaved: (value) => _username = value, validator: _validateUsername, ), StringField( - label: I18N.of(context).password, - hint: I18N.of(context).enterUsername, + label: L10().password, + hint: L10().enterUsername, initial: createNew ? '' : profile.password, onSaved: (value) => _password = value, validator: _validatePassword, @@ -266,28 +267,28 @@ class _InvenTreeLoginSettingsState extends State { Navigator.of(context).pop(); _selectProfile(context, profile); }, - child: Text(I18N.of(context).profileConnect), + child: Text(L10().profileConnect), ), SimpleDialogOption( onPressed: () { Navigator.of(context).pop(); _editProfile(context, userProfile: profile); }, - child: Text(I18N.of(context).profileEdit), + child: Text(L10().profileEdit), ), SimpleDialogOption( onPressed: () { Navigator.of(context).pop(); // Navigator.of(context, rootNavigator: true).pop(); confirmationDialog( - I18N.of(context).delete, - I18N.of(context).profileDelete + "?", + L10().delete, + L10().profileDelete + "?", onAccept: () { _deleteProfile(profile); } ); }, - child: Text(I18N.of(context).profileDelete), + child: Text(L10().profileDelete), ) ], ); @@ -300,7 +301,7 @@ class _InvenTreeLoginSettingsState extends State { // No profile available! children.add( ListTile( - title: Text(I18N.of(context).profileNone), + title: Text(L10().profileNone), ) ); } @@ -308,7 +309,7 @@ class _InvenTreeLoginSettingsState extends State { return Scaffold( key: _loginKey, appBar: AppBar( - title: Text(I18N.of(context).profileSelect), + title: Text(L10().profileSelect), ), body: Container( child: ListView( diff --git a/lib/settings/release.dart b/lib/settings/release.dart index 433e85b6..d15b4f92 100644 --- a/lib/settings/release.dart +++ b/lib/settings/release.dart @@ -2,8 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; import 'package:markdown/markdown.dart' as md; - -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; class ReleaseNotesWidget extends StatelessWidget { @@ -16,7 +15,7 @@ class ReleaseNotesWidget extends StatelessWidget { Widget build (BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(I18N.of(context).releaseNotes) + title: Text(L10().releaseNotes) ), body: Markdown( selectable: false, @@ -37,7 +36,7 @@ class CreditsWidget extends StatelessWidget { Widget build (BuildContext context) { return Scaffold( appBar: AppBar( - title: Text(I18N.of(context).credits), + title: Text(L10().credits), ), body: Markdown( selectable: false, diff --git a/lib/settings/settings.dart b/lib/settings/settings.dart index be44e7c2..38ae8c12 100644 --- a/lib/settings/settings.dart +++ b/lib/settings/settings.dart @@ -7,7 +7,8 @@ import 'package:InvenTree/widget/dialogs.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; + import 'package:url_launcher/url_launcher.dart'; import 'login.dart'; @@ -35,7 +36,7 @@ class _InvenTreeSettingsState extends State { return Scaffold( key: _scaffoldKey, appBar: AppBar( - title: Text(I18N.of(context).settings), + title: Text(L10().settings), ), body: Center( child: ListView( @@ -43,26 +44,26 @@ class _InvenTreeSettingsState extends State { context: context, tiles: [ ListTile( - title: Text(I18N.of(context).server), - subtitle: Text(I18N.of(context).configureServer), + title: Text(L10().server), + subtitle: Text(L10().configureServer), leading: FaIcon(FontAwesomeIcons.server), onTap: _editServerSettings, ), ListTile( leading: FaIcon(FontAwesomeIcons.cogs), - title: Text(I18N.of(context).appSettings), - subtitle: Text(I18N.of(context).appSettingsDetails), + title: Text(L10().appSettings), + subtitle: Text(L10().appSettingsDetails), onTap: _editAppSettings, ), ListTile( - title: Text(I18N.of(context).about), - subtitle: Text(I18N.of(context).appDetails), + title: Text(L10().about), + subtitle: Text(L10().appDetails), leading: FaIcon(FontAwesomeIcons.infoCircle), onTap: _about, ), ListTile( - title: Text(I18N.of(context).documentation), + title: Text(L10().documentation), subtitle: Text("https://inventree.readthedocs.io"), leading: FaIcon(FontAwesomeIcons.book), onTap: () { @@ -71,8 +72,8 @@ class _InvenTreeSettingsState extends State { ), ListTile( - title: Text(I18N.of(context).feedback), - subtitle: Text(I18N.of(context).submitFeedback), + title: Text(L10().feedback), + subtitle: Text(L10().submitFeedback), leading: FaIcon(FontAwesomeIcons.comments), onTap: () { _submitFeedback(context); @@ -115,12 +116,12 @@ class _InvenTreeSettingsState extends State { if (result) { showSnackIcon( - I18N.of(context).feedbackSuccess, + L10().feedbackSuccess, success: true, ); } else { showSnackIcon( - I18N.of(context).feedbackError, + L10().feedbackError, success: false, ); } @@ -133,7 +134,7 @@ class _InvenTreeSettingsState extends State { _controller.clear(); showFormDialog( - I18N.of(context).submitFeedback, + L10().submitFeedback, key: _feedbackKey, callback: () { _sendReport(context, _controller.text); diff --git a/lib/widget/category_display.dart b/lib/widget/category_display.dart index 5f007277..83d34dfc 100644 --- a/lib/widget/category_display.dart +++ b/lib/widget/category_display.dart @@ -2,17 +2,15 @@ import 'package:InvenTree/api.dart'; import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/inventree/part.dart'; -import 'package:InvenTree/preferences.dart'; import 'package:InvenTree/widget/progress.dart'; -import 'package:InvenTree/widget/search.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; + import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/widget/dialogs.dart'; import 'package:InvenTree/widget/snacks.dart'; import 'package:InvenTree/widget/part_detail.dart'; -import 'package:InvenTree/widget/drawer.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:InvenTree/widget/paginator.dart'; @@ -39,7 +37,7 @@ class _CategoryDisplayState extends RefreshableState { final _editCategoryKey = GlobalKey(); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).partCategory; + String getAppBarTitle(BuildContext context) => L10().partCategory; @override List getAppBarActions(BuildContext context) { @@ -71,7 +69,7 @@ class _CategoryDisplayState extends RefreshableState { actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, + tooltip: L10().edit, onPressed: _editCategoryDialog, ) ); @@ -99,7 +97,7 @@ class _CategoryDisplayState extends RefreshableState { var _description; showFormDialog( - I18N.of(context).editCategory, + L10().editCategory, key: _editCategoryKey, callback: () { _editCategory({ @@ -109,12 +107,12 @@ class _CategoryDisplayState extends RefreshableState { }, fields: [ StringField( - label: I18N.of(context).name, + label: L10().name, initial: category.name, onSaved: (value) => _name = value ), StringField( - label: I18N.of(context).description, + label: L10().description, initial: category.description, onSaved: (value) => _description = value ) @@ -163,7 +161,7 @@ class _CategoryDisplayState extends RefreshableState { if (category == null) { return Card( child: ListTile( - title: Text(I18N.of(context).partCategoryTopLevel) + title: Text(L10().partCategoryTopLevel) ) ); } else { @@ -180,7 +178,7 @@ class _CategoryDisplayState extends RefreshableState { if (extra) { children.add( ListTile( - title: Text(I18N.of(context).parentCategory), + title: Text(L10().parentCategory), subtitle: Text("${category.parentpathstring}"), leading: FaIcon(FontAwesomeIcons.levelUpAlt), onTap: () { @@ -215,17 +213,17 @@ class _CategoryDisplayState extends RefreshableState { items: [ BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.sitemap), - label: I18N.of(context).details, + label: L10().details, ), BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.shapes), - label: I18N.of(context).parts, + label: L10().parts, ), // TODO - Add the "actions" item back in /* BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.wrench), - label: I18N.of(context).actions + label: L10().actions ), */ ] @@ -237,7 +235,7 @@ class _CategoryDisplayState extends RefreshableState { getCategoryDescriptionCard(), ListTile( title: Text( - I18N.of(context).subcategories, + L10().subcategories, style: TextStyle(fontWeight: FontWeight.bold) ), trailing: _subcategories.isNotEmpty ? Text("${_subcategories.length}") : null, @@ -248,8 +246,8 @@ class _CategoryDisplayState extends RefreshableState { tiles.add(progressIndicator()); } else if (_subcategories.length == 0) { tiles.add(ListTile( - title: Text(I18N.of(context).noSubcategories), - subtitle: Text(I18N.of(context).noSubcategoriesAvailable) + title: Text(L10().noSubcategories), + subtitle: Text(L10().noSubcategoriesAvailable) )); } else { tiles.add(SubcategoryList(_subcategories)); @@ -263,7 +261,7 @@ class _CategoryDisplayState extends RefreshableState { List tiles = [ getCategoryDescriptionCard(extra: false), ListTile( - title: Text(I18N.of(context).actions, + title: Text(L10().actions, style: TextStyle(fontWeight: FontWeight.bold) ) ) diff --git a/lib/widget/company_detail.dart b/lib/widget/company_detail.dart index c2ee726c..5aec037c 100644 --- a/lib/widget/company_detail.dart +++ b/lib/widget/company_detail.dart @@ -2,13 +2,12 @@ import 'package:InvenTree/api.dart'; import 'package:InvenTree/inventree/company.dart'; import 'package:InvenTree/widget/dialogs.dart'; -import 'package:InvenTree/widget/drawer.dart'; import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; class CompanyDetailWidget extends StatefulWidget { @@ -29,7 +28,7 @@ class _CompanyDetailState extends RefreshableState { final _editCompanyKey = GlobalKey(); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).company; + String getAppBarTitle(BuildContext context) => L10().company; @override Future request(BuildContext context) async { @@ -55,17 +54,17 @@ class _CompanyDetailState extends RefreshableState { var _description; var _website; - showFormDialog(I18N.of(context).edit, + showFormDialog(L10().edit, key: _editCompanyKey, actions: [ FlatButton( - child: Text(I18N.of(context).cancel), + child: Text(L10().cancel), onPressed: () { Navigator.pop(context); }, ), FlatButton( - child: Text(I18N.of(context).save), + child: Text(L10().save), onPressed: () { if (_editCompanyKey.currentState.validate()) { _editCompanyKey.currentState.save(); @@ -81,21 +80,21 @@ class _CompanyDetailState extends RefreshableState { ], fields: [ StringField( - label: I18N.of(context).name, + label: L10().name, initial: company.name, onSaved: (value) { _name = value; }, ), StringField( - label: I18N.of(context).description, + label: L10().description, initial: company.description, onSaved: (value) { _description = value; }, ), StringField( - label: I18N.of(context).website, + label: L10().website, initial: company.website, allowEmpty: true, onSaved: (value) { @@ -193,7 +192,7 @@ class _CompanyDetailState extends RefreshableState { if (company.notes.isNotEmpty) { tiles.add(ListTile( - title: Text(I18N.of(context).notes), + title: Text(L10().notes), leading: FaIcon(FontAwesomeIcons.stickyNote), onTap: null, )); diff --git a/lib/widget/dialogs.dart b/lib/widget/dialogs.dart index e6120d53..9a07d05f 100644 --- a/lib/widget/dialogs.dart +++ b/lib/widget/dialogs.dart @@ -2,21 +2,20 @@ import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/widget/snacks.dart'; import 'package:audioplayers/audio_cache.dart'; -import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import 'package:one_context/one_context.dart'; Future confirmationDialog(String title, String text, {String acceptText, String rejectText, Function onAccept, Function onReject}) async { if (acceptText == null || acceptText.isEmpty) { - acceptText = I18N.of(OneContext().context).ok; + acceptText = L10().ok; } if (rejectText == null || rejectText.isEmpty) { - rejectText = I18N.of(OneContext().context).cancel; + rejectText = L10().cancel; } OneContext().showDialog( @@ -60,7 +59,7 @@ Future confirmationDialog(String title, String text, {String acceptText, S Future showInfoDialog(BuildContext context, String title, String description, {IconData icon = FontAwesomeIcons.info, String info, Function onDismissed}) async { if (info == null || info.isEmpty) { - info = I18N.of(context).info; + info = L10().info; } showDialog( @@ -87,7 +86,7 @@ Future showInfoDialog(BuildContext context, String title, String descripti Future showErrorDialog(String title, String description, {IconData icon = FontAwesomeIcons.exclamationCircle, String error, Function onDismissed}) async { if (error == null || error.isEmpty) { - error = I18N.of(OneContext().context).error; + error = L10().error; } OneContext().showDialog( @@ -113,7 +112,7 @@ Future showErrorDialog(String title, String description, {IconData icon = Future showServerError(String title, String description) async { if (title == null || title.isEmpty) { - title = I18N.of(OneContext().context).serverError; + title = L10().serverError; } // Play a sound @@ -127,12 +126,12 @@ Future showServerError(String title, String description) async { showSnackIcon( title, success: false, - actionText: I18N.of(OneContext().context).details, + actionText: L10().details, onAction: () { showErrorDialog( title, description, - error: I18N.of(OneContext().context).serverError, + error: L10().serverError, icon: FontAwesomeIcons.server ); } @@ -143,27 +142,27 @@ Future showStatusCodeError(int status, {int expected = 200}) async { BuildContext ctx = OneContext().context; - String msg = I18N.of(ctx).responseInvalid; + String msg = L10().responseInvalid; String extra = "Server responded with status code ${status}"; switch (status) { case 400: - msg = I18N.of(ctx).response400; + msg = L10().response400; break; case 401: - msg = I18N.of(ctx).response401; + msg = L10().response401; break; case 403: - msg = I18N.of(ctx).response403; + msg = L10().response403; break; case 404: - msg = I18N.of(ctx).response404; + msg = L10().response404; break; case 405: - msg = I18N.of(ctx).response405; + msg = L10().response405; break; case 429: - msg = I18N.of(ctx).response429; + msg = L10().response429; break; default: break; @@ -180,7 +179,7 @@ Future showTimeoutError(BuildContext context) async { // Use OneContext as "sometimes" context is null here? var ctx = OneContext().context; - await showServerError(I18N.of(ctx).timeout, I18N.of(ctx).noResponse); + await showServerError(L10().timeout, L10().noResponse); } void showFormDialog(String title, {String acceptText, String cancelText, GlobalKey key, List fields, List actions, Function callback}) { @@ -190,11 +189,11 @@ void showFormDialog(String title, {String acceptText, String cancelText, GlobalK var ctx = OneContext().context; if (acceptText == null) { - acceptText = I18N.of(ctx).save; + acceptText = L10().save; } if (cancelText == null) { - cancelText = I18N.of(ctx).cancel; + cancelText = L10().cancel; } // Undefined actions = OK + Cancel diff --git a/lib/widget/drawer.dart b/lib/widget/drawer.dart index 70d181f7..0948f605 100644 --- a/lib/widget/drawer.dart +++ b/lib/widget/drawer.dart @@ -3,9 +3,7 @@ import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/widget/company_list.dart'; import 'package:InvenTree/widget/search.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; - -import 'package:InvenTree/api.dart'; +import 'package:InvenTree/l10.dart'; import 'package:InvenTree/widget/category_display.dart'; import 'package:InvenTree/widget/location_display.dart'; @@ -118,28 +116,28 @@ class InvenTreeDrawer extends StatelessWidget { width: 30, ), title: Text( - I18N.of(context).appTitle, + L10().appTitle, style: TextStyle(fontWeight: FontWeight.bold), ), onTap: _home, ), ListTile( - title: Text(I18N.of(context).scanBarcode), + title: Text(L10().scanBarcode), onTap: _scan, leading: FaIcon(FontAwesomeIcons.barcode), ), ListTile( - title: Text(I18N.of(context).search), + title: Text(L10().search), leading: FaIcon(FontAwesomeIcons.search), onTap: _search, ), ListTile( - title: Text(I18N.of(context).parts), + title: Text(L10().parts), leading: Icon(Icons.category), onTap: _showParts, ), ListTile( - title: Text(I18N.of(context).stock), + title: Text(L10().stock), leading: FaIcon(FontAwesomeIcons.boxes), onTap: _showStock, ), @@ -161,7 +159,7 @@ class InvenTreeDrawer extends StatelessWidget { ), */ ListTile( - title: Text(I18N.of(context).settings), + title: Text(L10().settings), leading: Icon(Icons.settings), onTap: _settings, ), diff --git a/lib/widget/fields.dart b/lib/widget/fields.dart index 98aed1b4..2946f09a 100644 --- a/lib/widget/fields.dart +++ b/lib/widget/fields.dart @@ -4,7 +4,8 @@ import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:image_picker/image_picker.dart'; import 'package:one_context/one_context.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; + +import 'package:InvenTree/l10.dart'; import 'dart:async'; import 'dart:io'; @@ -52,7 +53,7 @@ class ImagePickerField extends FormField { onSaved: onSaved, validator: (File img) { if (required && (img == null)) { - return I18N.of(context).required; + return L10().required; } return null; @@ -67,13 +68,13 @@ class ImagePickerField extends FormField { mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ FlatButton( - child: Text(I18N.of(context).selectImage), + child: Text(L10().selectImage), onPressed: () { _selectFromGallery(state); }, ), FlatButton( - child: Text(I18N.of(context).takePicture), + child: Text(L10().takePicture), onPressed: () { _selectFromCamera(state); }, @@ -82,7 +83,7 @@ class ImagePickerField extends FormField { ), ); return ListTile( - title: Text(I18N.of(context).selectImage), + title: Text(L10().selectImage), ); } ); @@ -120,7 +121,7 @@ class StringField extends TextFormField { enabled: isEnabled, validator: (value) { if (!allowEmpty && value.isEmpty) { - return I18N.of(OneContext().context).valueCannotBeEmpty; + return L10().valueCannotBeEmpty; } if (validator != null) { @@ -148,14 +149,12 @@ class QuantityField extends TextFormField { keyboardType: TextInputType.numberWithOptions(signed: false, decimal: true), validator: (value) { - final ctx = OneContext().context; - - if (value.isEmpty) return I18N.of(ctx).quantityEmpty; + if (value.isEmpty) return L10().quantityEmpty; double quantity = double.tryParse(value); - if (quantity == null) return I18N.of(ctx).quantityInvalid; - if (quantity <= 0) return I18N.of(ctx).quantityPositive; + if (quantity == null) return L10().quantityInvalid; + if (quantity <= 0) return L10().quantityPositive; if ((max != null) && (quantity > max)) return "Quantity must not exceed ${max}"; return null; diff --git a/lib/widget/home.dart b/lib/widget/home.dart index 014fa2d1..677522e3 100644 --- a/lib/widget/home.dart +++ b/lib/widget/home.dart @@ -3,7 +3,7 @@ import 'package:InvenTree/widget/starred_parts.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'file:///C:/inventree-app/lib/l10.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; @@ -128,8 +128,8 @@ class _InvenTreeHomePageState extends State { // Tap to select / create a profile if (_profile == null) { return ListTile( - title: Text(I18N.of(context).profileNotSelected), - subtitle: Text(I18N.of(context).profileTapToCreate), + title: Text(L10().profileNotSelected), + subtitle: Text(L10().profileTapToCreate), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( FontAwesomeIcons.user, @@ -144,7 +144,7 @@ class _InvenTreeHomePageState extends State { // Profile is selected ... if (InvenTreeAPI().isConnecting()) { return ListTile( - title: Text(I18N.of(context).serverConnecting), + title: Text(L10().serverConnecting), subtitle: Text("${InvenTreeAPI().baseUrl}"), leading: FaIcon(FontAwesomeIcons.server), trailing: Spinner( @@ -157,7 +157,7 @@ class _InvenTreeHomePageState extends State { ); } else if (InvenTreeAPI().isConnected()) { return ListTile( - title: Text(I18N.of(context).serverConnected), + title: Text(L10().serverConnected), subtitle: Text("${InvenTreeAPI().baseUrl}"), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( @@ -170,7 +170,7 @@ class _InvenTreeHomePageState extends State { ); } else { return ListTile( - title: Text(I18N.of(context).serverCouldNotConnect), + title: Text(L10().serverCouldNotConnect), subtitle: Text("${_profile.server}"), leading: FaIcon(FontAwesomeIcons.server), trailing: FaIcon( @@ -198,12 +198,12 @@ class _InvenTreeHomePageState extends State { return Scaffold( key: _homeKey, appBar: AppBar( - title: Text(I18N.of(context).appTitle), + title: Text(L10().appTitle), actions: [ /* IconButton( icon: FaIcon(FontAwesomeIcons.search), - tooltip: I18N.of(context).search, + tooltip: L10().search, onPressed: _searchParts, ), */ @@ -224,10 +224,10 @@ class _InvenTreeHomePageState extends State { children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.barcode), - tooltip: I18N.of(context).scanBarcode, + tooltip: L10().scanBarcode, onPressed: () { _scan(context); }, ), - Text(I18N.of(context).scanBarcode), + Text(L10().scanBarcode), ], ), ], @@ -240,10 +240,10 @@ class _InvenTreeHomePageState extends State { children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.shapes), - tooltip: I18N.of(context).parts, + tooltip: L10().parts, onPressed: () { _parts(context); }, ), - Text(I18N.of(context).parts), + Text(L10().parts), ], ), Column( @@ -251,10 +251,10 @@ class _InvenTreeHomePageState extends State { IconButton( icon: new FaIcon(FontAwesomeIcons.search), - tooltip: I18N.of(context).searchParts, + tooltip: L10().searchParts, onPressed: _searchParts, ), - Text(I18N.of(context).searchParts), + Text(L10().searchParts), ], ), // TODO - Re-add starred parts link @@ -281,20 +281,20 @@ class _InvenTreeHomePageState extends State { children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.boxes), - tooltip: I18N.of(context).stock, + tooltip: L10().stock, onPressed: () { _stock(context); }, ), - Text(I18N.of(context).stock), + Text(L10().stock), ], ), Column( children: [ IconButton( icon: new FaIcon(FontAwesomeIcons.search), - tooltip: I18N.of(context).searchStock, + tooltip: L10().searchStock, onPressed: _searchStock, ), - Text(I18N.of(context).searchStock), + Text(L10().searchStock), ], ), ] diff --git a/lib/widget/location_display.dart b/lib/widget/location_display.dart index b7765275..a295e3cb 100644 --- a/lib/widget/location_display.dart +++ b/lib/widget/location_display.dart @@ -2,22 +2,20 @@ import 'package:InvenTree/api.dart'; import 'package:InvenTree/app_settings.dart'; import 'package:InvenTree/barcode.dart'; import 'package:InvenTree/inventree/stock.dart'; -import 'package:InvenTree/preferences.dart'; import 'package:InvenTree/widget/progress.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/widget/dialogs.dart'; -import 'package:InvenTree/widget/search.dart'; import 'package:InvenTree/widget/snacks.dart'; import 'package:InvenTree/widget/stock_detail.dart'; import 'package:InvenTree/widget/paginator.dart'; +import 'package:InvenTree/l10.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/foundation.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:infinite_scroll_pagination/infinite_scroll_pagination.dart'; class LocationDisplayWidget extends StatefulWidget { @@ -71,7 +69,7 @@ class _LocationDisplayState extends RefreshableState { actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, + tooltip: L10().edit, onPressed: _editLocationDialog, ) ); @@ -97,7 +95,7 @@ class _LocationDisplayState extends RefreshableState { var _name; var _description; - showFormDialog(I18N.of(context).editLocation, + showFormDialog(L10().editLocation, key: _editLocationKey, callback: () { _editLocation({ @@ -107,12 +105,12 @@ class _LocationDisplayState extends RefreshableState { }, fields: [ StringField( - label: I18N.of(context).name, + label: L10().name, initial: location.name, onSaved: (value) => _name = value, ), StringField( - label: I18N.of(context).description, + label: L10().description, initial: location.description, onSaved: (value) => _description = value, ) @@ -168,7 +166,7 @@ class _LocationDisplayState extends RefreshableState { if (location == null) { return Card( child: ListTile( - title: Text(I18N.of(context).stockTopLevel), + title: Text(L10().stockTopLevel), ) ); } else { @@ -183,7 +181,7 @@ class _LocationDisplayState extends RefreshableState { if (includeActions) { children.add( ListTile( - title: Text(I18N.of(context).parentCategory), + title: Text(L10().parentCategory), subtitle: Text("${location.parentpathstring}"), leading: FaIcon(FontAwesomeIcons.levelUpAlt), onTap: () { @@ -217,16 +215,16 @@ class _LocationDisplayState extends RefreshableState { items: [ BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.sitemap), - label: I18N.of(context).details, + label: L10().details, ), BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.boxes), - label: I18N.of(context).stock, + label: L10().stock, ), // TODO - Add in actions when they are written... BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.wrench), - label: I18N.of(context).actions, + label: L10().actions, ) ] ); @@ -273,7 +271,7 @@ List detailTiles() { locationDescriptionCard(), ListTile( title: Text( - I18N.of(context).sublocations, + L10().sublocations, style: TextStyle(fontWeight: FontWeight.bold), ), trailing: sublocations.length > 0 ? Text("${sublocations.length}") : null, @@ -286,8 +284,8 @@ List detailTiles() { tiles.add(SublocationList(_sublocations)); } else { tiles.add(ListTile( - title: Text(I18N.of(context).sublocationNone), - subtitle: Text(I18N.of(context).sublocationNoneDetail) + title: Text(L10().sublocationNone), + subtitle: Text(L10().sublocationNoneDetail) )); } @@ -305,9 +303,7 @@ List detailTiles() { // Scan items into location tiles.add( ListTile( - title: Text(I18N - .of(context) - .barcodeScanInItems), + title: Text(L10().barcodeScanInItems), leading: FaIcon(FontAwesomeIcons.exchangeAlt), trailing: FaIcon(FontAwesomeIcons.qrcode), onTap: () { diff --git a/lib/widget/paginator.dart b/lib/widget/paginator.dart index 99615a4a..a4d0e863 100644 --- a/lib/widget/paginator.dart +++ b/lib/widget/paginator.dart @@ -2,8 +2,8 @@ import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:InvenTree/l10.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; class PaginatedSearchWidget extends StatelessWidget { @@ -36,7 +36,7 @@ class PaginatedSearchWidget extends StatelessWidget { } }, decoration: InputDecoration( - hintText: I18N.of(context).search, + hintText: L10().search, ), ), trailing: Text( @@ -57,7 +57,7 @@ class NoResultsWidget extends StatelessWidget { Widget build(BuildContext context) { return ListTile( - title: Text(I18N.of(context).noResults), + title: Text(L10().noResults), subtitle: Text(description), leading: FaIcon(FontAwesomeIcons.exclamationCircle), ); diff --git a/lib/widget/part_detail.dart b/lib/widget/part_detail.dart index 7c71a90f..2d539768 100644 --- a/lib/widget/part_detail.dart +++ b/lib/widget/part_detail.dart @@ -1,14 +1,12 @@ import 'dart:io'; -import 'package:InvenTree/inventree/stock.dart'; import 'package:InvenTree/widget/part_notes.dart'; import 'package:InvenTree/widget/progress.dart'; import 'package:InvenTree/widget/snacks.dart'; -import 'package:InvenTree/widget/stock_detail.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:InvenTree/inventree/part.dart'; @@ -39,7 +37,7 @@ class _PartDisplayState extends RefreshableState { final _editPartKey = GlobalKey(); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).partDetails; + String getAppBarTitle(BuildContext context) => L10().partDetails; @override List getAppBarActions(BuildContext context) { @@ -59,7 +57,7 @@ class _PartDisplayState extends RefreshableState { actions.add( IconButton( icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, + tooltip: L10().edit, onPressed: _editPartDialog, ) ); @@ -127,7 +125,7 @@ class _PartDisplayState extends RefreshableState { var _keywords; var _link; - showFormDialog(I18N.of(context).editPart, + showFormDialog(L10().editPart, key: _editPartKey, callback: () { _savePart({ @@ -140,29 +138,29 @@ class _PartDisplayState extends RefreshableState { }, fields: [ StringField( - label: I18N.of(context).name, + label: L10().name, initial: part.name, onSaved: (value) => _name = value, ), StringField( - label: I18N.of(context).description, + label: L10().description, initial: part.description, onSaved: (value) => _description = value, ), StringField( - label: I18N.of(context).internalPartNumber, + label: L10().internalPartNumber, initial: part.IPN, allowEmpty: true, onSaved: (value) => _ipn = value, ), StringField( - label: I18N.of(context).keywords, + label: L10().keywords, initial: part.keywords, allowEmpty: true, onSaved: (value) => _keywords = value, ), StringField( - label: I18N.of(context).link, + label: L10().link, initial: part.link, allowEmpty: true, onSaved: (value) => _link = value @@ -216,7 +214,7 @@ class _PartDisplayState extends RefreshableState { if (part.categoryName != null && part.categoryName.isNotEmpty) { tiles.add( ListTile( - title: Text(I18N.of(context).partCategory), + title: Text(L10().partCategory), subtitle: Text("${part.categoryName}"), leading: FaIcon(FontAwesomeIcons.sitemap), onTap: () { @@ -232,8 +230,8 @@ class _PartDisplayState extends RefreshableState { } else { tiles.add( ListTile( - title: Text(I18N.of(context).partCategory), - subtitle: Text(I18N.of(context).partCategoryTopLevel), + title: Text(L10().partCategory), + subtitle: Text(L10().partCategoryTopLevel), leading: FaIcon(FontAwesomeIcons.sitemap), onTap: () { Navigator.push(context, MaterialPageRoute(builder: (context) => CategoryDisplayWidget(null))); @@ -245,7 +243,7 @@ class _PartDisplayState extends RefreshableState { // Stock information tiles.add( ListTile( - title: Text(I18N.of(context).stock), + title: Text(L10().stock), leading: FaIcon(FontAwesomeIcons.boxes), trailing: Text("${part.inStockString}"), onTap: () { @@ -261,7 +259,7 @@ class _PartDisplayState extends RefreshableState { if (part.supplier_count > 0) { tiles.add( ListTile( - title: Text(I18N.of(context).suppliers), + title: Text(L10().suppliers), leading: FaIcon(FontAwesomeIcons.industry), trailing: Text("${part.supplier_count}"), ) @@ -289,7 +287,7 @@ class _PartDisplayState extends RefreshableState { if (false && part.isAssembly) { tiles.add(ListTile( - title: Text(I18N.of(context).billOfMaterials), + title: Text(L10().billOfMaterials), leading: FaIcon(FontAwesomeIcons.thList), trailing: Text("${part.bomItemCount}"), onTap: null, @@ -298,7 +296,7 @@ class _PartDisplayState extends RefreshableState { tiles.add( ListTile( - title: Text(I18N.of(context).building), + title: Text(L10().building), leading: FaIcon(FontAwesomeIcons.tools), trailing: Text("${part.building}"), onTap: null, @@ -344,7 +342,7 @@ class _PartDisplayState extends RefreshableState { // TODO - Add request tests? if (false && part.isTrackable) { tiles.add(ListTile( - title: Text(I18N.of(context).testsRequired), + title: Text(L10().testsRequired), leading: FaIcon(FontAwesomeIcons.tasks), trailing: Text("${part.testTemplateCount}"), onTap: null, @@ -356,7 +354,7 @@ class _PartDisplayState extends RefreshableState { if (part.notes.isNotEmpty) { tiles.add( ListTile( - title: Text(I18N.of(context).notes), + title: Text(L10().notes), leading: FaIcon(FontAwesomeIcons.stickyNote), trailing: Text(""), onTap: () { @@ -382,7 +380,7 @@ class _PartDisplayState extends RefreshableState { tiles.add( ListTile( title: Text( - I18N.of(context).stockItems, + L10().stockItems, style: TextStyle(fontWeight: FontWeight.bold), ), subtitle: part.stockItems.isEmpty ? Text("No stock items available") : null, @@ -408,7 +406,7 @@ class _PartDisplayState extends RefreshableState { tiles.add( ListTile( - title: Text(I18N.of(context).stockItemCreate), + title: Text(L10().stockItemCreate), leading: FaIcon(FontAwesomeIcons.box), onTap: null, ) @@ -463,17 +461,17 @@ class _PartDisplayState extends RefreshableState { items: [ BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.infoCircle), - label: I18N.of(context).details, + label: L10().details, ), BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.boxes), - label: I18N.of(context).stock + label: L10().stock ), // TODO - Add part actions /* BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.wrench), - label: I18N.of(context).actions, + label: L10().actions, ), */ ] diff --git a/lib/widget/part_notes.dart b/lib/widget/part_notes.dart index a0f6c368..8b84b640 100644 --- a/lib/widget/part_notes.dart +++ b/lib/widget/part_notes.dart @@ -1,11 +1,8 @@ - - - import 'package:InvenTree/inventree/part.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_markdown/flutter_markdown.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; class PartNotesWidget extends StatefulWidget { @@ -26,7 +23,7 @@ class _PartNotesState extends RefreshableState { _PartNotesState(this.part); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).partNotes; + String getAppBarTitle(BuildContext context) => L10().partNotes; @override Widget getBody(BuildContext context) { diff --git a/lib/widget/search.dart b/lib/widget/search.dart index 1f8a066a..c6b9c0e9 100644 --- a/lib/widget/search.dart +++ b/lib/widget/search.dart @@ -6,10 +6,10 @@ import 'package:InvenTree/widget/stock_detail.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; + import 'package:InvenTree/inventree/part.dart'; import 'package:InvenTree/inventree/stock.dart'; -import 'package:one_context/one_context.dart'; import '../api.dart'; @@ -36,7 +36,7 @@ class PartSearchDelegate extends SearchDelegate { } @override - String get searchFieldLabel => I18N.of(context).searchParts; + String get searchFieldLabel => L10().searchParts; // List of part results List partResults = []; @@ -79,7 +79,7 @@ class PartSearchDelegate extends SearchDelegate { _searching = false; showSnackIcon( - "${partResults.length} ${I18N.of(OneContext().context).results}", + "${partResults.length} ${L10().results}", success: partResults.length > 0, icon: FontAwesomeIcons.pollH, ); @@ -157,21 +157,21 @@ class PartSearchDelegate extends SearchDelegate { if (query.length == 0) { return ListTile( - title: Text(I18N.of(context).queryEnter) + title: Text(L10().queryEnter) ); } if (query.length < 3) { return ListTile( - title: Text(I18N.of(context).queryShort), - subtitle: Text(I18N.of(context).queryShortDetail) + title: Text(L10().queryShort), + subtitle: Text(L10().queryShortDetail) ); } if (partResults.length == 0) { return ListTile( - title: Text(I18N.of(context).noResults), - subtitle: Text(I18N.of(context).queryNoResults + " '${query}'") + title: Text(L10().noResults), + subtitle: Text(L10().queryNoResults + " '${query}'") ); } @@ -221,7 +221,7 @@ class StockSearchDelegate extends SearchDelegate { } @override - String get searchFieldLabel => I18N.of(context).searchStock; + String get searchFieldLabel => L10().searchStock; // List of StockItem results List itemResults = []; @@ -263,7 +263,7 @@ class StockSearchDelegate extends SearchDelegate { _searching = false; showSnackIcon( - "${itemResults.length} ${I18N.of(OneContext().context).results}", + "${itemResults.length} ${L10().results}", success: itemResults.length > 0, icon: FontAwesomeIcons.pollH, ); @@ -340,21 +340,21 @@ class StockSearchDelegate extends SearchDelegate { if (query.length == 0) { return ListTile( - title: Text(I18N.of(context).queryEnter) + title: Text(L10().queryEnter) ); } if (query.length < 3) { return ListTile( - title: Text(I18N.of(context).queryShort), - subtitle: Text(I18N.of(context).queryShortDetail) + title: Text(L10().queryShort), + subtitle: Text(L10().queryShortDetail) ); } if (itemResults.length == 0) { return ListTile( - title: Text(I18N.of(context).noResults), - subtitle: Text(I18N.of(context).queryNoResults + " '${query}'") + title: Text(L10().noResults), + subtitle: Text(L10().queryNoResults + " '${query}'") ); } diff --git a/lib/widget/snacks.dart b/lib/widget/snacks.dart index ad229a81..6bba7277 100644 --- a/lib/widget/snacks.dart +++ b/lib/widget/snacks.dart @@ -12,7 +12,8 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:one_context/one_context.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; + void showSnackIcon(String text, {IconData icon, Function onAction, bool success, String actionText}) { @@ -44,7 +45,7 @@ void showSnackIcon(String text, {IconData icon, Function onAction, bool success, if (actionText == null) { // Default action text - actionText = I18N.of(OneContext().context).details; + actionText = L10().details; } action = SnackBarAction( diff --git a/lib/widget/starred_parts.dart b/lib/widget/starred_parts.dart index aadccd54..8d760400 100644 --- a/lib/widget/starred_parts.dart +++ b/lib/widget/starred_parts.dart @@ -7,7 +7,7 @@ import 'package:InvenTree/widget/refreshable_state.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import '../api.dart'; @@ -26,7 +26,7 @@ class _StarredPartState extends RefreshableState { List starredParts = []; @override - String getAppBarTitle(BuildContext context) => I18N.of(context).partsStarred; + String getAppBarTitle(BuildContext context) => L10().partsStarred; @override Future request(BuildContext context) async { @@ -77,8 +77,8 @@ class _StarredPartState extends RefreshableState { return ListView( children: [ ListTile( - title: Text(I18N.of(context).partsNone), - subtitle: Text(I18N.of(context).partsStarredNone) + title: Text(L10().partsNone), + subtitle: Text(L10().partsStarredNone) ) ], ); diff --git a/lib/widget/stock_detail.dart b/lib/widget/stock_detail.dart index 07c7e278..1d64d6a8 100644 --- a/lib/widget/stock_detail.dart +++ b/lib/widget/stock_detail.dart @@ -16,7 +16,7 @@ import 'package:InvenTree/widget/stock_notes.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import 'package:InvenTree/api.dart'; @@ -37,7 +37,7 @@ class StockDetailWidget extends StatefulWidget { class _StockItemDisplayState extends RefreshableState { @override - String getAppBarTitle(BuildContext context) => I18N.of(context).stockItem; + String getAppBarTitle(BuildContext context) => L10().stockItem; final TextEditingController _quantityController = TextEditingController(); final TextEditingController _notesController = TextEditingController(); @@ -62,7 +62,7 @@ class _StockItemDisplayState extends RefreshableState { /* IconButton( icon: FaIcon(FontAwesomeIcons.edit), - tooltip: I18N.of(context).edit, + tooltip: L10().edit, onPressed: _editPartDialog, ) */ @@ -117,7 +117,7 @@ class _StockItemDisplayState extends RefreshableState { _quantityController.clear(); _notesController.clear(); - showFormDialog( I18N.of(context).addStock, + showFormDialog( L10().addStock, key: _addStockKey, callback: () { _addStock(); @@ -125,12 +125,12 @@ class _StockItemDisplayState extends RefreshableState { fields: [ Text("Current stock: ${item.quantity}"), QuantityField( - label: I18N.of(context).addStock, + label: L10().addStock, controller: _quantityController, ), TextFormField( decoration: InputDecoration( - labelText: I18N.of(context).notes, + labelText: L10().notes, ), controller: _notesController, ) @@ -163,7 +163,7 @@ class _StockItemDisplayState extends RefreshableState { _quantityController.clear(); _notesController.clear(); - showFormDialog(I18N.of(context).removeStock, + showFormDialog(L10().removeStock, key: _removeStockKey, callback: () { _removeStock(); @@ -171,13 +171,13 @@ class _StockItemDisplayState extends RefreshableState { fields: [ Text("Current stock: ${item.quantity}"), QuantityField( - label: I18N.of(context).removeStock, + label: L10().removeStock, controller: _quantityController, max: item.quantity, ), TextFormField( decoration: InputDecoration( - labelText: I18N.of(context).notes, + labelText: L10().notes, ), controller: _notesController, ), @@ -202,21 +202,21 @@ class _StockItemDisplayState extends RefreshableState { _quantityController.text = item.quantityString; _notesController.clear(); - showFormDialog(I18N.of(context).countStock, + showFormDialog(L10().countStock, key: _countStockKey, callback: () { _countStock(); }, - acceptText: I18N.of(context).count, + acceptText: L10().count, fields: [ QuantityField( - label: I18N.of(context).countStock, + label: L10().countStock, hint: "${item.quantityString}", controller: _quantityController, ), TextFormField( decoration: InputDecoration( - labelText: I18N.of(context).notes, + labelText: L10().notes, ), controller: _notesController, ) @@ -231,12 +231,12 @@ class _StockItemDisplayState extends RefreshableState { if (result) { showSnackIcon( - I18N.of(context).stockItemUpdateSuccess, + L10().stockItemUpdateSuccess, success: true ); } else { showSnackIcon( - I18N.of(context).stockItemUpdateFailure, + L10().stockItemUpdateFailure, success: false, ); } @@ -271,14 +271,14 @@ class _StockItemDisplayState extends RefreshableState { _quantityController.text = "${item.quantityString}"; - showFormDialog(I18N.of(context).transferStock, + showFormDialog(L10().transferStock, key: _moveStockKey, callback: () { _transferStock(context, selectedLocation); }, fields: [ QuantityField( - label: I18N.of(context).quantity, + label: L10().quantity, controller: _quantityController, max: item.quantity, ), @@ -304,7 +304,7 @@ class _StockItemDisplayState extends RefreshableState { }, validator: (value) { if (selectedLocation == null) { - return I18N.of(context).selectLocation; + return L10().selectLocation; } return null; @@ -373,7 +373,7 @@ class _StockItemDisplayState extends RefreshableState { if (item.isSerialized()) { tiles.add( ListTile( - title: Text(I18N.of(context).serialNumber), + title: Text(L10().serialNumber), leading: FaIcon(FontAwesomeIcons.hashtag), trailing: Text("${item.serialNumber}"), ) @@ -381,7 +381,7 @@ class _StockItemDisplayState extends RefreshableState { } else { tiles.add( ListTile( - title: Text(I18N.of(context).quantity), + title: Text(L10().quantity), leading: FaIcon(FontAwesomeIcons.cubes), trailing: Text("${item.quantityString}"), ) @@ -392,7 +392,7 @@ class _StockItemDisplayState extends RefreshableState { if ((item.locationId > 0) && (item.locationName != null) && (item.locationName.isNotEmpty)) { tiles.add( ListTile( - title: Text(I18N.of(context).stockLocation), + title: Text(L10().stockLocation), subtitle: Text("${item.locationPathString}"), leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), onTap: () { @@ -408,9 +408,9 @@ class _StockItemDisplayState extends RefreshableState { } else { tiles.add( ListTile( - title: Text(I18N.of(context).stockLocation), + title: Text(L10().stockLocation), leading: FaIcon(FontAwesomeIcons.mapMarkerAlt), - subtitle: Text(I18N.of(context).locationNotSet), + subtitle: Text(L10().locationNotSet), ) ); } @@ -445,7 +445,7 @@ class _StockItemDisplayState extends RefreshableState { if ((item.testResultCount > 0) || (part != null && part.isTrackable)) { tiles.add( ListTile( - title: Text(I18N.of(context).testResults), + title: Text(L10().testResults), leading: FaIcon(FontAwesomeIcons.tasks), trailing: Text("${item.testResultCount}"), onTap: () { @@ -465,7 +465,7 @@ class _StockItemDisplayState extends RefreshableState { if (false && item.trackingItemCount > 0) { tiles.add( ListTile( - title: Text(I18N.of(context).history), + title: Text(L10().history), leading: FaIcon(FontAwesomeIcons.history), trailing: Text("${item.trackingItemCount}"), onTap: () { @@ -481,7 +481,7 @@ class _StockItemDisplayState extends RefreshableState { if (item.notes.isNotEmpty) { tiles.add( ListTile( - title: Text(I18N.of(context).notes), + title: Text(L10().notes), leading: FaIcon(FontAwesomeIcons.stickyNote), trailing: Text(""), onTap: () { @@ -508,14 +508,14 @@ class _StockItemDisplayState extends RefreshableState { if (!InvenTreeAPI().checkPermission('stock', 'change')) { tiles.add( ListTile( - title: Text(I18N.of(context).permissionRequired), + title: Text(L10().permissionRequired), leading: FaIcon(FontAwesomeIcons.userTimes) ) ); tiles.add( ListTile( - subtitle: Text(I18N.of(context).permissionAccountDenied), + subtitle: Text(L10().permissionAccountDenied), ) ); @@ -525,7 +525,7 @@ class _StockItemDisplayState extends RefreshableState { if (!item.isSerialized()) { tiles.add( ListTile( - title: Text(I18N.of(context).countStock), + title: Text(L10().countStock), leading: FaIcon(FontAwesomeIcons.checkCircle), onTap: _countStockDialog, trailing: Text(item.quantityString), @@ -534,7 +534,7 @@ class _StockItemDisplayState extends RefreshableState { tiles.add( ListTile( - title: Text(I18N.of(context).removeStock), + title: Text(L10().removeStock), leading: FaIcon(FontAwesomeIcons.minusCircle), onTap: _removeStockDialog, ) @@ -542,7 +542,7 @@ class _StockItemDisplayState extends RefreshableState { tiles.add( ListTile( - title: Text(I18N.of(context).addStock), + title: Text(L10().addStock), leading: FaIcon(FontAwesomeIcons.plusCircle), onTap: _addStockDialog, ) @@ -551,7 +551,7 @@ class _StockItemDisplayState extends RefreshableState { tiles.add( ListTile( - title: Text(I18N.of(context).transferStock), + title: Text(L10().transferStock), leading: FaIcon(FontAwesomeIcons.exchangeAlt), onTap: _transferStockDialog, ) @@ -560,7 +560,7 @@ class _StockItemDisplayState extends RefreshableState { // Scan item into a location tiles.add( ListTile( - title: Text(I18N.of(context).scanIntoLocation), + title: Text(L10().scanIntoLocation), leading: FaIcon(FontAwesomeIcons.exchangeAlt), trailing: FaIcon(FontAwesomeIcons.qrcode), onTap: () { @@ -578,7 +578,7 @@ class _StockItemDisplayState extends RefreshableState { if (item.uid.isEmpty) { tiles.add( ListTile( - title: Text(I18N.of(context).barcodeAssign), + title: Text(L10().barcodeAssign), leading: FaIcon(FontAwesomeIcons.barcode), trailing: FaIcon(FontAwesomeIcons.qrcode), onTap: () { @@ -594,7 +594,7 @@ class _StockItemDisplayState extends RefreshableState { } else { tiles.add( ListTile( - title: Text(I18N.of(context).barcodeUnassign), + title: Text(L10().barcodeUnassign), leading: FaIcon(FontAwesomeIcons.barcode), onTap: () { _unassignBarcode(context); @@ -614,11 +614,11 @@ class _StockItemDisplayState extends RefreshableState { items: [ BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.infoCircle), - title: Text(I18N.of(context).details), + title: Text(L10().details), ), BottomNavigationBarItem( icon: FaIcon(FontAwesomeIcons.wrench), - title: Text(I18N.of(context).actions), + title: Text(L10().actions), ), ] ); diff --git a/lib/widget/stock_item_test_results.dart b/lib/widget/stock_item_test_results.dart index 6baba8ad..9dad011e 100644 --- a/lib/widget/stock_item_test_results.dart +++ b/lib/widget/stock_item_test_results.dart @@ -7,16 +7,15 @@ import 'package:InvenTree/widget/fields.dart'; import 'package:InvenTree/widget/progress.dart'; import 'package:InvenTree/widget/snacks.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:InvenTree/l10.dart'; import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:InvenTree/widget/refreshable_state.dart'; -import 'package:flutter_speed_dial/flutter_speed_dial.dart'; import 'package:font_awesome_flutter/font_awesome_flutter.dart'; -import 'package:image_picker/image_picker.dart'; + class StockItemTestResultsWidget extends StatefulWidget { @@ -34,7 +33,7 @@ class _StockItemTestResultDisplayState extends RefreshableState(); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).testResults; + String getAppBarTitle(BuildContext context) => L10().testResults; @override Future request(BuildContext context) async { @@ -78,38 +77,38 @@ class _StockItemTestResultDisplayState extends RefreshableState[ StringField( - label: I18N.of(context).testName, + label: L10().testName, initial: name, isEnabled: nameIsEditable, onSaved: (value) => _name = value, ), CheckBoxField( - label: I18N.of(context).result, - hint: I18N.of(context).testPassedOrFailed, + label: L10().result, + hint: L10().testPassedOrFailed, initial: true, onSaved: (value) => _result = value, ), StringField( - label: I18N.of(context).value, + label: L10().value, initial: value, allowEmpty: true, onSaved: (value) => _value = value, validator: (String value) { if (valueRequired && (value == null || value.isEmpty)) { - return I18N.of(context).valueRequired; + return L10().valueRequired; } return null; }, ), ImagePickerField( context, - label: I18N.of(context).attachImage, + label: L10().attachImage, required: attachmentRequired, onSaved: (attachment) => _attachment = attachment, ), StringField( allowEmpty: true, - label: I18N.of(context).notes, + label: L10().notes, onSaved: (value) => _notes = value, ), ] @@ -178,7 +177,7 @@ class _StockItemTestResultDisplayState extends RefreshableState { _StockNotesState(this.item); @override - String getAppBarTitle(BuildContext context) => I18N.of(context).stockItemNotes; + String getAppBarTitle(BuildContext context) => L10().stockItemNotes; @override Widget getBody(BuildContext context) {