nc-photos/app/lib/app_localizations.dart

25 lines
812 B
Dart
Raw Normal View History

2022-06-06 19:37:46 +02:00
import 'package:flutter/widgets.dart';
2021-07-25 07:00:38 +02:00
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
2022-06-06 19:37:46 +02:00
import 'package:flutter_gen/gen_l10n/app_localizations_en.dart';
import 'package:logging/logging.dart';
import 'package:nc_photos/widget/my_app.dart';
2021-07-25 07:00:38 +02:00
/// Simplify localized string access
class L10n {
static AppLocalizations global() => AppLocalizations.of(MyApp.globalContext)!;
2022-06-06 19:37:46 +02:00
static AppLocalizations of(Locale locale) {
try {
return lookupAppLocalizations(locale);
} on FlutterError catch (_) {
// unsupported locale, use default (en)
return AppLocalizationsEn();
} catch (e, stackTrace) {
_log.shout("[of] Failed while lookupAppLocalizations", e, stackTrace);
return AppLocalizationsEn();
}
}
static final _log = Logger("app_localizations.L10n");
2021-07-25 07:00:38 +02:00
}