redesigned / search by submit / fixes
This commit is contained in:
46
lib/localizations.dart
Normal file
46
lib/localizations.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class AppLocalizations {
|
||||
static final AppLocalizations _singleton = new AppLocalizations._internal();
|
||||
AppLocalizations._internal();
|
||||
static AppLocalizations get instance => _singleton;
|
||||
|
||||
Map<dynamic, dynamic> _localisedValues;
|
||||
Locale _currentLocale;
|
||||
|
||||
Future<AppLocalizations> load(Locale locale) async {
|
||||
String jsonContent = await rootBundle
|
||||
.loadString("locale/locale_${locale.languageCode}.json");
|
||||
_localisedValues = json.decode(jsonContent);
|
||||
_currentLocale = locale;
|
||||
return this;
|
||||
}
|
||||
|
||||
String getLocale() {
|
||||
return _currentLocale.languageCode;
|
||||
}
|
||||
|
||||
String text(String key) {
|
||||
return _localisedValues[key] ?? "$key not found";
|
||||
}
|
||||
}
|
||||
|
||||
class AppLocalizationsDelegate extends LocalizationsDelegate<AppLocalizations> {
|
||||
const AppLocalizationsDelegate();
|
||||
|
||||
@override
|
||||
bool isSupported(Locale locale) =>
|
||||
['en', 'pl', 'de'].contains(locale.languageCode);
|
||||
|
||||
@override
|
||||
Future<AppLocalizations> load(Locale locale) {
|
||||
return AppLocalizations.instance.load(locale);
|
||||
}
|
||||
|
||||
@override
|
||||
bool shouldReload(AppLocalizationsDelegate old) => true;
|
||||
}
|
||||
Reference in New Issue
Block a user