cake_wallet/lib/entities/language.dart

38 lines
1,002 B
Dart
Raw Normal View History

2020-01-04 19:31:52 +00:00
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)'
};
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();
}
static Future<String> localeDetection() async {
var locale = await Devicelocale.currentLocale;
locale = Intl.shortLocale(locale);
return languages.keys.contains(locale) ? locale : 'en';
}
2020-01-04 19:31:52 +00:00
}