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
|
||||
- Fixes bug where API data was not fetched with correct locale
|
||||
|
||||
### 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:http/http.dart" as http;
|
||||
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:cached_network_image/cached_network_image.dart";
|
||||
import "package:flutter/material.dart";
|
||||
@ -772,10 +774,9 @@ class InvenTreeAPI {
|
||||
_request = await client.openUrl("GET", _uri).timeout(Duration(seconds: 10));
|
||||
|
||||
// Set headers
|
||||
_request.headers.set(HttpHeaders.authorizationHeader, _authorizationHeader());
|
||||
_request.headers.set(HttpHeaders.acceptHeader, "application/json");
|
||||
_request.headers.set(HttpHeaders.contentTypeHeader, "application/json");
|
||||
_request.headers.set(HttpHeaders.acceptLanguageHeader, Intl.getCurrentLocale());
|
||||
defaultHeaders().forEach((key, value) {
|
||||
_request?.headers.set(key, value);
|
||||
});
|
||||
|
||||
} on SocketException catch (error) {
|
||||
debug("SocketException at ${url}: ${error.toString()}");
|
||||
@ -1083,10 +1084,9 @@ class InvenTreeAPI {
|
||||
_request = await client.openUrl(method, _uri).timeout(Duration(seconds: 10));
|
||||
|
||||
// Set headers
|
||||
_request.headers.set(HttpHeaders.authorizationHeader, _authorizationHeader());
|
||||
_request.headers.set(HttpHeaders.acceptHeader, "application/json");
|
||||
_request.headers.set(HttpHeaders.contentTypeHeader, "application/json");
|
||||
_request.headers.set(HttpHeaders.acceptLanguageHeader, Intl.getCurrentLocale());
|
||||
defaultHeaders().forEach((key, value) {
|
||||
_request?.headers.set(key, value);
|
||||
});
|
||||
|
||||
return _request;
|
||||
} on SocketException catch (error) {
|
||||
@ -1268,6 +1268,7 @@ class InvenTreeAPI {
|
||||
urlParams: params,
|
||||
);
|
||||
|
||||
|
||||
if (request == null) {
|
||||
// Return an "invalid" 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
|
||||
Map<String, String> defaultHeaders() {
|
||||
Map<String, String> headers = {};
|
||||
@ -1312,7 +1335,7 @@ class InvenTreeAPI {
|
||||
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
||||
headers[HttpHeaders.acceptHeader] = "application/json";
|
||||
headers[HttpHeaders.contentTypeHeader] = "application/json";
|
||||
headers[HttpHeaders.acceptLanguageHeader] = Intl.getCurrentLocale();
|
||||
headers[HttpHeaders.acceptLanguageHeader] = currentLocale;
|
||||
|
||||
return headers;
|
||||
}
|
||||
@ -1527,6 +1550,12 @@ class InvenTreeAPI {
|
||||
InvenTreeStatusCode get StockStatus => _get_status_class("stock/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;
|
||||
|
||||
Timer? _notification_timer;
|
||||
|
@ -152,6 +152,8 @@ class InvenTreeAppState extends State<StatefulWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
Locale? get locale => _locale;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import "package:flutter/material.dart";
|
||||
import "package:inventree/api.dart";
|
||||
import "package:one_context/one_context.dart";
|
||||
|
||||
import "package:adaptive_theme/adaptive_theme.dart";
|
||||
@ -120,6 +121,9 @@ class _InvenTreeAppSettingsState extends State<InvenTreeAppSettingsWidget> {
|
||||
|
||||
// Refresh the entire app locale
|
||||
InvenTreeApp.of(context)?.setLocale(locale);
|
||||
|
||||
// Clear the cached status label information
|
||||
InvenTreeAPI().clearStatusCodeData();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
name: inventree
|
||||
description: InvenTree stock management
|
||||
|
||||
version: 0.12.7+74
|
||||
version: 0.12.8+75
|
||||
|
||||
environment:
|
||||
sdk: ">=2.19.5 <3.13.0"
|
||||
|
Loading…
x
Reference in New Issue
Block a user