mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Translation fix (#424)
* Fix locale header - Moving to new framework meant that Intl.getCurrentLocale was no longer working * Update release notes * Fix typo in pubspec.yaml * Clear cached values when locale is changed * Add extra context check
This commit is contained in:
parent
dd12769a51
commit
6520873384
@ -2,6 +2,7 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
- Added extra options for transferring stock items
|
- Added extra options for transferring stock items
|
||||||
|
- Fixes bug where API data was not fetched with correct locale
|
||||||
|
|
||||||
### 0.12.7 - August 2023
|
### 0.12.7 - August 2023
|
||||||
---
|
---
|
||||||
|
47
lib/api.dart
47
lib/api.dart
@ -5,6 +5,8 @@ import "dart:io";
|
|||||||
import "package:flutter/foundation.dart";
|
import "package:flutter/foundation.dart";
|
||||||
import "package:http/http.dart" as http;
|
import "package:http/http.dart" as http;
|
||||||
import "package:intl/intl.dart";
|
import "package:intl/intl.dart";
|
||||||
|
import "package:inventree/main.dart";
|
||||||
|
import "package:one_context/one_context.dart";
|
||||||
import "package:open_filex/open_filex.dart";
|
import "package:open_filex/open_filex.dart";
|
||||||
import "package:cached_network_image/cached_network_image.dart";
|
import "package:cached_network_image/cached_network_image.dart";
|
||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
@ -772,10 +774,9 @@ class InvenTreeAPI {
|
|||||||
_request = await client.openUrl("GET", _uri).timeout(Duration(seconds: 10));
|
_request = await client.openUrl("GET", _uri).timeout(Duration(seconds: 10));
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
_request.headers.set(HttpHeaders.authorizationHeader, _authorizationHeader());
|
defaultHeaders().forEach((key, value) {
|
||||||
_request.headers.set(HttpHeaders.acceptHeader, "application/json");
|
_request?.headers.set(key, value);
|
||||||
_request.headers.set(HttpHeaders.contentTypeHeader, "application/json");
|
});
|
||||||
_request.headers.set(HttpHeaders.acceptLanguageHeader, Intl.getCurrentLocale());
|
|
||||||
|
|
||||||
} on SocketException catch (error) {
|
} on SocketException catch (error) {
|
||||||
debug("SocketException at ${url}: ${error.toString()}");
|
debug("SocketException at ${url}: ${error.toString()}");
|
||||||
@ -1083,10 +1084,9 @@ class InvenTreeAPI {
|
|||||||
_request = await client.openUrl(method, _uri).timeout(Duration(seconds: 10));
|
_request = await client.openUrl(method, _uri).timeout(Duration(seconds: 10));
|
||||||
|
|
||||||
// Set headers
|
// Set headers
|
||||||
_request.headers.set(HttpHeaders.authorizationHeader, _authorizationHeader());
|
defaultHeaders().forEach((key, value) {
|
||||||
_request.headers.set(HttpHeaders.acceptHeader, "application/json");
|
_request?.headers.set(key, value);
|
||||||
_request.headers.set(HttpHeaders.contentTypeHeader, "application/json");
|
});
|
||||||
_request.headers.set(HttpHeaders.acceptLanguageHeader, Intl.getCurrentLocale());
|
|
||||||
|
|
||||||
return _request;
|
return _request;
|
||||||
} on SocketException catch (error) {
|
} on SocketException catch (error) {
|
||||||
@ -1268,6 +1268,7 @@ class InvenTreeAPI {
|
|||||||
urlParams: params,
|
urlParams: params,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
// Return an "invalid" APIResponse
|
// Return an "invalid" APIResponse
|
||||||
return APIResponse(
|
return APIResponse(
|
||||||
@ -1305,6 +1306,28 @@ class InvenTreeAPI {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Find the current locale code for the running app
|
||||||
|
String get currentLocale {
|
||||||
|
|
||||||
|
if (OneContext.hasContext) {
|
||||||
|
// Try to get app context
|
||||||
|
BuildContext? context = OneContext().context;
|
||||||
|
|
||||||
|
if (context != null) {
|
||||||
|
Locale? locale = InvenTreeApp
|
||||||
|
.of(context)
|
||||||
|
?.locale;
|
||||||
|
|
||||||
|
if (locale != null) {
|
||||||
|
return locale.languageCode; //.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback value
|
||||||
|
return Intl.getCurrentLocale();
|
||||||
|
}
|
||||||
|
|
||||||
// Return a list of request headers
|
// Return a list of request headers
|
||||||
Map<String, String> defaultHeaders() {
|
Map<String, String> defaultHeaders() {
|
||||||
Map<String, String> headers = {};
|
Map<String, String> headers = {};
|
||||||
@ -1312,7 +1335,7 @@ class InvenTreeAPI {
|
|||||||
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
||||||
headers[HttpHeaders.acceptHeader] = "application/json";
|
headers[HttpHeaders.acceptHeader] = "application/json";
|
||||||
headers[HttpHeaders.contentTypeHeader] = "application/json";
|
headers[HttpHeaders.contentTypeHeader] = "application/json";
|
||||||
headers[HttpHeaders.acceptLanguageHeader] = Intl.getCurrentLocale();
|
headers[HttpHeaders.acceptLanguageHeader] = currentLocale;
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
@ -1527,6 +1550,12 @@ class InvenTreeAPI {
|
|||||||
InvenTreeStatusCode get StockStatus => _get_status_class("stock/status/");
|
InvenTreeStatusCode get StockStatus => _get_status_class("stock/status/");
|
||||||
InvenTreeStatusCode get PurchaseOrderStatus => _get_status_class("order/po/status/");
|
InvenTreeStatusCode get PurchaseOrderStatus => _get_status_class("order/po/status/");
|
||||||
|
|
||||||
|
void clearStatusCodeData() {
|
||||||
|
StockHistoryStatus.data.clear();
|
||||||
|
StockStatus.data.clear();
|
||||||
|
PurchaseOrderStatus.data.clear();
|
||||||
|
}
|
||||||
|
|
||||||
int notification_counter = 0;
|
int notification_counter = 0;
|
||||||
|
|
||||||
Timer? _notification_timer;
|
Timer? _notification_timer;
|
||||||
|
@ -152,6 +152,8 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Locale? get locale => _locale;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import "package:flutter/material.dart";
|
import "package:flutter/material.dart";
|
||||||
|
import "package:inventree/api.dart";
|
||||||
import "package:one_context/one_context.dart";
|
import "package:one_context/one_context.dart";
|
||||||
|
|
||||||
import "package:adaptive_theme/adaptive_theme.dart";
|
import "package:adaptive_theme/adaptive_theme.dart";
|
||||||
@ -120,6 +121,9 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
|||||||
|
|
||||||
// Refresh the entire app locale
|
// Refresh the entire app locale
|
||||||
InvenTreeApp.of(context)?.setLocale(locale);
|
InvenTreeApp.of(context)?.setLocale(locale);
|
||||||
|
|
||||||
|
// Clear the cached status label information
|
||||||
|
InvenTreeAPI().clearStatusCodeData();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
name: inventree
|
name: inventree
|
||||||
description: InvenTree stock management
|
description: InvenTree stock management
|
||||||
|
|
||||||
version: 0.12.7+74
|
version: 0.12.8+75
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.19.5 <3.13.0"
|
sdk: ">=2.19.5 <3.13.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user