95 lines
2.9 KiB
Dart
95 lines
2.9 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
|
|
class LocalizationService {
|
|
static final LocalizationService _instance = LocalizationService._internal();
|
|
static LocalizationService get instance => _instance;
|
|
|
|
Locale _currentLocale = const Locale('id');
|
|
Locale get currentLocale => _currentLocale;
|
|
|
|
final Map<String, Map<String, String>> _localizedValues = {
|
|
'id': {
|
|
// Common
|
|
'app_name': 'Plant Disease Detection',
|
|
'ok': 'OK',
|
|
'cancel': 'Batal',
|
|
'back': 'Kembali',
|
|
'retry': 'Coba Lagi',
|
|
'error': 'Error',
|
|
'success': 'Berhasil',
|
|
|
|
// Plant Scanner
|
|
'analyze_plant': 'Analisis Tanaman',
|
|
'take_photo': 'Ambil Foto',
|
|
'choose_from_gallery': 'Pilih dari Galeri',
|
|
'analyzing': 'Menganalisis...',
|
|
'plant_detected': 'Tanaman Terdeteksi',
|
|
'no_plant_detected': 'Tidak Ada Tanaman Terdeteksi',
|
|
'disease_detected': 'Penyakit Terdeteksi',
|
|
'healthy_plant': 'Tanaman Sehat',
|
|
'symptoms': 'Gejala',
|
|
'treatment': 'Pengobatan',
|
|
'prevention': 'Pencegahan',
|
|
'confidence': 'Tingkat Kepercayaan',
|
|
|
|
// Help Dialog
|
|
'help_title': 'Panduan Penggunaan',
|
|
'help_take_clear_photo': 'Ambil foto dengan pencahayaan yang baik',
|
|
'help_focus_infected': 'Fokus pada bagian tanaman yang terinfeksi',
|
|
'help_ensure_clear': 'Pastikan gambar jelas dan tidak buram',
|
|
'got_it': 'Mengerti',
|
|
},
|
|
'en': {
|
|
// Common
|
|
'app_name': 'Plant Disease Detection',
|
|
'ok': 'OK',
|
|
'cancel': 'Cancel',
|
|
'back': 'Back',
|
|
'retry': 'Retry',
|
|
'error': 'Error',
|
|
'success': 'Success',
|
|
|
|
// Plant Scanner
|
|
'analyze_plant': 'Analyze Plant',
|
|
'take_photo': 'Take Photo',
|
|
'choose_from_gallery': 'Choose from Gallery',
|
|
'analyzing': 'Analyzing...',
|
|
'plant_detected': 'Plant Detected',
|
|
'no_plant_detected': 'No Plant Detected',
|
|
'disease_detected': 'Disease Detected',
|
|
'healthy_plant': 'Healthy Plant',
|
|
'symptoms': 'Symptoms',
|
|
'treatment': 'Treatment',
|
|
'prevention': 'Prevention',
|
|
'confidence': 'Confidence',
|
|
|
|
// Help Dialog
|
|
'help_title': 'Usage Guide',
|
|
'help_take_clear_photo': 'Take a photo with good lighting',
|
|
'help_focus_infected': 'Focus on the infected part of the plant',
|
|
'help_ensure_clear': 'Ensure the image is clear and not blurry',
|
|
'got_it': 'Got it',
|
|
},
|
|
};
|
|
|
|
LocalizationService._internal();
|
|
|
|
String getString(String key) {
|
|
return _localizedValues[_currentLocale.languageCode]?[key] ?? key;
|
|
}
|
|
|
|
void setLocale(Locale locale) {
|
|
if (_localizedValues.containsKey(locale.languageCode)) {
|
|
_currentLocale = locale;
|
|
}
|
|
}
|
|
|
|
bool isIndonesian() {
|
|
return _currentLocale.languageCode == 'id';
|
|
}
|
|
|
|
void toggleLanguage() {
|
|
setLocale(_currentLocale.languageCode == 'id' ? const Locale('en') : const Locale('id'));
|
|
}
|
|
} |