2020-01-04 19:31:52 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2020-02-26 17:18:58 +00:00
|
|
|
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)'
|
|
|
|
};
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
class Language with ChangeNotifier {
|
2020-01-08 12:26:34 +00:00
|
|
|
Language(this._currentLanguage);
|
2020-01-04 19:31:52 +00:00
|
|
|
|
|
|
|
String _currentLanguage;
|
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
String getCurrentLanguage() => _currentLanguage;
|
2020-01-04 19:31:52 +00:00
|
|
|
|
2020-01-08 12:26:34 +00:00
|
|
|
void setCurrentLanguage(String language) {
|
2020-01-04 19:31:52 +00:00
|
|
|
_currentLanguage = language;
|
|
|
|
notifyListeners();
|
|
|
|
}
|
2020-02-26 17:18:58 +00:00
|
|
|
|
|
|
|
static Future<String> localeDetection() async {
|
2020-09-07 17:35:34 +00:00
|
|
|
var locale = await Devicelocale.currentLocale;
|
2020-02-26 17:18:58 +00:00
|
|
|
locale = Intl.shortLocale(locale);
|
|
|
|
|
|
|
|
return languages.keys.contains(locale) ? locale : 'en';
|
|
|
|
}
|
2020-01-04 19:31:52 +00:00
|
|
|
}
|