2021-06-23 10:15:25 +02:00
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'package:nc_photos/pref.dart';
|
|
|
|
|
|
|
|
class AppLanguage {
|
2021-08-28 22:58:10 +02:00
|
|
|
const AppLanguage(this.langId, this.nativeName, this.isoName, this.locale);
|
2021-06-23 10:15:25 +02:00
|
|
|
|
|
|
|
final int langId;
|
|
|
|
final String nativeName;
|
2021-08-28 22:58:10 +02:00
|
|
|
final String? isoName;
|
2021-07-23 22:05:57 +02:00
|
|
|
final Locale? locale;
|
2021-06-23 10:15:25 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 10:30:37 +02:00
|
|
|
String getSelectedLanguageName() => _getSelectedLanguage().nativeName;
|
|
|
|
Locale? getSelectedLocale() => _getSelectedLanguage().locale;
|
2021-06-23 10:15:25 +02:00
|
|
|
|
|
|
|
final supportedLanguages = {
|
2021-08-28 22:58:10 +02:00
|
|
|
_AppLanguageEnum.systemDefault.index: AppLanguage(
|
|
|
|
_AppLanguageEnum.systemDefault.index, "System default", null, null),
|
2021-08-02 07:53:13 +02:00
|
|
|
// sorted by alphabetic order of their ISO language names
|
2021-06-23 10:15:25 +02:00
|
|
|
_AppLanguageEnum.english.index: AppLanguage(
|
2021-08-28 22:58:10 +02:00
|
|
|
_AppLanguageEnum.english.index, "English", "English", const Locale("en")),
|
2021-08-05 08:59:04 +02:00
|
|
|
_AppLanguageEnum.french.index: AppLanguage(
|
2021-08-28 22:58:10 +02:00
|
|
|
_AppLanguageEnum.french.index, "français", "French", const Locale("fr")),
|
|
|
|
_AppLanguageEnum.greek.index: AppLanguage(
|
|
|
|
_AppLanguageEnum.greek.index, "ελληνικά", "Greek", const Locale("el")),
|
2021-08-22 23:02:58 +02:00
|
|
|
_AppLanguageEnum.russian.index: AppLanguage(
|
2021-08-28 22:58:10 +02:00
|
|
|
_AppLanguageEnum.russian.index, "русский", "Russian", const Locale("ru")),
|
2021-06-23 10:15:25 +02:00
|
|
|
_AppLanguageEnum.spanish.index: AppLanguage(
|
2021-08-28 22:58:10 +02:00
|
|
|
_AppLanguageEnum.spanish.index, "Español", "Spanish", const Locale("es")),
|
2021-06-23 10:15:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
enum _AppLanguageEnum {
|
|
|
|
// the order must not be changed
|
|
|
|
systemDefault,
|
|
|
|
english,
|
|
|
|
spanish,
|
2021-08-02 07:53:13 +02:00
|
|
|
greek,
|
2021-08-05 08:59:04 +02:00
|
|
|
french,
|
2021-08-22 23:02:58 +02:00
|
|
|
russian,
|
2021-06-23 10:15:25 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 10:30:37 +02:00
|
|
|
AppLanguage _getSelectedLanguage() {
|
2021-06-23 10:15:25 +02:00
|
|
|
try {
|
2021-07-23 22:05:57 +02:00
|
|
|
final lang = Pref.inst().getLanguageOr(0);
|
|
|
|
return supportedLanguages[lang]!;
|
2021-06-23 10:15:25 +02:00
|
|
|
} catch (_) {
|
2021-07-23 22:05:57 +02:00
|
|
|
return supportedLanguages[_AppLanguageEnum.systemDefault.index]!;
|
2021-06-23 10:15:25 +02:00
|
|
|
}
|
|
|
|
}
|