mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix: fallback to supported locale if easy_localization doesn't support device locale
This commit is contained in:
parent
0d47397851
commit
e9ba1e1886
@ -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;
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user