2020-12-01 12:26:29 +00:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class Localization extends StatelessWidget {
|
|
|
|
const Localization({
|
2024-05-15 10:57:52 +00:00
|
|
|
required this.child,
|
2022-10-26 16:26:09 +00:00
|
|
|
super.key,
|
2022-06-05 19:36:32 +00:00
|
|
|
});
|
2020-12-01 12:26:29 +00:00
|
|
|
|
2024-06-16 00:12:59 +00:00
|
|
|
/// value for resetting locale in settings to system default
|
|
|
|
static const systemLocale = Locale('system');
|
|
|
|
|
2024-05-17 22:45:05 +00:00
|
|
|
// when adding new locale, add corresponding native language name to mapper
|
|
|
|
// below
|
|
|
|
static const supportedLocales = [
|
|
|
|
Locale('ar'),
|
|
|
|
Locale('az'),
|
|
|
|
Locale('be'),
|
|
|
|
Locale('cs'),
|
|
|
|
Locale('de'),
|
|
|
|
Locale('en'),
|
|
|
|
Locale('es'),
|
|
|
|
Locale('et'),
|
|
|
|
Locale('fr'),
|
|
|
|
Locale('he'),
|
2024-06-27 18:28:34 +00:00
|
|
|
Locale('ja'),
|
2024-08-30 10:24:29 +00:00
|
|
|
// Disabled due to poor translation quality
|
|
|
|
// Locale('kk'),
|
2024-05-17 22:45:05 +00:00
|
|
|
Locale('lv'),
|
|
|
|
Locale('mk'),
|
|
|
|
Locale('pl'),
|
|
|
|
Locale('ru'),
|
|
|
|
Locale('sk'),
|
|
|
|
Locale('sl'),
|
|
|
|
Locale('th'),
|
|
|
|
Locale('uk'),
|
|
|
|
Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'),
|
|
|
|
];
|
|
|
|
|
|
|
|
// https://en.wikipedia.org/wiki/IETF_language_tag#List_of_common_primary_language_subtags
|
|
|
|
static final _languageNames = {
|
2024-06-16 00:12:59 +00:00
|
|
|
systemLocale: 'System default',
|
2024-05-17 22:45:05 +00:00
|
|
|
const Locale('ar'): 'العربية',
|
|
|
|
const Locale('az'): 'Azərbaycan',
|
|
|
|
const Locale('be'): 'беларуская',
|
|
|
|
const Locale('cs'): 'čeština',
|
|
|
|
const Locale('de'): 'Deutsch',
|
|
|
|
const Locale('en'): 'English',
|
|
|
|
const Locale('es'): 'español',
|
|
|
|
const Locale('et'): 'eesti',
|
|
|
|
const Locale('fr'): 'français',
|
|
|
|
const Locale('he'): 'עברית',
|
2024-06-27 18:28:34 +00:00
|
|
|
const Locale('ja'): '日本語',
|
2024-05-17 22:45:05 +00:00
|
|
|
const Locale('kk'): 'Қазақша',
|
|
|
|
const Locale('lv'): 'latviešu',
|
|
|
|
const Locale('mk'): 'македонски јазик',
|
|
|
|
const Locale('pl'): 'polski',
|
|
|
|
const Locale('ru'): 'русский',
|
|
|
|
const Locale('sk'): 'slovenčina',
|
|
|
|
const Locale('sl'): 'slovenski',
|
|
|
|
const Locale('th'): 'ไทย',
|
|
|
|
const Locale('uk'): 'Українська',
|
|
|
|
const Locale.fromSubtags(languageCode: 'zh', scriptCode: 'Hans'): '中文',
|
|
|
|
};
|
|
|
|
|
|
|
|
static String getLanguageName(final Locale locale) =>
|
|
|
|
_languageNames[locale] ?? locale.languageCode;
|
|
|
|
|
2024-05-15 10:57:52 +00:00
|
|
|
final Widget child;
|
|
|
|
|
2020-12-01 12:26:29 +00:00
|
|
|
@override
|
2022-06-05 19:36:32 +00:00
|
|
|
Widget build(final BuildContext context) => EasyLocalization(
|
2024-05-17 22:45:05 +00:00
|
|
|
supportedLocales: supportedLocales,
|
2022-06-05 22:40:34 +00:00
|
|
|
path: 'assets/translations',
|
|
|
|
fallbackLocale: const Locale('en'),
|
2022-10-04 08:26:18 +00:00
|
|
|
useFallbackTranslations: true,
|
2022-06-05 22:40:34 +00:00
|
|
|
saveLocale: false,
|
2024-03-14 17:22:03 +00:00
|
|
|
useOnlyLangCode: false,
|
2024-05-15 10:57:52 +00:00
|
|
|
child: child,
|
2022-06-05 22:40:34 +00:00
|
|
|
);
|
2020-12-01 12:26:29 +00:00
|
|
|
}
|