Default to en as fallBack and hardcode supported locales

This commit is contained in:
Neeraj Gupta 2023-04-04 19:38:10 +05:30
parent 2ada82f8e0
commit 32edfa2a06
No known key found for this signature in database
GPG key ID: 3C5A1684DC1729E1
3 changed files with 25 additions and 3 deletions

View file

@ -10,6 +10,7 @@ import 'package:logging/logging.dart';
import 'package:media_extension/media_extension_action_types.dart';
import 'package:photos/ente_theme_data.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
import 'package:photos/services/app_lifecycle_service.dart';
import 'package:photos/services/sync_service.dart';
import 'package:photos/ui/home_widget.dart';
@ -71,7 +72,8 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
: const HomeWidget(),
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
S.delegate
@ -87,7 +89,8 @@ class _EnteAppState extends State<EnteApp> with WidgetsBindingObserver {
home: const HomeWidget(),
debugShowCheckedModeBanner: false,
builder: EasyLoading.init(),
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
S.delegate

View file

@ -4,3 +4,20 @@ import "package:photos/generated/l10n.dart";
extension AppLocalizationsX on BuildContext {
S get l10n => S.of(this);
}
// list of locales which are enabled for auth app.
// Add more language to the list only when at least 90% of the strings are
// translated in the corresponding language.
const List<Locale> appSupportedLocales = <Locale>[
Locale('en'),
];
Locale localResolutionCallBack(locales, supportedLocales) {
for (Locale locale in locales) {
if (appSupportedLocales.contains(locale)) {
return locale;
}
}
// if device language is not supported by the app, use en as default
return const Locale('en');
}

View file

@ -3,6 +3,7 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import "package:photos/generated/l10n.dart";
import "package:photos/l10n/l10n.dart";
/// A widget which handles app lifecycle events for showing and hiding a lock screen.
/// This should wrap around a `MyApp` widget (or equivalent).
@ -109,7 +110,8 @@ class _AppLockState extends State<AppLock> with WidgetsBindingObserver {
themeMode: widget.savedThemeMode,
theme: widget.lightTheme,
darkTheme: widget.darkTheme,
supportedLocales: AppLocalizations.supportedLocales,
supportedLocales: appSupportedLocales,
localeResolutionCallback: localResolutionCallBack,
localizationsDelegates: const [
...AppLocalizations.localizationsDelegates,
S.delegate