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)',
|
2023-01-06 15:14:33 +00:00
|
|
|
'it': 'Italiano (Italian)',
|
2023-01-06 15:27:18 +00:00
|
|
|
'th': 'ภาษาไทย (Thai)',
|
2023-01-10 23:19:16 +00:00
|
|
|
'ar': 'العربية (Arabic)',
|
2023-01-19 14:10:17 +00:00
|
|
|
'tr': 'Türkçe (Turkish)',
|
|
|
|
'my': 'မြန်မာ (Burmese)',
|
2023-02-28 07:57:48 +00:00
|
|
|
'bg': 'Български (Bulgarian)',
|
2023-02-04 14:42:41 +00:00
|
|
|
'cs': 'čeština (Czech)',
|
2023-03-01 15:04:47 +00:00
|
|
|
'ur': 'اردو (Urdu)',
|
2023-05-19 14:33:16 +00:00
|
|
|
'id': 'Bahasa Indonesia (Indonesian)',
|
2023-05-25 17:30:21 +00:00
|
|
|
'yo': 'Yorùbá (Yoruba)',
|
2023-09-14 21:41:54 +00:00
|
|
|
'ha': 'Hausa Najeriya (Nigeria)',
|
|
|
|
'tl': 'Filipino (Tagalog)'
|
2020-09-28 15:47:43 +00:00
|
|
|
};
|
2022-06-29 12:38:44 +00:00
|
|
|
|
|
|
|
static const Map<String, String> localeCountryCode = {
|
|
|
|
'en': 'usa',
|
|
|
|
'de': 'deu',
|
|
|
|
'es': 'esp',
|
|
|
|
'fr': 'fra',
|
|
|
|
'hi': 'ind',
|
|
|
|
'ja': 'jpn',
|
|
|
|
'ko': 'kor',
|
|
|
|
'nl': 'nld',
|
|
|
|
'pl': 'pol',
|
|
|
|
'pt': 'prt',
|
|
|
|
'ru': 'rus',
|
|
|
|
'uk': 'ukr',
|
|
|
|
'zh': 'chn',
|
|
|
|
'hr': 'hrv',
|
2023-01-06 15:14:33 +00:00
|
|
|
'it': 'ita',
|
2023-01-06 15:27:18 +00:00
|
|
|
'th': 'tha',
|
2023-01-10 23:19:16 +00:00
|
|
|
'ar': 'sau',
|
2023-01-19 14:10:17 +00:00
|
|
|
'tr': 'tur',
|
|
|
|
'my': 'mmr',
|
2023-02-28 07:57:48 +00:00
|
|
|
'bg': 'bgr',
|
2023-02-04 14:42:41 +00:00
|
|
|
'cs': 'czk',
|
2023-03-01 15:04:47 +00:00
|
|
|
'ur': 'pak',
|
2023-05-19 14:33:16 +00:00
|
|
|
'id': 'idn',
|
2023-06-01 12:46:17 +00:00
|
|
|
'yo': 'nga',
|
2023-09-14 21:41:54 +00:00
|
|
|
'ha': 'hau',
|
|
|
|
'tl': 'phl'
|
2022-06-29 12:38:44 +00:00
|
|
|
};
|
|
|
|
|
2023-06-01 12:46:17 +00:00
|
|
|
static final list = <String, String>{};
|
2021-03-24 16:52:30 +00:00
|
|
|
|
2023-09-27 17:33:40 +00:00
|
|
|
static const defaultLocale = 'en';
|
|
|
|
|
2021-03-24 16:52:30 +00:00
|
|
|
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 {
|
2023-09-27 17:33:40 +00:00
|
|
|
try {
|
|
|
|
var locale = await Devicelocale.currentLocale ?? '';
|
|
|
|
locale = Intl.shortLocale(locale);
|
2020-09-28 15:47:43 +00:00
|
|
|
|
2023-09-27 17:33:40 +00:00
|
|
|
if (list.keys.contains(locale)) {
|
|
|
|
return locale;
|
|
|
|
}
|
|
|
|
return LanguageService.defaultLocale;
|
|
|
|
} catch(_) {
|
|
|
|
return LanguageService.defaultLocale;
|
|
|
|
}
|
2020-09-28 15:47:43 +00:00
|
|
|
}
|
|
|
|
}
|