Make some strings translatable

Instead of hard-coding the strings.
This commit is contained in:
Vishesh Handa
2020-05-14 12:00:40 +02:00
parent 867f6df14c
commit a959101010
3 changed files with 53 additions and 23 deletions

View File

@ -36,3 +36,29 @@ actions:
newNote: New Note newNote: New Note
newJournal: New Journal Entry newJournal: New Journal Entry
newChecklist: New Checklist 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 /

View File

@ -1,3 +1,4 @@
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
@ -51,16 +52,16 @@ class _FolderListingScreenState extends State<FolderListingScreen> {
action = PopupMenuButton( action = PopupMenuButton(
itemBuilder: (context) { itemBuilder: (context) {
return [ return [
const PopupMenuItem<String>( PopupMenuItem<String>(
child: Text("Rename Folder"), child: Text(tr("screens.folders.actions.rename")),
value: "Rename", value: "Rename",
), ),
const PopupMenuItem<String>( PopupMenuItem<String>(
child: Text("Create Sub-Folder"), child: Text(tr("screens.folders.actions.subFolder")),
value: "Create", value: "Create",
), ),
const PopupMenuItem<String>( PopupMenuItem<String>(
child: Text("Delete Folder"), child: Text(tr("screens.folders.actions.delete")),
value: "Delete", value: "Delete",
), ),
]; ];
@ -71,8 +72,8 @@ class _FolderListingScreenState extends State<FolderListingScreen> {
context: context, context: context,
builder: (_) => RenameDialog( builder: (_) => RenameDialog(
oldPath: selectedFolder.folderPath, oldPath: selectedFolder.folderPath,
inputDecoration: 'Folder Name', inputDecoration: tr("screens.folders.actions.decoration"),
dialogTitle: "Rename Folder", dialogTitle: tr("screens.folders.actions.rename"),
), ),
); );
if (folderName is String) { if (folderName is String) {
@ -115,9 +116,9 @@ class _FolderListingScreenState extends State<FolderListingScreen> {
}, },
); );
var title = const Text("Folders"); var title = Text(tr('screens.folders.title'));
if (selectedFolder != null) { if (selectedFolder != null) {
title = const Text("Folder Selected"); title = Text(tr("screens.folders.selected"));
} }
return Scaffold( return Scaffold(
@ -173,9 +174,11 @@ class _CreateFolderAlertDialogState extends State<CreateFolderAlertDialog> {
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: <Widget>[ children: <Widget>[
TextFormField( TextFormField(
decoration: const InputDecoration(labelText: 'Folder Name'), decoration: InputDecoration(
labelText: tr("screens.folders.actions.decoration"),
),
validator: (value) { validator: (value) {
if (value.isEmpty) return 'Please enter a name'; if (value.isEmpty) return tr("screens.folders.actions.empty");
return ""; return "";
}, },
autofocus: true, autofocus: true,
@ -188,18 +191,18 @@ class _CreateFolderAlertDialogState extends State<CreateFolderAlertDialog> {
); );
return AlertDialog( return AlertDialog(
title: const Text("Create new Folder"), title: Text(tr("screens.folders.dialog.title")),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
onPressed: () => Navigator.of(context).pop(false), onPressed: () => Navigator.of(context).pop(false),
child: const Text("Discard"), child: Text(tr("screens.folders.dialog.create")),
), ),
FlatButton( FlatButton(
onPressed: () { onPressed: () {
var newFolderName = _textController.text; var newFolderName = _textController.text;
return Navigator.of(context).pop(newFolderName); return Navigator.of(context).pop(newFolderName);
}, },
child: const Text("Create"), child: Text(tr("screens.folders.dialog.discard")),
), ),
], ],
content: form, content: form,
@ -217,11 +220,11 @@ class FolderErrorDialog extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return AlertDialog( return AlertDialog(
title: const Text("Error"), title: Text(tr("screens.folders.errorDialog.title")),
content: const Text("Cannot delete a Folder which contains notes"), content: Text(tr("screens.folders.errorDialog.content")),
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
child: const Text("Ok"), child: Text(tr("screens.folders.errorDialog.ok")),
onPressed: () => Navigator.of(context).pop(), onPressed: () => Navigator.of(context).pop(),
), ),
], ],

View File

@ -1,5 +1,6 @@
import 'dart:io'; import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:path/path.dart'; import 'package:path/path.dart';
import 'package:path/path.dart' as p; import 'package:path/path.dart' as p;
@ -40,17 +41,17 @@ class _RenameDialogState extends State<RenameDialog> {
decoration: InputDecoration(labelText: widget.inputDecoration), decoration: InputDecoration(labelText: widget.inputDecoration),
validator: (value) { validator: (value) {
if (value.isEmpty) { if (value.isEmpty) {
return 'Please enter a name'; return tr('widgets.rename.validator.empty');
} }
if (value.contains(p.separator)) { if (value.contains(p.separator)) {
return 'Cannot contain ${p.separator}'; return tr('widgets.rename.validator.contains');
} }
var newPath = join(dirname(widget.oldPath), value); var newPath = join(dirname(widget.oldPath), value);
if (FileSystemEntity.typeSync(newPath) != if (FileSystemEntity.typeSync(newPath) !=
FileSystemEntityType.notFound) { FileSystemEntityType.notFound) {
return 'Already Exists'; return tr('widgets.rename.validator.exists');
} }
return null; return null;
}, },
@ -68,7 +69,7 @@ class _RenameDialogState extends State<RenameDialog> {
actions: <Widget>[ actions: <Widget>[
FlatButton( FlatButton(
onPressed: () => Navigator.of(context).pop(false), onPressed: () => Navigator.of(context).pop(false),
child: const Text("Cancel"), child: Text(tr('widgets.rename.no')),
), ),
FlatButton( FlatButton(
onPressed: () { onPressed: () {
@ -77,7 +78,7 @@ class _RenameDialogState extends State<RenameDialog> {
Navigator.of(context).pop(newName); Navigator.of(context).pop(newName);
} }
}, },
child: const Text("Rename"), child: Text(tr('widgets.rename.yes')),
), ),
], ],
content: form, content: form,