translate mapbox page 10%

This commit is contained in:
2025-07-27 20:04:55 +02:00
parent 2c2eedb7ce
commit dcc2ec25de
2 changed files with 37 additions and 36 deletions

View File

@@ -107,5 +107,5 @@
"enter_existing_pseudo": "Enter a existing pseudo", "enter_existing_pseudo": "Enter a existing pseudo",
"remembr_me": "Remember me", "remembr_me": "Remember me",
"new_user": "New User? Create Account", "new_user": "New User? Create Account",
"sign_in": "Sign in" "sign_in": "Sign in",
} }

View File

@@ -13,6 +13,11 @@ import '../variable/globals.dart' as globals;
import '../classes/MyDrawer.dart'; import '../classes/MyDrawer.dart';
import '../classes/auth_service.dart'; import '../classes/auth_service.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:provider/provider.dart';
import '../locale_provider.dart'; //
void main() async { void main() async {
await dotenv.load(fileName: ".env"); // Load .env file await dotenv.load(fileName: ".env"); // Load .env file
runApp(const MyApp()); runApp(const MyApp());
@@ -69,8 +74,8 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
void _initToken() { void _initToken() {
mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? ''; mapboxAccessToken = dotenv.env['MAPBOX_ACCESS_TOKEN'] ?? '';
if (mapboxAccessToken.isEmpty) { if (mapboxAccessToken.isEmpty) {
showAlertDialog( showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
context, "Erreur Mapbox", "Mapbox Access Token is not available."); "Mapbox Access Token is not available.");
} }
} }
@@ -95,43 +100,37 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
_handleErrorResponse(responseGet.statusCode); _handleErrorResponse(responseGet.statusCode);
} }
} else { } else {
showAlertDialog(context, "Erreur serveur", "Invalid cache."); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
AppLocalizations.of(context)?.invalid_cache ?? "Invalid cache.");
} }
} }
void _handleErrorResponse(int statusCode) { void _handleErrorResponse(int statusCode) {
String text; final messages = {
switch (statusCode) { 400: AppLocalizations.of(context)?.request_error ??
case 400: "Poorly constructed query",
text = "Bad Request."; 406: AppLocalizations.of(context)?.incorrect_password ??
break; "Incorrect password",
case 406: 404: AppLocalizations.of(context)?.unknown_user ?? "Unknown user",
text = "Incorrect Password."; 403: AppLocalizations.of(context)?.disabled_user ?? "Disabled user",
break; 410: AppLocalizations.of(context)?.invalid_token ?? "Invalid token",
case 404: 500: AppLocalizations.of(context)?.internal_error_server ??
text = "User Not Found."; "Internal error server"
break; };
case 403:
text = "Action not permitted."; final errorMessage = messages[statusCode] ??
break; AppLocalizations.of(context)?.unknown_error_auth ??
case 410: "Unknown error auth";
text = "Invalid Token."; showAlertDialog(
break; context, AppLocalizations.of(context)?.error ?? "Error", errorMessage);
case 500:
text = "Internal Server Error.";
break;
default:
text = "Unknown error.";
}
showAlertDialog(context, "Erreur serveur", text);
} }
Future<void> _getUserLocation() async { Future<void> _getUserLocation() async {
try { try {
bool serviceEnabled = await Geolocator.isLocationServiceEnabled(); bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
if (!serviceEnabled) { if (!serviceEnabled) {
showAlertDialog( showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
context, "Erreur de service", "Location services are disabled."); "Location services are disabled.");
return; return;
} }
@@ -139,14 +138,16 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
if (permission == LocationPermission.denied) { if (permission == LocationPermission.denied) {
permission = await Geolocator.requestPermission(); permission = await Geolocator.requestPermission();
if (permission == LocationPermission.denied) { if (permission == LocationPermission.denied) {
showAlertDialog(context, "Erreur de permission", showAlertDialog(
context,
AppLocalizations.of(context)?.error ?? "Error",
"Location permissions are denied."); "Location permissions are denied.");
return; return;
} }
} }
if (permission == LocationPermission.deniedForever) { if (permission == LocationPermission.deniedForever) {
showAlertDialog(context, "Erreur de permission", showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Location permissions are permanently denied. Enable them in settings."); "Location permissions are permanently denied. Enable them in settings.");
return; return;
} }
@@ -158,7 +159,6 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
locationSettings: locationSettings); locationSettings: locationSettings);
} on LocationServiceDisabledException { } on LocationServiceDisabledException {
// Handle location services disabled // Handle location services disabled
print('Location services are disabled.');
position = await Geolocator.getLastKnownPosition(); position = await Geolocator.getLastKnownPosition();
if (position == null) { if (position == null) {
print('No last known position available.'); print('No last known position available.');
@@ -180,7 +180,8 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
_initToken(); _initToken();
_getEventInfo(); _getEventInfo();
} catch (e) { } catch (e) {
showAlertDialog(context, "Erreur geo", "Failed to get user location: $e"); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Failed to get user location: $e");
} }
} }
@@ -253,7 +254,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
currentRouteLine = null; currentRouteLine = null;
} }
if (!isUserPositionInitialized) { if (!isUserPositionInitialized) {
showAlertDialog(context, "Erreur de position", showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"User position is not yet initialized. Try again."); "User position is not yet initialized. Try again.");
return; return;
} }
@@ -293,7 +294,7 @@ class _MapboxPagesState extends State<MapboxPages> with ShowAlertDialog {
_zoomToFitRoute(routeCoordinates); _zoomToFitRoute(routeCoordinates);
} }
} else { } else {
showAlertDialog(context, "Erreur de coordonée", showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Invalid coordinates or user position."); "Invalid coordinates or user position.");
} }
} }