Skip to content

Commit

Permalink
Merge pull request #1573 from atsign-foundation/npt_desktop-onboarding
Browse files Browse the repository at this point in the history
fix: added missing translations
  • Loading branch information
CurtlyCritchlow authored Nov 26, 2024
2 parents 13b4f53 + 48b90cf commit fc6a9c9
Show file tree
Hide file tree
Showing 17 changed files with 793 additions and 614 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/features/logging/logging.dart';
import 'package:npt_flutter/styles/sizes.dart';

Expand All @@ -11,7 +12,7 @@ class DebugDumpLogsButton extends StatelessWidget {
Widget build(BuildContext context) {
if (!kDebugMode) return gap0;
return ElevatedButton(
child: const Text("Dev: Dump Logs to terminal"),
child: Text(AppLocalizations.of(context)!.debugDumpLogTitle),
onPressed: () {
var list = context.read<LogsCubit>().logs;
for (final line in list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import 'dart:convert';

import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/features/onboarding/util/activate_util.dart';
import 'package:npt_flutter/widgets/spinner.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
Expand Down Expand Up @@ -46,15 +48,16 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
_getPinCode();
}

final strings = AppLocalizations.of(App.navState.currentContext!)!;

@override
Widget build(BuildContext context) {
return AlertDialog(
title: Center(
child: switch (status) {
// TODO localize
ActivationStatus.preparing => const Text("Preparing for activation"),
ActivationStatus.otpWait => const Text("Please enter the OTP from your email"),
ActivationStatus.activating => const Text("Activating"),
ActivationStatus.preparing => Text(strings.activationStatusPreparing),
ActivationStatus.otpWait => Text(strings.activationStatusOtpWait),
ActivationStatus.activating => Text(strings.activationStatusActivating),
},
),
content: SizedBox(
Expand All @@ -66,7 +69,6 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
height: 80,
child: Column(
children: [
// TODO localize
PinCodeTextField(
focusNode: pinFocusNode,
appContext: context,
Expand Down Expand Up @@ -128,11 +130,10 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
} else {
if (!mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
SnackBar(
backgroundColor: Colors.red,
// TODO localize
content: Text(
"Failed to request an OTP, try resending, or contact support if the issue persists",
strings.errorOtpRequestFailed,
),
),
);
Expand All @@ -144,8 +145,7 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {

Widget get cancelButton => TextButton(
key: const Key("NoPortsActivateCancelButton"),
// TODO localize
child: const Text("Cancel"),
child: Text(strings.cancel),
onPressed: () {
Navigator.of(context).pop(AtOnboardingResult.cancelled());
},
Expand All @@ -154,8 +154,7 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
Widget get resendPinButton => TextButton(
key: const Key("NoPortsActivateResendButton"),
onPressed: _getPinCode,
// TODO localize
child: const Text("Resend Pin"),
child: Text(strings.resendPin),
);

Widget get confirmPinButton => TextButton(
Expand All @@ -174,11 +173,10 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {

if (cramkey == null) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(
SnackBar(
backgroundColor: Colors.red,
content: Text(
// TODO localize
"Failed to verify the OTP with the activation server, please try again. Contact support if the issue persists",
strings.errorOtpVerificationFailed,
),
),
);
Expand All @@ -198,7 +196,6 @@ class _ActivateAtsignDialogState extends State<ActivateAtsignDialog> {
if (!mounted) return;
Navigator.of(context).pop(result);
},
// TODO localize
child: const Text("Confirm"),
child: Text(strings.confirm),
);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
import 'dart:developer';
import 'dart:io';

import 'package:at_contacts_flutter/at_contacts_flutter.dart';
import 'package:at_onboarding_flutter/at_onboarding_flutter.dart';
import 'package:at_onboarding_flutter/at_onboarding_screens.dart';
import 'package:at_onboarding_flutter/at_onboarding_services.dart';
// ignore: implementation_imports
import 'package:at_onboarding_flutter/src/utils/at_onboarding_app_constants.dart';
import 'package:at_server_status/at_server_status.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/app.dart';
import 'package:npt_flutter/constants.dart';
import 'package:npt_flutter/features/onboarding/onboarding.dart';
import 'package:npt_flutter/features/onboarding/util/atsign_manager.dart';
import 'package:npt_flutter/features/onboarding/util/onboarding_util.dart';
import 'package:npt_flutter/features/onboarding/widgets/activate_atsign_dialog.dart';
import 'package:npt_flutter/features/onboarding/widgets/onboarding_dialog.dart';
import 'package:npt_flutter/routes.dart';

import 'package:npt_flutter/util/language.dart';
import 'package:path_provider/path_provider.dart';
import 'package:phosphor_flutter/phosphor_flutter.dart';

final strings = AppLocalizations.of(App.navState.currentContext!)!;
Future<AtClientPreference> loadAtClientPreference(String rootDomain) async {
var dir = await getApplicationSupportDirectory();

Expand Down Expand Up @@ -71,10 +73,8 @@ class _OnboardingButtonState extends State<OnboardingButton> {
),
iconAlignment: IconAlignment.end,
),
// TODO: localize
_OnboardingButtonStatus.picking => const Text("Waiting for file to be picked"),
// TODO: localize
_OnboardingButtonStatus.processingFile => const Text("Processing file"),
_OnboardingButtonStatus.picking => Text(strings.onboardingButtonStatusPicking),
_OnboardingButtonStatus.processingFile => Text(strings.onboardingButtonStatusProcessingFile),
};
}

Expand Down Expand Up @@ -167,12 +167,12 @@ class _OnboardingButtonState extends State<OnboardingButton> {

Future<AtOnboardingResult?> handleAtsignByStatus(String atsign, NoPortsOnboardingUtil util) async {
AtStatus status;

try {
status = await util.atServerStatus(atsign);
} catch (_) {
return AtOnboardingResult.error(
// TODO localize
message: "Failed to retrieve the atserver status, make sure you have a stable internet connection",
message: strings.errorAtServerUnavailable,
);
}
AtOnboardingResult? result;
Expand All @@ -185,15 +185,14 @@ class _OnboardingButtonState extends State<OnboardingButton> {

if (apiKey == null) {
result = AtOnboardingResult.error(
// TODO localize
message: "The atSign you have requested, doesn't exist in this root domain",
message: strings.errorAtSignNotExist,
);
break;
}
AtOnboardingConstants.setApiKey(apiKey);
AtOnboardingConstants.rootDomain = util.config.atClientPreference.rootDomain;
// TODO: localize locale - right now hardcoded to english
await AtOnboardingLocalizations.load(const Locale("en"));

await AtOnboardingLocalizations.load(LanguageUtil.getLanguageFromLocale(Locale(Platform.localeName)).locale);
if (!mounted) return null;
Map<String, String> apis = {
"root.atsign.org": "my.atsign.com",
Expand All @@ -202,8 +201,7 @@ class _OnboardingButtonState extends State<OnboardingButton> {
var regUrl = apis[util.config.atClientPreference.rootDomain];
if (regUrl == null) {
result ??= AtOnboardingResult.error(
// TODO: localize
message: "The specified root domain is not supported by automatic activation.",
message: strings.errorRootDomainNotSupported,
);
break;
}
Expand All @@ -224,7 +222,7 @@ class _OnboardingButtonState extends State<OnboardingButton> {
var onboardingService = OnboardingService.getInstance();
bool res = await onboardingService.changePrimaryAtsign(atsign: result.atsign!);
if (!res) {
result = AtOnboardingResult.error(message: "Failed to switch atSigns after activation");
result = AtOnboardingResult.error(message: strings.errorSwitchAtSignFailed);
}
}
}
Expand All @@ -237,20 +235,16 @@ class _OnboardingButtonState extends State<OnboardingButton> {
result = await handleFileUploadStatusStream(statusStream, atsign);
case AtSignStatus.notFound:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign you have requested, doesn't exist in this root domain",
message: strings.errorAtSignNotExist,
);
case AtSignStatus.unavailable:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign is unavailable. Make sure you have pressed \"Activate\" from your dashboard "
"and have a stable internet connection.",
message: strings.errorAtServerUnavailable,
);
case null: // This case should never happen, treat it as an error
case AtSignStatus.error:
result = AtOnboardingResult.error(
// TODO: localize
message: "Failed to retrieve the atserver status",
message: strings.errorAtServerUnavailable,
);
}
return result;
Expand All @@ -265,44 +259,37 @@ class _OnboardingButtonState extends State<OnboardingButton> {
switch (status) {
case ErrorIncorrectKeyFile():
result = AtOnboardingResult.error(
// TODO: localize
message: "Invalid atKeys file detected",
message: strings.errorAtKeysInvalid,
);
break outer;
case ErrorAtSignMismatch():
result = AtOnboardingResult.error(
// TODO: localize
message: "The atKeys file you uploaded did not match the atSign requested",
message: strings.errorAtKeysUploadedMismatch,
);
break outer;
case ErrorFailedFileProcessing():
result = AtOnboardingResult.error(
// TODO: localize
message: "Failed to process the atKeys file",
message: strings.errorAtKeysFileProcessFailed,
);
break outer;
case ErrorAtServerUnreachable():
result = AtOnboardingResult.error(
// TODO: localize
message: "Unable to connect to the atServer, make sure you have a stable internet connection",
message: strings.errorAtServerUnavailable,
);
break outer;
case ErrorAuthFailed():
result = AtOnboardingResult.error(
// TODO: localize
message: "Authentication failed",
message: strings.errorAuthenticatinFailed,
);
break outer;
case ErrorAuthTimeout():
result = AtOnboardingResult.error(
// TODO: localize
message: "Authentication timed out",
message: strings.errorAuthenticationTimedOut,
);
break outer;
case ErrorPairedAtsign _:
result = AtOnboardingResult.error(
// TODO: localize
message: "The atSign ${status.atSign ?? atsign} is already paired, please contact support.",
message: strings.errorAtSignAlreadyPaired(status.atSign ?? atsign),
);
break outer;
case FilePickingInProgress():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class OnboardingDialog extends StatelessWidget {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Text("Select or type the client atSign"),
Text(strings.selectorTitleAtsign),
gapH16,
AtsignSelector(
options: options,
),
gapH16,
const Text("Select or type the root domain"),
Text(strings.selectorTitleRootDomain),
AtDirectorySelector(
options: options,
),
Expand All @@ -53,7 +53,7 @@ class OnboardingDialog extends StatelessWidget {
onPressed: () {
Navigator.of(context).pop(true);
},
child: const Text("Next"),
child: Text(strings.next),
),
],
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ class ProfileHeaderView extends StatelessWidget {
);

case ProfileListFailedLoad _:
return const Row(
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Failed to load this profile, please refresh manually:"),
ProfileListRefreshButton(),
Text(strings.errorProfileLoadFailed),
const ProfileListRefreshButton(),
],
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/features/profile/profile.dart';
import 'package:npt_flutter/features/settings/settings.dart';
import 'package:npt_flutter/styles/sizes.dart';
Expand Down Expand Up @@ -28,11 +29,11 @@ class ProfileView extends StatelessWidget {
);

case ProfileFailedLoad _:
return const Row(
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text("Failed to load this profile, please refresh manually:"),
ProfileRefreshButton(),
Text(AppLocalizations.of(context)!.errorProfileLoadFailed),
const ProfileRefreshButton(),
],
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:npt_flutter/features/profile/profile.dart';

class ProfileRefreshButton extends StatelessWidget {
Expand All @@ -10,11 +11,9 @@ class ProfileRefreshButton extends StatelessWidget {
return BlocBuilder<ProfileBloc, ProfileState>(
builder: (BuildContext context, ProfileState state) => ElevatedButton(
onPressed: () {
context
.read<ProfileBloc>()
.add(const ProfileLoadEvent(useCache: false));
context.read<ProfileBloc>().add(const ProfileLoadEvent(useCache: false));
},
child: const Text("Refresh"),
child: Text(AppLocalizations.of(context)!.refresh),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ class ProfileListView extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("Failed to load profiles"),
Text(strings.profilesFailedLoaded),
ElevatedButton(
child: const Text("Reload"),
child: Text(strings.reload),
onPressed: () {
context.read<ProfileListBloc>().add(const ProfileListLoadEvent());
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:npt_flutter/features/settings/settings.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';

class SettingsErrorHint extends StatelessWidget {
const SettingsErrorHint({
Expand All @@ -19,7 +20,7 @@ class SettingsErrorHint extends StatelessWidget {
return BlocSelector<SettingsBloc, SettingsState, bool>(selector: (state) {
return state is SettingsFailedLoad;
}, builder: (context, hasError) {
if (hasError) return const Text("Error loading profile");
if (hasError) return Text(AppLocalizations.of(context)!.profileFailedLoaded);
return Container();
});
}
Expand Down
Loading

0 comments on commit fc6a9c9

Please sign in to comment.