mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
read device locale as default locale setting
This commit is contained in:
parent
8127e47cea
commit
be806e301c
@ -59,6 +59,7 @@ class ApplicationWidget extends StatelessWidget {
|
||||
const ratio = 1.73;
|
||||
const minWidth = 600.0;
|
||||
setWindowMinSize(const Size(minWidth, minWidth / ratio));
|
||||
settingModel.updateWithBuildContext(context);
|
||||
AppTheme theme = context.select<AppearanceSettingModel, AppTheme>(
|
||||
(value) => value.theme,
|
||||
);
|
||||
|
@ -39,7 +39,7 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
|
||||
}
|
||||
|
||||
void setLanguage(BuildContext context, AppLanguage language) {
|
||||
String languageString = stringFromLanguageName(language);
|
||||
String languageString = stringFromLanguage(language);
|
||||
|
||||
if (setting.language != languageString) {
|
||||
context.setLocale(localeFromLanguageName(language));
|
||||
@ -49,4 +49,9 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
void updateWithBuildContext(BuildContext context) {
|
||||
final language = languageFromLocale(context.deviceLocale);
|
||||
setLanguage(context, language);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ enum AppLanguage {
|
||||
french,
|
||||
}
|
||||
|
||||
String stringFromLanguageName(AppLanguage language) {
|
||||
String stringFromLanguage(AppLanguage language) {
|
||||
switch (language) {
|
||||
case AppLanguage.english:
|
||||
return "en";
|
||||
@ -45,3 +45,16 @@ Locale localeFromLanguageName(AppLanguage language) {
|
||||
return const Locale('fr', 'CA');
|
||||
}
|
||||
}
|
||||
|
||||
AppLanguage languageFromLocale(Locale locale) {
|
||||
switch (locale.languageCode) {
|
||||
case "zh":
|
||||
return AppLanguage.chinese;
|
||||
case "it":
|
||||
return AppLanguage.italian;
|
||||
case "fr":
|
||||
return AppLanguage.french;
|
||||
default:
|
||||
return AppLanguage.english;
|
||||
}
|
||||
}
|
||||
|
@ -694,7 +694,7 @@ packages:
|
||||
name: material_color_utilities
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.1.2"
|
||||
version: "0.1.3"
|
||||
meta:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
Loading…
Reference in New Issue
Block a user