2021-03-24 16:52:30 +00:00
|
|
|
import 'package:cake_wallet/generated/locales.dart';
|
2020-09-28 15:47:43 +00:00
|
|
|
import 'package:devicelocale/devicelocale.dart';
|
|
|
|
import 'package:intl/intl.dart';
|
|
|
|
|
|
|
|
class LanguageService {
|
2021-03-24 16:52:30 +00:00
|
|
|
static const Map<String, String> supportedLocales = {
|
2020-09-28 15:47:43 +00:00
|
|
|
'en': 'English',
|
|
|
|
'de': 'Deutsch (German)',
|
|
|
|
'es': 'Español (Spanish)',
|
2022-03-09 12:06:34 +00:00
|
|
|
'fr': 'Français (French)',
|
2020-09-28 15:47:43 +00:00
|
|
|
'hi': 'हिंदी (Hindi)',
|
|
|
|
'ja': '日本 (Japanese)',
|
|
|
|
'ko': '한국어 (Korean)',
|
|
|
|
'nl': 'Nederlands (Dutch)',
|
|
|
|
'pl': 'Polski (Polish)',
|
|
|
|
'pt': 'Português (Portuguese)',
|
|
|
|
'ru': 'Русский (Russian)',
|
|
|
|
'uk': 'Українська (Ukrainian)',
|
2021-05-05 16:12:06 +00:00
|
|
|
'zh': '中文 (Chinese)',
|
2021-05-10 16:26:52 +00:00
|
|
|
'hr': 'Hrvatski (Croatian)',
|
2021-04-23 15:33:51 +00:00
|
|
|
'it': 'Italiano (Italian)'
|
2020-09-28 15:47:43 +00:00
|
|
|
};
|
2021-03-24 16:52:30 +00:00
|
|
|
static final list = <String, String> {};
|
|
|
|
|
|
|
|
static void loadLocaleList() {
|
|
|
|
supportedLocales.forEach((key, value) {
|
|
|
|
if (locales.contains(key)) {
|
|
|
|
list[key] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-09-28 15:47:43 +00:00
|
|
|
|
|
|
|
static Future<String> localeDetection() async {
|
|
|
|
var locale = await Devicelocale.currentLocale;
|
|
|
|
locale = Intl.shortLocale(locale);
|
|
|
|
|
|
|
|
return list.keys.contains(locale) ? locale : 'en';
|
|
|
|
}
|
|
|
|
}
|