From a9591010106b2fd7ecf724b5864a87b9a3fb1ca0 Mon Sep 17 00:00:00 2001 From: Vishesh Handa Date: Thu, 14 May 2020 12:00:40 +0200 Subject: [PATCH] Make some strings translatable Instead of hard-coding the strings. --- assets/langs/en.yaml | 26 ++++++++++++++++++++++ lib/screens/folder_listing.dart | 39 ++++++++++++++++++--------------- lib/widgets/rename_dialog.dart | 11 +++++----- 3 files changed, 53 insertions(+), 23 deletions(-) diff --git a/assets/langs/en.yaml b/assets/langs/en.yaml index 300cc694..7499fbcc 100644 --- a/assets/langs/en.yaml +++ b/assets/langs/en.yaml @@ -36,3 +36,29 @@ actions: newNote: New Note newJournal: New Journal Entry newChecklist: New Checklist +screens: + folders: + title: Folders + selected: Folder Selected + dialog: + title: Create new Folder + create: Create + discard: Discard + errorDialog: + title: Error + content: Cannot delete a Folder which contains notes + ok: Ok + actions: + rename: Rename Folder + subFolder: Create Sub-Folder + delete: Delete Folder + decoration: Folder Name + empty: Please enter a name +widgets: + rename: + yes: Rename + no: Cancel + validator: + empty: Please enter a name + exists: Already Exists + contains: Cannot contain / diff --git a/lib/screens/folder_listing.dart b/lib/screens/folder_listing.dart index 8ccb11e7..faebf77a 100644 --- a/lib/screens/folder_listing.dart +++ b/lib/screens/folder_listing.dart @@ -1,3 +1,4 @@ +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; @@ -51,16 +52,16 @@ class _FolderListingScreenState extends State { action = PopupMenuButton( itemBuilder: (context) { return [ - const PopupMenuItem( - child: Text("Rename Folder"), + PopupMenuItem( + child: Text(tr("screens.folders.actions.rename")), value: "Rename", ), - const PopupMenuItem( - child: Text("Create Sub-Folder"), + PopupMenuItem( + child: Text(tr("screens.folders.actions.subFolder")), value: "Create", ), - const PopupMenuItem( - child: Text("Delete Folder"), + PopupMenuItem( + child: Text(tr("screens.folders.actions.delete")), value: "Delete", ), ]; @@ -71,8 +72,8 @@ class _FolderListingScreenState extends State { context: context, builder: (_) => RenameDialog( oldPath: selectedFolder.folderPath, - inputDecoration: 'Folder Name', - dialogTitle: "Rename Folder", + inputDecoration: tr("screens.folders.actions.decoration"), + dialogTitle: tr("screens.folders.actions.rename"), ), ); if (folderName is String) { @@ -115,9 +116,9 @@ class _FolderListingScreenState extends State { }, ); - var title = const Text("Folders"); + var title = Text(tr('screens.folders.title')); if (selectedFolder != null) { - title = const Text("Folder Selected"); + title = Text(tr("screens.folders.selected")); } return Scaffold( @@ -173,9 +174,11 @@ class _CreateFolderAlertDialogState extends State { mainAxisSize: MainAxisSize.min, children: [ TextFormField( - decoration: const InputDecoration(labelText: 'Folder Name'), + decoration: InputDecoration( + labelText: tr("screens.folders.actions.decoration"), + ), validator: (value) { - if (value.isEmpty) return 'Please enter a name'; + if (value.isEmpty) return tr("screens.folders.actions.empty"); return ""; }, autofocus: true, @@ -188,18 +191,18 @@ class _CreateFolderAlertDialogState extends State { ); return AlertDialog( - title: const Text("Create new Folder"), + title: Text(tr("screens.folders.dialog.title")), actions: [ FlatButton( onPressed: () => Navigator.of(context).pop(false), - child: const Text("Discard"), + child: Text(tr("screens.folders.dialog.create")), ), FlatButton( onPressed: () { var newFolderName = _textController.text; return Navigator.of(context).pop(newFolderName); }, - child: const Text("Create"), + child: Text(tr("screens.folders.dialog.discard")), ), ], content: form, @@ -217,11 +220,11 @@ class FolderErrorDialog extends StatelessWidget { @override Widget build(BuildContext context) { return AlertDialog( - title: const Text("Error"), - content: const Text("Cannot delete a Folder which contains notes"), + title: Text(tr("screens.folders.errorDialog.title")), + content: Text(tr("screens.folders.errorDialog.content")), actions: [ FlatButton( - child: const Text("Ok"), + child: Text(tr("screens.folders.errorDialog.ok")), onPressed: () => Navigator.of(context).pop(), ), ], diff --git a/lib/widgets/rename_dialog.dart b/lib/widgets/rename_dialog.dart index 848c7946..787c15fd 100644 --- a/lib/widgets/rename_dialog.dart +++ b/lib/widgets/rename_dialog.dart @@ -1,5 +1,6 @@ import 'dart:io'; +import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:path/path.dart'; import 'package:path/path.dart' as p; @@ -40,17 +41,17 @@ class _RenameDialogState extends State { decoration: InputDecoration(labelText: widget.inputDecoration), validator: (value) { if (value.isEmpty) { - return 'Please enter a name'; + return tr('widgets.rename.validator.empty'); } if (value.contains(p.separator)) { - return 'Cannot contain ${p.separator}'; + return tr('widgets.rename.validator.contains'); } var newPath = join(dirname(widget.oldPath), value); if (FileSystemEntity.typeSync(newPath) != FileSystemEntityType.notFound) { - return 'Already Exists'; + return tr('widgets.rename.validator.exists'); } return null; }, @@ -68,7 +69,7 @@ class _RenameDialogState extends State { actions: [ FlatButton( onPressed: () => Navigator.of(context).pop(false), - child: const Text("Cancel"), + child: Text(tr('widgets.rename.no')), ), FlatButton( onPressed: () { @@ -77,7 +78,7 @@ class _RenameDialogState extends State { Navigator.of(context).pop(newName); } }, - child: const Text("Rename"), + child: Text(tr('widgets.rename.yes')), ), ], content: form,