feature/internationale #46

Merged
v4l3n71n merged 38 commits from feature/internationale into main 2025-08-06 20:38:37 +00:00
23 changed files with 974 additions and 301 deletions
Showing only changes of commit 5d02f2b1fb - Show all commits

View File

@@ -20,6 +20,11 @@ import '../classes/ad_helper.dart';
import 'package:google_mobile_ads/google_mobile_ads.dart'; import 'package:google_mobile_ads/google_mobile_ads.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 {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await MobileAds.instance.initialize(); await MobileAds.instance.initialize();
@@ -165,7 +170,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
var endDate = "${endDateFormat}T${endTimepicker.text.replaceAll('-', ':')}"; var endDate = "${endDateFormat}T${endTimepicker.text.replaceAll('-', ':')}";
if (!startDateCompare.isAfter(dateNow)) { if (!startDateCompare.isAfter(dateNow)) {
showAlertDialog(context, "Erreur evenement", "Evenement non futur"); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
AppLocalizations.of(context)?.no_future_event ?? "No future event");
return; return;
} }
@@ -173,7 +179,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
var accessToken = prefs.getString("access_token") ?? ""; var accessToken = prefs.getString("access_token") ?? "";
if (accessToken.isEmpty) { if (accessToken.isEmpty) {
showAlertDialog(context, "Erreur token", "Token d'accès manquant"); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Token d'accès manquant");
return; return;
} }
@@ -188,14 +195,15 @@ class _UpdateeventImageState extends State<UpdateeventImage>
final searchboxResponse = await http.get(searchboxUrl); final searchboxResponse = await http.get(searchboxUrl);
if (searchboxResponse.statusCode != 200) { if (searchboxResponse.statusCode != 200) {
showAlertDialog(context, "Erreur map", showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Erreur lors de la géocodage avec Searchbox"); "Erreur lors de la géocodage avec Searchbox");
return; return;
} }
final searchboxData = json.decode(searchboxResponse.body); final searchboxData = json.decode(searchboxResponse.body);
if (searchboxData['results'].isEmpty) { if (searchboxData['results'].isEmpty) {
showAlertDialog(context, "Erreur", "Lieu introuvable"); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Lieu introuvable");
return; return;
} }
@@ -239,8 +247,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
await http.Response.fromStream(await imgbbRequest.send()); await http.Response.fromStream(await imgbbRequest.send());
if (imgbbResponse.statusCode != 200) { if (imgbbResponse.statusCode != 200) {
showAlertDialog( showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
context, "Erreur serveur", "Erreur lors de l'upload d'image"); "Erreur lors de l'upload d'image");
return; return;
} }
@@ -276,22 +284,26 @@ class _UpdateeventImageState extends State<UpdateeventImage>
handleHttpError(eventResponse.statusCode, context); handleHttpError(eventResponse.statusCode, context);
} }
} catch (e) { } catch (e) {
showAlertDialog(context, "Erreur", "Erreur: ${e.toString()}"); showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
"Erreur: ${e.toString()}");
} }
} }
// Utility function to handle HTTP errors // Utility function to handle HTTP errors
void handleHttpError(int statusCode, BuildContext context) { void handleHttpError(int statusCode, BuildContext context) {
final errorMessages = { final messages = {
400: "Requête mal construite", 400: AppLocalizations.of(context)?.request_error ??
403: "Utilisateur désactivé", "Poorly constructed query",
404: "Utilisateur inconnu", 406: AppLocalizations.of(context)?.incorrect_password ??
406: "Mot de passe incorrect", "Incorrect password",
410: "Token invalide", 404: AppLocalizations.of(context)?.unknown_user ?? "Unknown user",
500: "Problème interne du serveur", 403: AppLocalizations.of(context)?.disabled_user ?? "Disabled user",
410: AppLocalizations.of(context)?.invalid_token ?? "Invalid token",
500: AppLocalizations.of(context)?.internal_error_server ??
"Internal error server"
}; };
showAlertDialog(context, "Erreur serveur", showAlertDialog(context, AppLocalizations.of(context)?.error ?? "Error",
errorMessages[statusCode] ?? "Erreur inconnue"); messages[statusCode] ?? "Unknown error");
} }
void start() async { void start() async {
@@ -344,11 +356,9 @@ class _UpdateeventImageState extends State<UpdateeventImage>
// Perform the request // Perform the request
final response = await http.get(searchboxUrl); final response = await http.get(searchboxUrl);
print("response code suggestion: ${response.statusCode}");
if (response.statusCode == 200) { if (response.statusCode == 200) {
final data = json.decode(response.body); final data = json.decode(response.body);
print("data suggestion: ${data}");
setState(() { setState(() {
// Map the results to extract name and full_address // Map the results to extract name and full_address
@@ -432,7 +442,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
return Scaffold( return Scaffold(
backgroundColor: Colors.white, backgroundColor: Colors.white,
appBar: AppBar( appBar: AppBar(
title: Text("Add or Update a event"), title: Text(AppLocalizations.of(context)?.add_event ??
"Add or Update a event"),
backgroundColor: Colors.blue, backgroundColor: Colors.blue,
foregroundColor: Colors.white, foregroundColor: Colors.white,
), ),
@@ -467,8 +478,10 @@ class _UpdateeventImageState extends State<UpdateeventImage>
validator: (value) => _validateField(value), validator: (value) => _validateField(value),
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Nom', labelText: AppLocalizations.of(context)?.name ?? "Name",
hintText: 'Modifier le nom de l\'évènement'), hintText:
AppLocalizations.of(context)?.edit_event_name ??
"Edit event name"),
), ),
), ),
_buildGeographicalZoneSearchField(), _buildGeographicalZoneSearchField(),
@@ -482,8 +495,10 @@ class _UpdateeventImageState extends State<UpdateeventImage>
validator: (value) => _validateField(value), validator: (value) => _validateField(value),
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Date de debut', labelText: AppLocalizations.of(context)?.start_date ??
hintText: 'Cliquez ici pour selectionner une date'), "Start date",
hintText: AppLocalizations.of(context)?.select_date ??
"Click to select a date"),
onTap: () => onTapFunctionDatePicker( onTap: () => onTapFunctionDatePicker(
context: context, position: "start")), context: context, position: "start")),
), ),
@@ -497,8 +512,10 @@ class _UpdateeventImageState extends State<UpdateeventImage>
validator: (value) => _validateField(value), validator: (value) => _validateField(value),
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Heure de debut', labelText: AppLocalizations.of(context)?.start_time ??
hintText: 'Cliquez ici pour selectionner une heure'), "Start time",
hintText: AppLocalizations.of(context)?.select_time ??
"Click to select a time"),
onTap: () => onTapFunctionTimePicker( onTap: () => onTapFunctionTimePicker(
context: context, position: "start")), context: context, position: "start")),
), ),
@@ -512,8 +529,10 @@ class _UpdateeventImageState extends State<UpdateeventImage>
validator: (value) => _validateField(value), validator: (value) => _validateField(value),
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Date de fin', labelText: AppLocalizations.of(context)?.end_date ??
hintText: 'Cliquez ici pour selectionner une date'), "End date",
hintText: AppLocalizations.of(context)?.select_date ??
"Click to select a date"),
onTap: () => onTapFunctionDatePicker( onTap: () => onTapFunctionDatePicker(
context: context, position: "end")), context: context, position: "end")),
), ),
@@ -527,8 +546,10 @@ class _UpdateeventImageState extends State<UpdateeventImage>
validator: (value) => _validateField(value), validator: (value) => _validateField(value),
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Heure de fin', labelText: AppLocalizations.of(context)?.end_time ??
hintText: 'Cliquez ici pour selectionner une heure'), "End time",
hintText: AppLocalizations.of(context)?.select_time ??
"Click to select a time"),
onTap: () => onTapFunctionTimePicker( onTap: () => onTapFunctionTimePicker(
context: context, position: "end")), context: context, position: "end")),
), ),
@@ -538,7 +559,8 @@ class _UpdateeventImageState extends State<UpdateeventImage>
textSeparators: const [' ', ','], textSeparators: const [' ', ','],
validator: (String tag) { validator: (String tag) {
if (_stringTagController.getTags!.contains(tag)) { if (_stringTagController.getTags!.contains(tag)) {
return 'Tu as deja rentre ce tag'; return AppLocalizations.of(context)?.already_tag ??
'You have already entered this tag';
} }
return null; return null;
}, },
@@ -553,10 +575,12 @@ class _UpdateeventImageState extends State<UpdateeventImage>
onSubmitted: inputFieldValues.onTagSubmitted, onSubmitted: inputFieldValues.onTagSubmitted,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Tags', labelText:
AppLocalizations.of(context)?.tag ?? 'Tags',
hintText: inputFieldValues.tags.isNotEmpty hintText: inputFieldValues.tags.isNotEmpty
? '' ? ''
: "Enter tag...", : AppLocalizations.of(context)?.enter_tag ??
"Enter tag...",
errorText: inputFieldValues.error, errorText: inputFieldValues.error,
prefixIcon: inputFieldValues.tags.isNotEmpty prefixIcon: inputFieldValues.tags.isNotEmpty
? SingleChildScrollView( ? SingleChildScrollView(
@@ -633,7 +657,9 @@ class _UpdateeventImageState extends State<UpdateeventImage>
textSeparators: const [','], textSeparators: const [','],
validator: (String tag) { validator: (String tag) {
if (_stringOrgaController.getTags!.contains(tag)) { if (_stringOrgaController.getTags!.contains(tag)) {
return 'Cet organisateur est déjà rentré'; return AppLocalizations.of(context)
?.already_organiser ??
'You have already entered this organizer';
} }
return null; return null;
}, },
@@ -648,10 +674,14 @@ class _UpdateeventImageState extends State<UpdateeventImage>
onSubmitted: inputFieldValues.onTagSubmitted, onSubmitted: inputFieldValues.onTagSubmitted,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Organisateurs', labelText:
AppLocalizations.of(context)?.organizer ??
'Organizers',
hintText: inputFieldValues.tags.isNotEmpty hintText: inputFieldValues.tags.isNotEmpty
? '' ? ''
: "Enter un organisateur...", : AppLocalizations.of(context)
?.enter_organizer ??
"Enter un organisateur...",
errorText: inputFieldValues.error, errorText: inputFieldValues.error,
prefixIcon: inputFieldValues.tags.isNotEmpty prefixIcon: inputFieldValues.tags.isNotEmpty
? SingleChildScrollView( ? SingleChildScrollView(
@@ -732,8 +762,11 @@ class _UpdateeventImageState extends State<UpdateeventImage>
maxLines: 10, maxLines: 10,
decoration: InputDecoration( decoration: InputDecoration(
border: OutlineInputBorder(), border: OutlineInputBorder(),
labelText: 'Description', labelText: AppLocalizations.of(context)?.description ??
hintText: 'Décrire l\'evènement'), 'Description',
hintText:
AppLocalizations.of(context)?.describe_event ??
'Describe the event'),
), ),
), ),
SizedBox( SizedBox(
@@ -752,7 +785,7 @@ class _UpdateeventImageState extends State<UpdateeventImage>
} }
}, },
child: Text( child: Text(
'Ajouter', AppLocalizations.of(context)?.add_event ?? 'Add',
style: TextStyle(color: Colors.white, fontSize: 25), style: TextStyle(color: Colors.white, fontSize: 25),
), ),
), ),