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';
|
2021-08-29 13:51:43 +02:00
|
|
|
import 'package:nc_photos/widget/my_app.dart';
|
2022-12-16 16:01:04 +01:00
|
|
|
import 'package:np_codegen/np_codegen.dart';
|
|
|
|
|
|
|
|
part 'app_localizations.g.dart';
|
2021-07-25 07:00:38 +02:00
|
|
|
|
|
|
|
/// Simplify localized string access
|
2022-12-16 16:01:04 +01:00
|
|
|
@npLog
|
2021-07-25 07:00:38 +02:00
|
|
|
class L10n {
|
2021-08-29 13:51:43 +02:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-20 17:49:14 +01:00
|
|
|
static final _log = _$L10nNpLog.log;
|
2021-07-25 07:00:38 +02:00
|
|
|
}
|