refactor: Use non nullable localizations builder and lazy load on web
This commit is contained in:
parent
8cedd2a45a
commit
0d4b7d67cc
111 changed files with 879 additions and 883 deletions
|
|
@ -48,8 +48,8 @@ abstract class ClientManager {
|
|||
await Future.wait(
|
||||
clients.map(
|
||||
(client) => client.initWithRestore(
|
||||
onMigration: () {
|
||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||
onMigration: () async {
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
sendInitNotification(
|
||||
l10n.databaseMigrationTitle,
|
||||
l10n.databaseMigrationBody,
|
||||
|
|
|
|||
|
|
@ -35,9 +35,9 @@ extension DateTimeExtension on DateTime {
|
|||
|
||||
/// Returns a simple time String.
|
||||
String localizedTimeOfDay(BuildContext context) =>
|
||||
L10n.of(context)!.alwaysUse24HourFormat == 'true'
|
||||
? DateFormat('HH:mm', L10n.of(context)!.localeName).format(this)
|
||||
: DateFormat('h:mm a', L10n.of(context)!.localeName).format(this);
|
||||
L10n.of(context).alwaysUse24HourFormat == 'true'
|
||||
? DateFormat('HH:mm', L10n.of(context).localeName).format(this)
|
||||
: DateFormat('h:mm a', L10n.of(context).localeName).format(this);
|
||||
|
||||
/// Returns [localizedTimeOfDay()] if the ChatTime is today, the name of the week
|
||||
/// day if the ChatTime is this week and a date string else.
|
||||
|
|
@ -77,7 +77,7 @@ extension DateTimeExtension on DateTime {
|
|||
final sameDay = sameYear && now.month == month && now.day == day;
|
||||
|
||||
if (sameDay) return localizedTimeOfDay(context);
|
||||
return L10n.of(context)!.dateAndTimeOfDay(
|
||||
return L10n.of(context).dateAndTimeOfDay(
|
||||
localizedTimeShort(context),
|
||||
localizedTimeOfDay(context),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ class ErrorReporter {
|
|||
await showAdaptiveDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog.adaptive(
|
||||
title: Text(L10n.of(context)!.reportErrorDescription),
|
||||
title: Text(L10n.of(context).reportErrorDescription),
|
||||
content: SizedBox(
|
||||
height: 256,
|
||||
width: 256,
|
||||
|
|
@ -36,13 +36,13 @@ class ErrorReporter {
|
|||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: Text(L10n.of(context)!.close),
|
||||
child: Text(L10n.of(context).close),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Clipboard.setData(
|
||||
ClipboardData(text: text),
|
||||
),
|
||||
child: Text(L10n.of(context)!.copy),
|
||||
child: Text(L10n.of(context).copy),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => launchUrl(
|
||||
|
|
@ -56,7 +56,7 @@ class ErrorReporter {
|
|||
),
|
||||
mode: LaunchMode.externalApplication,
|
||||
),
|
||||
child: Text(L10n.of(context)!.report),
|
||||
child: Text(L10n.of(context).report),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ abstract class FluffyShare {
|
|||
ClipboardData(text: text),
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.copiedToClipboard)),
|
||||
SnackBar(content: Text(L10n.of(context).copiedToClipboard)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
@ -34,7 +34,7 @@ abstract class FluffyShare {
|
|||
final client = Matrix.of(context).client;
|
||||
final ownProfile = await client.fetchOwnProfile();
|
||||
await FluffyShare.share(
|
||||
L10n.of(context)!.inviteText(
|
||||
L10n.of(context).inviteText(
|
||||
ownProfile.displayName ?? client.userID!,
|
||||
'https://matrix.to/#/${client.userID}?client=im.fluffychat',
|
||||
),
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ extension InitWithRestoreExtension on Client {
|
|||
}
|
||||
} catch (e, s) {
|
||||
Logs().wtf('Client init failed!', e, s);
|
||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
final sessionBackupString = await storage?.read(key: storageKey);
|
||||
if (sessionBackupString == null) {
|
||||
ClientManager.sendInitNotification(
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ extension LocalizedExceptionExtension on Object {
|
|||
]) {
|
||||
if (this is FileTooBigMatrixException) {
|
||||
final exception = this as FileTooBigMatrixException;
|
||||
return L10n.of(context)!.fileIsTooBigForServer(
|
||||
return L10n.of(context).fileIsTooBigForServer(
|
||||
_formatFileSize(exception.maxFileSize),
|
||||
);
|
||||
}
|
||||
|
|
@ -38,17 +38,17 @@ extension LocalizedExceptionExtension on Object {
|
|||
switch ((this as MatrixException).error) {
|
||||
case MatrixError.M_FORBIDDEN:
|
||||
if (exceptionContext == ExceptionContext.changePassword) {
|
||||
return L10n.of(context)!.passwordIsWrong;
|
||||
return L10n.of(context).passwordIsWrong;
|
||||
}
|
||||
return L10n.of(context)!.noPermission;
|
||||
return L10n.of(context).noPermission;
|
||||
case MatrixError.M_LIMIT_EXCEEDED:
|
||||
return L10n.of(context)!.tooManyRequestsWarning;
|
||||
return L10n.of(context).tooManyRequestsWarning;
|
||||
default:
|
||||
return (this as MatrixException).errorMessage;
|
||||
}
|
||||
}
|
||||
if (this is InvalidPassphraseException) {
|
||||
return L10n.of(context)!.wrongRecoveryKey;
|
||||
return L10n.of(context).wrongRecoveryKey;
|
||||
}
|
||||
if (this is BadServerVersionsException) {
|
||||
final serverVersions = (this as BadServerVersionsException)
|
||||
|
|
@ -61,7 +61,7 @@ extension LocalizedExceptionExtension on Object {
|
|||
.toString()
|
||||
.replaceAll('{', '"')
|
||||
.replaceAll('}', '"');
|
||||
return L10n.of(context)!.badServerVersionsException(
|
||||
return L10n.of(context).badServerVersionsException(
|
||||
serverVersions,
|
||||
supportedVersions,
|
||||
serverVersions,
|
||||
|
|
@ -79,7 +79,7 @@ extension LocalizedExceptionExtension on Object {
|
|||
.toString()
|
||||
.replaceAll('{', '"')
|
||||
.replaceAll('}', '"');
|
||||
return L10n.of(context)!.badServerLoginTypesException(
|
||||
return L10n.of(context).badServerLoginTypesException(
|
||||
serverVersions,
|
||||
supportedVersions,
|
||||
supportedVersions,
|
||||
|
|
@ -89,16 +89,16 @@ extension LocalizedExceptionExtension on Object {
|
|||
this is SocketException ||
|
||||
this is SyncConnectionException ||
|
||||
this is ClientException) {
|
||||
return L10n.of(context)!.noConnectionToTheServer;
|
||||
return L10n.of(context).noConnectionToTheServer;
|
||||
}
|
||||
if (this is FormatException &&
|
||||
exceptionContext == ExceptionContext.checkHomeserver) {
|
||||
return L10n.of(context)!.doesNotSeemToBeAValidHomeserver;
|
||||
return L10n.of(context).doesNotSeemToBeAValidHomeserver;
|
||||
}
|
||||
if (this is String) return toString();
|
||||
if (this is UiaException) return toString();
|
||||
Logs().w('Something went wrong: ', this);
|
||||
return L10n.of(context)!.oopsSomethingWentWrong;
|
||||
return L10n.of(context).oopsSomethingWentWrong;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ Future<DatabaseApi> flutterMatrixSdkDatabaseBuilder(Client client) async {
|
|||
|
||||
try {
|
||||
// Send error notification:
|
||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
ClientManager.sendInitNotification(
|
||||
l10n.initAppError,
|
||||
l10n.databaseBuildErrorBody(
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ void _sendNoEncryptionWarning(Object exception) async {
|
|||
|
||||
if (isStored == true) return;
|
||||
|
||||
final l10n = lookupL10n(PlatformDispatcher.instance.locale);
|
||||
final l10n = await lookupL10n(PlatformDispatcher.instance.locale);
|
||||
ClientManager.sendInitNotification(
|
||||
l10n.noDatabaseEncryption,
|
||||
exception.toString(),
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ extension MatrixFileExtension on MatrixFile {
|
|||
}
|
||||
|
||||
final downloadPath = await FilePicker.platform.saveFile(
|
||||
dialogTitle: L10n.of(context)!.saveFile,
|
||||
dialogTitle: L10n.of(context).saveFile,
|
||||
fileName: name,
|
||||
type: filePickerFileType,
|
||||
bytes: bytes,
|
||||
|
|
@ -38,7 +38,7 @@ extension MatrixFileExtension on MatrixFile {
|
|||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
L10n.of(context)!.fileHasBeenSavedAt(downloadPath),
|
||||
L10n.of(context).fileHasBeenSavedAt(downloadPath),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ abstract class PlatformInfos {
|
|||
TextButton.icon(
|
||||
onPressed: () => launchUrlString(AppConfig.sourceCodeUrl),
|
||||
icon: const Icon(Icons.source_outlined),
|
||||
label: Text(L10n.of(context)!.sourceCode),
|
||||
label: Text(L10n.of(context).sourceCode),
|
||||
),
|
||||
TextButton.icon(
|
||||
onPressed: () => launchUrlString(AppConfig.emojiFontUrl),
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ Future<void> pushHelper(
|
|||
} catch (e, s) {
|
||||
Logs().v('Push Helper has crashed!', e, s);
|
||||
|
||||
l10n ??= lookupL10n(const Locale('en'));
|
||||
l10n ??= await lookupL10n(const Locale('en'));
|
||||
flutterLocalNotificationsPlugin.show(
|
||||
notification.roomId?.hashCode ?? 0,
|
||||
l10n.newMessageInFluffyChat,
|
||||
|
|
|
|||
|
|
@ -12,24 +12,24 @@ extension RoomStatusExtension on Room {
|
|||
typingUsers.removeWhere((User u) => u.id == client.userID);
|
||||
|
||||
if (AppConfig.hideTypingUsernames) {
|
||||
typingText = L10n.of(context)!.isTyping;
|
||||
typingText = L10n.of(context).isTyping;
|
||||
if (typingUsers.first.id != directChatMatrixID) {
|
||||
typingText =
|
||||
L10n.of(context)!.numUsersTyping(typingUsers.length.toString());
|
||||
L10n.of(context).numUsersTyping(typingUsers.length.toString());
|
||||
}
|
||||
} else if (typingUsers.length == 1) {
|
||||
typingText = L10n.of(context)!.isTyping;
|
||||
typingText = L10n.of(context).isTyping;
|
||||
if (typingUsers.first.id != directChatMatrixID) {
|
||||
typingText =
|
||||
L10n.of(context)!.userIsTyping(typingUsers.first.calcDisplayname());
|
||||
L10n.of(context).userIsTyping(typingUsers.first.calcDisplayname());
|
||||
}
|
||||
} else if (typingUsers.length == 2) {
|
||||
typingText = L10n.of(context)!.userAndUserAreTyping(
|
||||
typingText = L10n.of(context).userAndUserAreTyping(
|
||||
typingUsers.first.calcDisplayname(),
|
||||
typingUsers[1].calcDisplayname(),
|
||||
);
|
||||
} else if (typingUsers.length > 2) {
|
||||
typingText = L10n.of(context)!.userAndOthersAreTyping(
|
||||
typingText = L10n.of(context).userAndOthersAreTyping(
|
||||
typingUsers.first.calcDisplayname(),
|
||||
(typingUsers.length - 1).toString(),
|
||||
);
|
||||
|
|
|
|||
|
|
@ -35,13 +35,13 @@ abstract class UpdateNotifier {
|
|||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
L10n.of(context)!.updateInstalled(currentVersion),
|
||||
L10n.of(context).updateInstalled(currentVersion),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
action: SnackBarAction(
|
||||
label: L10n.of(context)!.changelog,
|
||||
label: L10n.of(context).changelog,
|
||||
onPressed: () => launchUrlString(AppConfig.changelogUrl),
|
||||
),
|
||||
),
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import 'package:fluffychat/widgets/matrix.dart';
|
|||
|
||||
extension UiaRequestManager on MatrixState {
|
||||
Future uiaRequestHandler(UiaRequest uiaRequest) async {
|
||||
final l10n = L10n.of(context)!;
|
||||
final l10n = L10n.of(context);
|
||||
try {
|
||||
if (uiaRequest.state != UiaRequestState.waitForUser ||
|
||||
uiaRequest.nextStages.isEmpty) {
|
||||
|
|
@ -49,7 +49,7 @@ extension UiaRequestManager on MatrixState {
|
|||
case AuthenticationTypes.emailIdentity:
|
||||
if (currentThreepidCreds == null) {
|
||||
return uiaRequest.cancel(
|
||||
UiaException(L10n.of(context)!.serverRequiresEmail),
|
||||
UiaException(L10n.of(context).serverRequiresEmail),
|
||||
);
|
||||
}
|
||||
final auth = AuthenticationThreePidCreds(
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ class UrlLauncher {
|
|||
if (uri == null) {
|
||||
// we can't open this thing
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.cantOpenUri(url!))),
|
||||
SnackBar(content: Text(L10n.of(context).cantOpenUri(url!))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
@ -49,10 +49,10 @@ class UrlLauncher {
|
|||
// that the user can see the actual url before opening the browser.
|
||||
final consent = await showOkCancelAlertDialog(
|
||||
context: context,
|
||||
title: L10n.of(context)!.openLinkInBrowser,
|
||||
title: L10n.of(context).openLinkInBrowser,
|
||||
message: url,
|
||||
okLabel: L10n.of(context)!.yes,
|
||||
cancelLabel: L10n.of(context)!.cancel,
|
||||
okLabel: L10n.of(context).yes,
|
||||
cancelLabel: L10n.of(context).cancel,
|
||||
);
|
||||
if (consent != OkCancelResult.ok) return;
|
||||
}
|
||||
|
|
@ -93,7 +93,7 @@ class UrlLauncher {
|
|||
}
|
||||
if (uri.host.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text(L10n.of(context)!.cantOpenUri(url!))),
|
||||
SnackBar(content: Text(L10n.of(context).cantOpenUri(url!))),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,14 +226,14 @@ class CallKeepManager {
|
|||
barrierDismissible: true,
|
||||
useRootNavigator: false,
|
||||
builder: (_) => AlertDialog(
|
||||
title: Text(L10n.of(context)!.callingPermissions),
|
||||
title: Text(L10n.of(context).callingPermissions),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
onTap: () => openCallingAccountsPage(context),
|
||||
title: Text(L10n.of(context)!.callingAccount),
|
||||
subtitle: Text(L10n.of(context)!.callingAccountDetails),
|
||||
title: Text(L10n.of(context).callingAccount),
|
||||
subtitle: Text(L10n.of(context).callingAccountDetails),
|
||||
trailing: const Icon(Icons.phone),
|
||||
),
|
||||
const Divider(),
|
||||
|
|
@ -241,14 +241,14 @@ class CallKeepManager {
|
|||
onTap: () => FlutterForegroundTask.openSystemAlertWindowSettings(
|
||||
forceOpen: true,
|
||||
),
|
||||
title: Text(L10n.of(context)!.appearOnTop),
|
||||
subtitle: Text(L10n.of(context)!.appearOnTopDetails),
|
||||
title: Text(L10n.of(context).appearOnTop),
|
||||
subtitle: Text(L10n.of(context).appearOnTopDetails),
|
||||
trailing: const Icon(Icons.file_upload_rounded),
|
||||
),
|
||||
const Divider(),
|
||||
ListTile(
|
||||
onTap: () => openAppSettings(),
|
||||
title: Text(L10n.of(context)!.otherCallingPermissions),
|
||||
title: Text(L10n.of(context).otherCallingPermissions),
|
||||
trailing: const Icon(Icons.mic),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue