Files
meshcore-sar_android/lib/services/locale_preferences.dart
Janez T 52b2f4ede1 Add localization support for German, Spanish, French, and Italian
- Updated localization files for French, Croatian, Italian, Slovenian to include translations for German, Spanish, French, and Italian.
- Added new methods for handling drawing messages sent to the public channel in multiple languages.
- Enhanced the Contact model to identify public channels using a dedicated method.
- Implemented echo detection for public channel messages, including tracking and reporting of echoes.
- Updated BLE response handling to support echo detection and tracking of sent messages.
- Modified UI components to reflect new localization strings and echo statuses.
2025-10-18 22:39:26 +02:00

91 lines
2.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
/// Service for managing locale preferences
class LocalePreferences {
static const String _localeKey = 'app_locale';
/// Supported locales
static const List<Locale> supportedLocales = [
Locale('en'), // English
Locale('sl'), // Slovenian
Locale('hr'), // Croatian
Locale('de'), // German
Locale('es'), // Spanish
Locale('fr'), // French
Locale('it'), // Italian
];
/// Get the saved locale or return null to use system locale
static Future<Locale?> getLocale() async {
final prefs = await SharedPreferences.getInstance();
final localeCode = prefs.getString(_localeKey);
if (localeCode == null) {
return null; // Use system locale
}
return Locale(localeCode);
}
/// Save the selected locale
static Future<void> setLocale(Locale? locale) async {
final prefs = await SharedPreferences.getInstance();
if (locale == null) {
// Remove preference to use system locale
await prefs.remove(_localeKey);
} else {
await prefs.setString(_localeKey, locale.languageCode);
}
}
/// Get display name for a locale
static String getDisplayName(Locale? locale) {
if (locale == null) {
return 'System Default';
}
switch (locale.languageCode) {
case 'en':
return 'English';
case 'sl':
return 'Slovenščina';
case 'hr':
return 'Hrvatski';
case 'de':
return 'Deutsch';
case 'es':
return 'Español';
case 'fr':
return 'Français';
case 'it':
return 'Italiano';
default:
return locale.languageCode;
}
}
/// Get native display name for a locale (shown in selection dialog)
static String getNativeDisplayName(Locale locale) {
switch (locale.languageCode) {
case 'en':
return 'English';
case 'sl':
return 'Slovenščina';
case 'hr':
return 'Hrvatski';
case 'de':
return 'Deutsch';
case 'es':
return 'Español';
case 'fr':
return 'Français';
case 'it':
return 'Italiano';
default:
return locale.languageCode;
}
}
}