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.

fix: fallback to supported locale if easy_localization doesn't support device locale

appflowye9ba1e18860d
diff --git a/frontend/app_flowy/lib/workspace/application/appearance.dart b/frontend/app_flowy/lib/workspace/application/appearance.dart
index 8303912fc0..77f3ec567a 100644
--- a/frontend/app_flowy/lib/workspace/application/appearance.dart
+++ b/frontend/app_flowy/lib/workspace/application/appearance.dart
@@ -1,6 +1,7 @@
import 'package:app_flowy/user/infrastructure/repos/user_setting_repo.dart';
import 'package:equatable/equatable.dart';
import 'package:flowy_infra/theme.dart';
+import 'package:flowy_log/flowy_log.dart';
import 'package:flowy_sdk/protobuf/flowy-user-data-model/user_setting.pb.dart';
import 'package:flutter/material.dart';
import 'package:easy_localization/easy_localization.dart';
@@ -46,6 +47,12 @@ class AppearanceSettingModel extends ChangeNotifier with EquatableMixin {
void setLocale(BuildContext context, Locale newLocale) {
if (_locale != newLocale) {
+ if (context.supportedLocales.contains(newLocale)) {
+ Log.error("Unsupported locale: $newLocale");
+ newLocale = const Locale('en');
+ Log.debug("Fall back to locale: $newLocale");
+ }
+
context.setLocale(newLocale);
_locale = newLocale;
setting.locale.languageCode = _locale.languageCode;
diff --git a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
index 1af32ab72a..ae6794542c 100644
--- a/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
+++ b/frontend/rust-lib/flowy-user/src/handlers/user_handler.rs
@@ -59,7 +59,13 @@ pub async fn get_appearance_setting() -> DataResult<AppearanceSettings, FlowyErr
match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) {
None => data_result(AppearanceSettings::default()),
Some(s) => {
- let setting: AppearanceSettings = serde_json::from_str(&s)?;
+ let setting = match serde_json::from_str(&s) {
+ Ok(setting) => setting,
+ Err(e) => {
+ tracing::error!("Deserialize AppearanceSettings failed: {:?}, fallback to default", e);
+ AppearanceSettings::default()
+ }
+ };
data_result(setting)
}
}