cake_wallet/lib/entities/language_service.dart

81 lines
2 KiB
Dart
Raw Permalink Normal View History

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 {
static const Map<String, String> supportedLocales = {
2020-09-28 15:47:43 +00:00
'en': 'English',
'de': 'Deutsch (German)',
'es': 'Español (Spanish)',
'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)',
'zh': '中文 (Chinese)',
'hr': 'Hrvatski (Croatian)',
2023-01-06 15:14:33 +00:00
'it': 'Italiano (Italian)',
'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)',
'bg': 'Български (Bulgarian)',
2023-02-04 14:42:41 +00:00
'cs': 'čeština (Czech)',
'ur': 'اردو (Urdu)',
'id': 'Bahasa Indonesia (Indonesian)',
'yo': 'Yorùbá (Yoruba)',
'ha': 'Hausa Najeriya (Nigeria)',
'tl': 'Filipino (Tagalog)'
2020-09-28 15:47:43 +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',
'th': 'tha',
2023-01-10 23:19:16 +00:00
'ar': 'sau',
2023-01-19 14:10:17 +00:00
'tr': 'tur',
'my': 'mmr',
'bg': 'bgr',
2023-02-04 14:42:41 +00:00
'cs': 'czk',
'ur': 'pak',
'id': 'idn',
2023-06-01 12:46:17 +00:00
'yo': 'nga',
'ha': 'hau',
'tl': 'phl'
};
2023-06-01 12:46:17 +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 {
2022-10-12 17:09:57 +00:00
var locale = await Devicelocale.currentLocale ?? '';
2020-09-28 15:47:43 +00:00
locale = Intl.shortLocale(locale);
return list.keys.contains(locale) ? locale : 'en';
}
}