Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

read device locale as default locale setting

appflowybe806e301c57
diff --git a/frontend/app_flowy/lib/startup/tasks/application_widget.dart b/frontend/app_flowy/lib/startup/tasks/application_widget.dart
index 375d4a299a..41c2b1397e 100644
--- a/frontend/app_flowy/lib/startup/tasks/application_widget.dart
+++ b/frontend/app_flowy/lib/startup/tasks/application_widget.dart
@@ -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,
);
diff --git a/frontend/app_flowy/lib/workspace/application/appearance.dart b/frontend/app_flowy/lib/workspace/application/appearance.dart
index 187491cf3f..1e5682f9ec 100644
--- a/frontend/app_flowy/lib/workspace/application/appearance.dart
+++ b/frontend/app_flowy/lib/workspace/application/appearance.dart
@@ -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);
+ }
}
diff --git a/frontend/app_flowy/packages/flowy_infra/lib/language.dart b/frontend/app_flowy/packages/flowy_infra/lib/language.dart
index 13ee652501..0109bf6e9a 100644
--- a/frontend/app_flowy/packages/flowy_infra/lib/language.dart
+++ b/frontend/app_flowy/packages/flowy_infra/lib/language.dart
@@ -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;
+ }
+}
diff --git a/frontend/app_flowy/pubspec.lock b/frontend/app_flowy/pubspec.lock
index e00e5ccb9f..efa82e7604 100644
--- a/frontend/app_flowy/pubspec.lock
+++ b/frontend/app_flowy/pubspec.lock
@@ -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: