CWA-174 | added localeDetection() to Language class, moved languages from change_language.dart to language.dart, localeDetection() called in the settings store

This commit is contained in:
Oleksandr Sobol
2020-02-26 19:18:58 +02:00
parent 35f1498331
commit 90f66274a2
5 changed files with 40 additions and 22 deletions
+24
View File
@@ -1,4 +1,21 @@
import 'package:flutter/material.dart';
import 'package:devicelocale/devicelocale.dart';
import 'package:intl/intl.dart';
const Map<String, String> languages = {
'en': 'English',
'de': 'Deutsch (German)',
'es': 'Español (Spanish)',
'hi': 'हिंदी (Hindi)',
'ja': '日本 (Japanese)',
'ko': '한국어 (Korean)',
'nl': 'Nederlands (Dutch)',
'pl': 'Polski (Polish)',
'pt': 'Português (Portuguese)',
'ru': 'Русский (Russian)',
'uk': 'Українська (Ukrainian)',
'zh': '中文 (Chinese)'
};
class Language with ChangeNotifier {
Language(this._currentLanguage);
@@ -11,4 +28,11 @@ class Language with ChangeNotifier {
_currentLanguage = language;
notifyListeners();
}
static Future<String> localeDetection() async {
String locale = await Devicelocale.currentLocale;
locale = Intl.shortLocale(locale);
return languages.keys.contains(locale) ? locale : 'en';
}
}