Skip to content

Commit

Permalink
feat: Migrated strings, and translations to native flutter l10n plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
astubenbord committed Feb 16, 2023
1 parent 7b55a96 commit 14ab604
Show file tree
Hide file tree
Showing 90 changed files with 1,661 additions and 683 deletions.
8 changes: 8 additions & 0 deletions crowdin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
files: [
{
"source" : "/lib/l10n/intl_en.arb",
"translation" : "/lib/l10n/intl_%two_letters_code%.arb",
"type" : "arb",
}
]
# Add your credentials here
4 changes: 2 additions & 2 deletions integration_test/src/framework.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

Future<TestingFrameworkVariables> initializeTestingFramework(
{String languageCode = 'en'}) async {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
final translations = await S.load(
final translations = await S.delegate.load(
Locale.fromSubtags(
languageCode: languageCode,
),
Expand Down
4 changes: 3 additions & 1 deletion l10n.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
arb-dir: lib/l10n
template-arb-file: intl_en.arb
output-dir: lib/generated/l10n
output-class: S
output-localization-file: app_localizations.dart
untranslated-messages-file: untranslated_messages.txt
synthetic-package: false
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import 'package:flutter/material.dart';
import 'package:paperless_mobile/features/settings/model/color_scheme_option.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

String translateColorSchemeOption(
BuildContext context, ColorSchemeOption option) {
switch (option) {
case ColorSchemeOption.classic:
return S.of(context).classic;
return S.of(context)!.classicColorScheme;
case ColorSchemeOption.dynamic:
return S.of(context).dynamic;
return S.of(context)!.dynamicColorScheme;
}
}
70 changes: 35 additions & 35 deletions lib/core/translation/error_code_localization_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
import 'package:flutter/cupertino.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

String translateError(BuildContext context, ErrorCode code) {
switch (code) {
case ErrorCode.unknown:
return S.of(context).anUnknownErrorOccurred;
return S.of(context)!.anUnknownErrorOccurred;
case ErrorCode.authenticationFailed:
return S.of(context).authenticationFailedPleaseTryAgain;
return S.of(context)!.authenticationFailedPleaseTryAgain;
case ErrorCode.notAuthenticated:
return S.of(context).userIsNotAuthenticated;
return S.of(context)!.userIsNotAuthenticated;
case ErrorCode.documentUploadFailed:
return S.of(context).couldNotUploadDocument;
return S.of(context)!.couldNotUploadDocument;
case ErrorCode.documentUpdateFailed:
return S.of(context).couldNotUpdateDocument;
return S.of(context)!.couldNotUpdateDocument;
case ErrorCode.documentLoadFailed:
return S.of(context).couldNotLoadDocuments;
return S.of(context)!.couldNotLoadDocuments;
case ErrorCode.documentDeleteFailed:
return S.of(context).couldNotDeleteDocument;
return S.of(context)!.couldNotDeleteDocument;
case ErrorCode.documentPreviewFailed:
return S.of(context).couldNotLoadDocumentPreview;
return S.of(context)!.couldNotLoadDocumentPreview;
case ErrorCode.documentAsnQueryFailed:
return S.of(context).couldNotAssignArchiveSerialNumber;
return S.of(context)!.couldNotAssignArchiveSerialNumber;
case ErrorCode.tagCreateFailed:
return S.of(context).couldNotCreateTag;
return S.of(context)!.couldNotCreateTag;
case ErrorCode.tagLoadFailed:
return S.of(context).couldNotLoadTags;
return S.of(context)!.couldNotLoadTags;
case ErrorCode.documentTypeCreateFailed:
return S.of(context).couldNotCreateDocument;
return S.of(context)!.couldNotCreateDocument;
case ErrorCode.documentTypeLoadFailed:
return S.of(context).couldNotLoadDocumentTypes;
return S.of(context)!.couldNotLoadDocumentTypes;
case ErrorCode.correspondentCreateFailed:
return S.of(context).couldNotCreateCorrespondent;
return S.of(context)!.couldNotCreateCorrespondent;
case ErrorCode.correspondentLoadFailed:
return S.of(context).couldNotLoadCorrespondents;
return S.of(context)!.couldNotLoadCorrespondents;
case ErrorCode.scanRemoveFailed:
return S.of(context).anErrorOccurredRemovingTheScans;
return S.of(context)!.anErrorOccurredRemovingTheScans;
case ErrorCode.invalidClientCertificateConfiguration:
return S.of(context).invalidCertificateOrMissingPassphrase;
return S.of(context)!.invalidCertificateOrMissingPassphrase;
case ErrorCode.documentBulkActionFailed:
return S.of(context).couldNotBulkEditDocuments;
return S.of(context)!.couldNotBulkEditDocuments;
case ErrorCode.biometricsNotSupported:
return S.of(context).biometricAuthenticationNotSupported;
return S.of(context)!.biometricAuthenticationNotSupported;
case ErrorCode.biometricAuthenticationFailed:
return S.of(context).biometricAuthenticationFailed;
return S.of(context)!.biometricAuthenticationFailed;
case ErrorCode.deviceOffline:
return S.of(context).youAreCurrentlyOffline;
return S.of(context)!.youAreCurrentlyOffline;
case ErrorCode.serverUnreachable:
return S.of(context).couldNotReachYourPaperlessServer;
return S.of(context)!.couldNotReachYourPaperlessServer;
case ErrorCode.similarQueryError:
return S.of(context).couldNotLoadSimilarDocuments;
return S.of(context)!.couldNotLoadSimilarDocuments;
case ErrorCode.autocompleteQueryError:
return S.of(context).anErrorOccurredWhileTryingToAutocompleteYourQuery;
return S.of(context)!.anErrorOccurredWhileTryingToAutocompleteYourQuery;
case ErrorCode.storagePathLoadFailed:
return S.of(context).couldNotLoadStoragePaths;
return S.of(context)!.couldNotLoadStoragePaths;
case ErrorCode.storagePathCreateFailed:
return S.of(context).couldNotCreateStoragePath;
return S.of(context)!.couldNotCreateStoragePath;
case ErrorCode.loadSavedViewsError:
return S.of(context).couldNotLoadSavedViews;
return S.of(context)!.couldNotLoadSavedViews;
case ErrorCode.createSavedViewError:
return S.of(context).couldNotCreateSavedView;
return S.of(context)!.couldNotCreateSavedView;
case ErrorCode.deleteSavedViewError:
return S.of(context).couldNotDeleteSavedView;
return S.of(context)!.couldNotDeleteSavedView;
case ErrorCode.requestTimedOut:
return S.of(context).requestTimedOut;
return S.of(context)!.requestTimedOut;
case ErrorCode.unsupportedFileFormat:
return S.of(context).fileFormatNotSupported;
return S.of(context)!.fileFormatNotSupported;
case ErrorCode.missingClientCertificate:
return S.of(context).aClientCertificateWasExpectedButNotSent;
return S.of(context)!.aClientCertificateWasExpectedButNotSent;
case ErrorCode.suggestionsQueryError:
return S.of(context).couldNotLoadSuggestions;
return S.of(context)!.couldNotLoadSuggestions;
case ErrorCode.acknowledgeTasksError:
return S.of(context).couldNotAcknowledgeTasks;
return S.of(context)!.couldNotAcknowledgeTasks;
}
}
26 changes: 13 additions & 13 deletions lib/core/translation/matching_algorithm_localization_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import 'package:flutter/material.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

String translateMatchingAlgorithmDescription(
BuildContext context,
MatchingAlgorithm algorithm,
) {
switch (algorithm) {
case MatchingAlgorithm.anyWord:
return S.of(context).documentContainsAnyOfTheseWords;
return S.of(context)!.documentContainsAnyOfTheseWords;
case MatchingAlgorithm.allWords:
return S.of(context).documentContainsAllOfTheseWords;
return S.of(context)!.documentContainsAllOfTheseWords;
case MatchingAlgorithm.exactMatch:
return S.of(context).documentContainsThisString;
return S.of(context)!.documentContainsThisString;
case MatchingAlgorithm.regex:
return S.of(context).documentMatchesThisRegularExpression;
return S.of(context)!.documentMatchesThisRegularExpression;
case MatchingAlgorithm.fuzzy:
return S.of(context).documentContainsAWordSimilarToThisWord;
return S.of(context)!.documentContainsAWordSimilarToThisWord;
case MatchingAlgorithm.auto:
return S.of(context).learnMatchingAutomatically;
return S.of(context)!.learnMatchingAutomatically;
}
}

Expand All @@ -28,16 +28,16 @@ String translateMatchingAlgorithmName(
) {
switch (algorithm) {
case MatchingAlgorithm.anyWord:
return S.of(context).any;
return S.of(context)!.any;
case MatchingAlgorithm.allWords:
return S.of(context).all;
return S.of(context)!.all;
case MatchingAlgorithm.exactMatch:
return S.of(context).exact;
return S.of(context)!.exact;
case MatchingAlgorithm.regex:
return S.of(context).regularExpression;
return S.of(context)!.regularExpression;
case MatchingAlgorithm.fuzzy:
return S.of(context).fuzzy;
return S.of(context)!.fuzzy;
case MatchingAlgorithm.auto:
return S.of(context).auto;
return S.of(context)!.auto;
}
}
16 changes: 8 additions & 8 deletions lib/core/translation/sort_field_localization_mapper.dart
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import 'package:flutter/material.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

String translateSortField(BuildContext context, SortField? sortField) {
switch (sortField) {
case SortField.archiveSerialNumber:
return S.of(context).asn;
return S.of(context)!.asn;
case SortField.correspondentName:
return S.of(context).correspondent;
return S.of(context)!.correspondent;
case SortField.title:
return S.of(context).title;
return S.of(context)!.title;
case SortField.documentType:
return S.of(context).documentType;
return S.of(context)!.documentType;
case SortField.created:
return S.of(context).createdAt;
return S.of(context)!.createdAt;
case SortField.added:
return S.of(context).addedAt;
return S.of(context)!.addedAt;
case SortField.modified:
return S.of(context).modifiedAt;
return S.of(context)!.modifiedAt;
default:
return '';
}
Expand Down
11 changes: 6 additions & 5 deletions lib/core/widgets/app_options_popup_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// import 'package:paperless_mobile/features/settings/bloc/application_settings_state.dart';
// import 'package:paperless_mobile/features/settings/model/view_type.dart';
// import 'package:paperless_mobile/features/settings/view/settings_page.dart';
// import 'package:paperless_mobile/generated/l10n.dart';
// import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

// import 'package:url_launcher/link.dart';
// import 'package:url_launcher/url_launcher_string.dart';

Expand Down Expand Up @@ -74,7 +75,7 @@
// padding: EdgeInsets.zero,
// child: ListTile(
// leading: const Icon(Icons.bug_report),
// title: Text(S.of(context).reportABug),
// title: Text(S.of(context)!.reportABug),
// ),
// );
// }
Expand All @@ -85,7 +86,7 @@
// value: AppPopupMenuEntries.openSettings,
// child: ListTile(
// leading: const Icon(Icons.settings_outlined),
// title: Text(S.of(context).settings),
// title: Text(S.of(context)!.settings),
// ),
// );
// }
Expand All @@ -96,7 +97,7 @@
// value: AppPopupMenuEntries.openAboutThisAppDialog,
// child: ListTile(
// leading: const Icon(Icons.info_outline),
// title: Text(S.of(context).aboutThisApp),
// title: Text(S.of(context)!.aboutThisApp),
// ),
// );
// }
Expand Down Expand Up @@ -146,7 +147,7 @@
// applicationName: 'Paperless Mobile',
// applicationVersion: packageInfo.version + '+' + packageInfo.buildNumber,
// children: [
// Text(S.of(context).developedBy('Anton Stubenbord')),
// Text(S.of(context)!.developedBy('Anton Stubenbord')),
// Link(
// uri: Uri.parse('https://github.com/astubenbord/paperless-mobile'),
// builder: (context, followLink) => GestureDetector(
Expand Down
4 changes: 2 additions & 2 deletions lib/core/widgets/dialog_utils/dialog_cancel_button.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:flutter/src/widgets/placeholder.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

class DialogCancelButton extends StatelessWidget {
final void Function()? onTap;
Expand All @@ -10,7 +10,7 @@ class DialogCancelButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
return TextButton(
child: Text(S.of(context).cancel),
child: Text(S.of(context)!.cancel),
onPressed: onTap ?? () => Navigator.pop(context),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:intl/intl.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/widgets/form_builder_fields/extended_date_range_form_field/form_builder_relative_date_range_field.dart';
import 'package:paperless_mobile/extensions/flutter_extensions.dart';
import 'package:paperless_mobile/generated/l10n.dart';
import 'package:paperless_mobile/generated/l10n/app_localizations.dart';

class ExtendedDateRangeDialog extends StatefulWidget {
final DateRangeQuery initialValue;
Expand Down Expand Up @@ -47,7 +47,7 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
Widget build(BuildContext context) {
return AlertDialog(
insetPadding: const EdgeInsets.all(24.0),
title: Text(S.of(context).selectDateRange),
title: Text(S.of(context)!.selectDateRange),
content: FormBuilder(
key: _formKey,
child: Column(
Expand All @@ -56,7 +56,7 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
children: [
_buildDateRangeQueryTypeSelection(),
Text(
S.of(context).hintYouCanAlsoSpecifyRelativeValues,
S.of(context)!.hintYouCanAlsoSpecifyRelativeValues,
style: Theme.of(context).textTheme.bodySmall,
).paddedOnly(top: 8, bottom: 16),
Builder(
Expand All @@ -83,11 +83,11 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
),
actions: [
TextButton(
child: Text(S.of(context).cancel),
child: Text(S.of(context)!.cancel),
onPressed: () => Navigator.pop(context),
),
TextButton(
child: Text(S.of(context).save),
child: Text(S.of(context)!.save),
onPressed: () {
_formKey.currentState?.save();
if (_formKey.currentState?.validate() ?? false) {
Expand All @@ -110,12 +110,12 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
ButtonSegment(
value: DateRangeType.absolute,
enabled: true,
label: Text(S.of(context).absolute),
label: Text(S.of(context)!.absolute),
),
ButtonSegment(
value: DateRangeType.relative,
enabled: true,
label: Text(S.of(context).relative),
label: Text(S.of(context)!.relative),
),
],
selected: {_selectedDateRangeType},
Expand All @@ -133,7 +133,7 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
: null,
initialDate: _before?.subtract(const Duration(days: 1)),
decoration: InputDecoration(
labelText: S.of(context).after,
labelText: S.of(context)!.after,
prefixIcon: const Icon(Icons.date_range),
suffixIcon: _after != null
? IconButton(
Expand Down Expand Up @@ -161,7 +161,7 @@ class _ExtendedDateRangeDialogState extends State<ExtendedDateRangeDialog> {
: null,
inputType: InputType.date,
decoration: InputDecoration(
labelText: S.of(context).before,
labelText: S.of(context)!.before,
prefixIcon: const Icon(Icons.date_range),
suffixIcon: _before != null
? IconButton(
Expand Down
Loading

0 comments on commit 14ab604

Please sign in to comment.