- Localization of CmdEdit.cpp, which means L10N is complete.
This commit is contained in:
Paul Beckingham 2011-12-01 00:46:54 -05:00
parent c25bb6404f
commit 1d9a11f8ea
2 changed files with 132 additions and 62 deletions

View file

@ -25,6 +25,7 @@
// //
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
#define L10N // Localization complete.
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
@ -34,6 +35,7 @@
#include <i18n.h> #include <i18n.h>
#include <text.h> #include <text.h>
#include <util.h> #include <util.h>
#include <i18n.h>
#include <main.h> #include <main.h>
#include <CmdEdit.h> #include <CmdEdit.h>
@ -143,24 +145,24 @@ std::string CmdEdit::formatTask (Task task)
context.config.getBoolean ("edit.verbose"); // Deprecated 2.0 context.config.getBoolean ("edit.verbose"); // Deprecated 2.0
if (verbose) if (verbose)
before << "# The 'task edit <id>' command allows you to modify all aspects of a task\n" before << "# " << STRING_EDIT_HEADER_1 << "\n"
<< "# using a text editor. Below is a representation of all the task details.\n" << "# " << STRING_EDIT_HEADER_2 << "\n"
<< "# Modify what you wish, and when you save and quit your editor,\n" << "# " << STRING_EDIT_HEADER_3 << "\n"
<< "# taskwarrior will read this file, determine what changed, and apply\n" << "# " << STRING_EDIT_HEADER_4 << "\n"
<< "# those changes. If you exit your editor without saving or making\n" << "# " << STRING_EDIT_HEADER_5 << "\n"
<< "# modifications, taskwarrior will do nothing.\n" << "# " << STRING_EDIT_HEADER_6 << "\n"
<< "#\n" << "#\n"
<< "# Lines that begin with # represent data you cannot change, like ID.\n" << "# " << STRING_EDIT_HEADER_7 << "\n"
<< "# If you get too creative with your editing, taskwarrior will send you\n" << "# " << STRING_EDIT_HEADER_8 << "\n"
<< "# back to the editor to try again.\n" << "# " << STRING_EDIT_HEADER_9 << "\n"
<< "#\n" << "#\n"
<< "# Should you find yourself in an endless loop, re-editing the same file,\n" << "# " << STRING_EDIT_HEADER_10 << "\n"
<< "# just quit the editor without making any changes. Taskwarrior will \n" << "# " << STRING_EDIT_HEADER_11 << "\n"
<< "# notice this and stop the editing.\n" << "# " << STRING_EDIT_HEADER_12 << "\n"
<< "#\n"; << "#\n";
before << "# Name Editable details\n" before << "# " << STRING_EDIT_TABLE_HEADER_1 << "\n"
<< "# ----------------- ----------------------------------------------------\n" << "# " << STRING_EDIT_TABLE_HEADER_2 << "\n"
<< "# ID: " << task.id << "\n" << "# ID: " << task.id << "\n"
<< "# UUID: " << task.get ("uuid") << "\n" << "# UUID: " << task.get ("uuid") << "\n"
<< "# Status: " << ucFirst (Task::statusToText (task.getStatus ())) << "\n" << "# Status: " << ucFirst (Task::statusToText (task.getStatus ())) << "\n"
@ -175,7 +177,7 @@ std::string CmdEdit::formatTask (Task task)
join (allTags, " ", tags); join (allTags, " ", tags);
if (verbose) if (verbose)
before << "# Separate the tags with spaces, like this: tag1 tag2\n"; before << "# " << STRING_EDIT_TAG_SEP << "\n";
before << " Tags: " << allTags << "\n" before << " Tags: " << allTags << "\n"
<< " Description: " << task.get ("description") << "\n" << " Description: " << task.get ("description") << "\n"
@ -191,9 +193,9 @@ std::string CmdEdit::formatTask (Task task)
<< " Background color: " << task.get ("bg") << "\n"; << " Background color: " << task.get ("bg") << "\n";
if (verbose) if (verbose)
before << "# Annotations look like this: <date> -- <text> and there can be any number of them.\n" before << "# " << STRING_EDIT_HEADER_13 << "\n"
<< "# The ' -- ' separator between the date and text field should not be removed.\n" << "# " << STRING_EDIT_HEADER_14 << "\n"
<< "# A \"blank slot\" for adding an annotation follows for your convenience.\n"; << "# " << STRING_EDIT_HEADER_15 << "\n";
std::map <std::string, std::string> annotations; std::map <std::string, std::string> annotations;
task.getAnnotations (annotations); task.getAnnotations (annotations);
@ -215,11 +217,11 @@ std::string CmdEdit::formatTask (Task task)
join (allDeps, ",", dependencies); join (allDeps, ",", dependencies);
if (verbose) if (verbose)
before << "# Dependencies should be a comma-separated list of task IDs, with no spaces.\n"; before << "# " << STRING_EDIT_DEP_SEP << "\n";
before << " Dependencies: " << allDeps << "\n"; before << " Dependencies: " << allDeps << "\n";
before << "# End\n"; before << "# " << STRING_EDIT_END << "\n";
return before.str (); return before.str ();
} }
@ -232,12 +234,12 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (value != "") if (value != "")
{ {
context.footnote ("Project modified."); context.footnote (STRING_EDIT_PROJECT_MOD);
task.set ("project", value); task.set ("project", value);
} }
else else
{ {
context.footnote ("Project deleted."); context.footnote (STRING_EDIT_PROJECT_DEL);
task.remove ("project"); task.remove ("project");
} }
} }
@ -250,13 +252,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (context.columns["priority"]->validate (value)) if (context.columns["priority"]->validate (value))
{ {
context.footnote ("Priority modified."); context.footnote (STRING_EDIT_PRIORITY_MOD);
task.set ("priority", value); task.set ("priority", value);
} }
} }
else else
{ {
context.footnote ("Priority deleted."); context.footnote (STRING_EDIT_PRIORITY_DEL);
task.remove ("priority"); task.remove ("priority");
} }
} }
@ -274,11 +276,11 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (value != "") if (value != "")
{ {
context.footnote ("Description modified."); context.footnote (STRING_EDIT_DESC_MOD);
task.set ("description", value); task.set ("description", value);
} }
else else
throw std::string ("Cannot remove description."); throw std::string (STRING_EDIT_DESC_REMOVE_ERR);
} }
// entry // entry
@ -290,12 +292,12 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("entry")); Date original (task.get_date ("entry"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Creation date modified."); context.footnote (STRING_EDIT_ENTRY_MOD);
task.set ("entry", value); task.set ("entry", value);
} }
} }
else else
throw std::string ("Cannot remove creation date."); throw std::string (STRING_EDIT_ENTRY_REMOVE_ERR);
// start // start
value = findDate (after, "\n Started:"); value = findDate (after, "\n Started:");
@ -308,13 +310,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("start")); Date original (task.get_date ("start"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Start date modified."); context.footnote (STRING_EDIT_START_MOD);
task.set ("start", value); task.set ("start", value);
} }
} }
else else
{ {
context.footnote ("Start date modified."); context.footnote (STRING_EDIT_START_MOD);
task.set ("start", value); task.set ("start", value);
} }
} }
@ -322,7 +324,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (task.get ("start") != "") if (task.get ("start") != "")
{ {
context.footnote ("Start date removed."); context.footnote (STRING_EDIT_START_DEL);
task.remove ("start"); task.remove ("start");
} }
} }
@ -338,18 +340,18 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("end")); Date original (task.get_date ("end"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Done date modified."); context.footnote (STRING_EDIT_END_MOD);
task.set ("end", value); task.set ("end", value);
} }
} }
else if (task.getStatus () != Task::deleted) else if (task.getStatus () != Task::deleted)
throw std::string ("Cannot set a done date on a pending task."); throw std::string (STRING_EDIT_END_SET_ERR);
} }
else else
{ {
if (task.get ("end") != "") if (task.get ("end") != "")
{ {
context.footnote ("Done date removed."); context.footnote (STRING_EDIT_END_DEL);
task.setStatus (Task::pending); task.setStatus (Task::pending);
task.remove ("end"); task.remove ("end");
} }
@ -366,13 +368,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("due")); Date original (task.get_date ("due"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Due date modified."); context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", value); task.set ("due", value);
} }
} }
else else
{ {
context.footnote ("Due date modified."); context.footnote (STRING_EDIT_DUE_MOD);
task.set ("due", value); task.set ("due", value);
} }
} }
@ -383,11 +385,11 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
if (task.getStatus () == Task::recurring || if (task.getStatus () == Task::recurring ||
task.get ("parent") != "") task.get ("parent") != "")
{ {
context.footnote ("Cannot remove a due date from a recurring task."); context.footnote (STRING_EDIT_DUE_DEL_ERR);
} }
else else
{ {
context.footnote ("Due date removed."); context.footnote (STRING_EDIT_DUE_DEL);
task.remove ("due"); task.remove ("due");
} }
} }
@ -404,13 +406,13 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("until")); Date original (task.get_date ("until"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Until date modified."); context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", value); task.set ("until", value);
} }
} }
else else
{ {
context.footnote ("Until date modified."); context.footnote (STRING_EDIT_UNTIL_MOD);
task.set ("until", value); task.set ("until", value);
} }
} }
@ -418,7 +420,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (task.get ("until") != "") if (task.get ("until") != "")
{ {
context.footnote ("Until date removed."); context.footnote (STRING_EDIT_UNTIL_DEL);
task.remove ("until"); task.remove ("until");
} }
} }
@ -432,21 +434,21 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Duration d; Duration d;
if (d.valid (value)) if (d.valid (value))
{ {
context.footnote ("Recurrence modified."); context.footnote (STRING_EDIT_RECUR_MOD);
if (task.get ("due") != "") if (task.get ("due") != "")
{ {
task.set ("recur", value); task.set ("recur", value);
task.setStatus (Task::recurring); task.setStatus (Task::recurring);
} }
else else
throw std::string ("A recurring task must have a due date."); throw std::string (STRING_EDIT_RECUR_DUE_ERR);
} }
else else
throw std::string ("Not a valid recurrence duration."); throw std::string (STRING_EDIT_RECUR_ERR);
} }
else else
{ {
context.footnote ("Recurrence removed."); context.footnote (STRING_EDIT_RECUR_DEL);
task.setStatus (Task::pending); task.setStatus (Task::pending);
task.remove ("recur"); task.remove ("recur");
task.remove ("until"); task.remove ("until");
@ -466,14 +468,14 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
Date original (task.get_date ("wait")); Date original (task.get_date ("wait"));
if (!original.sameDay (edited)) if (!original.sameDay (edited))
{ {
context.footnote ("Wait date modified."); context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", value); task.set ("wait", value);
task.setStatus (Task::waiting); task.setStatus (Task::waiting);
} }
} }
else else
{ {
context.footnote ("Wait date modified."); context.footnote (STRING_EDIT_WAIT_MOD);
task.set ("wait", value); task.set ("wait", value);
task.setStatus (Task::waiting); task.setStatus (Task::waiting);
} }
@ -482,7 +484,7 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (task.get ("wait") != "") if (task.get ("wait") != "")
{ {
context.footnote ("Wait date removed."); context.footnote (STRING_EDIT_WAIT_DEL);
task.remove ("wait"); task.remove ("wait");
task.setStatus (Task::pending); task.setStatus (Task::pending);
} }
@ -494,12 +496,12 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (value != "") if (value != "")
{ {
context.footnote ("Parent UUID modified."); context.footnote (STRING_EDIT_PARENT_MOD);
task.set ("parent", value); task.set ("parent", value);
} }
else else
{ {
context.footnote ("Parent UUID removed."); context.footnote (STRING_EDIT_PARENT_DEL);
task.remove ("parent"); task.remove ("parent");
} }
} }
@ -510,12 +512,12 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (value != "") if (value != "")
{ {
context.footnote ("Foreground color modified."); context.footnote (STRING_EDIT_FG_MOD);
task.set ("fg", value); task.set ("fg", value);
} }
else else
{ {
context.footnote ("Foreground color removed."); context.footnote (STRING_EDIT_FG_DEL);
task.remove ("fg"); task.remove ("fg");
} }
} }
@ -526,12 +528,12 @@ void CmdEdit::parseTask (Task& task, const std::string& after)
{ {
if (value != "") if (value != "")
{ {
context.footnote ("Background color modified."); context.footnote (STRING_EDIT_BG_MOD);
task.set ("bg", value); task.set ("bg", value);
} }
else else
{ {
context.footnote ("Background color removed."); context.footnote (STRING_EDIT_BG_DEL);
task.remove ("bg"); task.remove ("bg");
} }
} }
@ -591,7 +593,7 @@ bool CmdEdit::editFile (Task& task)
// Check for file permissions. // Check for file permissions.
Directory location (context.config.get ("data.location")); Directory location (context.config.get ("data.location"));
if (! location.writable ()) if (! location.writable ())
throw std::string ("Your data.location directory is not writable."); throw std::string (STRING_EDIT_UNWRITABLE);
// Create a temp file name in data.location. // Create a temp file name in data.location.
std::stringstream file; std::stringstream file;
@ -620,11 +622,11 @@ ARE_THESE_REALLY_HARMFUL:
bool changes = false; // No changes made. bool changes = false; // No changes made.
// Launch the editor. // Launch the editor.
std::cout << "Launching '" << editor << "' now...\n"; std::cout << format (STRING_EDIT_LAUNCHING, editor) << "\n";
if (-1 == system (editor.c_str ())) if (-1 == system (editor.c_str ()))
std::cout << "No editing performed.\n"; std::cout << STRING_EDIT_NO_EDITS << "\n";
else else
std::cout << "Editing complete.\n"; std::cout << STRING_EDIT_COMPLETE << "\n";
// Slurp file. // Slurp file.
std::string after; std::string after;
@ -634,7 +636,7 @@ ARE_THESE_REALLY_HARMFUL:
// if changes were made. // if changes were made.
if (before != after) if (before != after)
{ {
std::cout << "Edits were detected.\n"; std::cout << STRING_EDIT_CHANGES << "\n";
std::string problem = ""; std::string problem = "";
bool oops = false; bool oops = false;
@ -651,13 +653,13 @@ ARE_THESE_REALLY_HARMFUL:
if (oops) if (oops)
{ {
std::cout << "Error: " << problem << "\n"; std::cout << STRING_ERROR_PREFIX << problem << "\n";
// Preserve the edits. // Preserve the edits.
before = after; before = after;
File::write (file.str (), before); File::write (file.str (), before);
if (confirm ("Taskwarrior couldn't handle your edits. Would you like to try again?")) if (confirm (STRING_EDIT_UNPARSEABLE))
goto ARE_THESE_REALLY_HARMFUL; goto ARE_THESE_REALLY_HARMFUL;
} }
else else
@ -665,7 +667,7 @@ ARE_THESE_REALLY_HARMFUL:
} }
else else
{ {
std::cout << "No edits were detected.\n"; std::cout << STRING_EDIT_NO_CHANGES << "\n";
changes = false; changes = false;
} }

View file

@ -582,8 +582,76 @@
#define STRING_E9_INSUFFICIENT_OP "There are not enough operands for the '{1}' operator." #define STRING_E9_INSUFFICIENT_OP "There are not enough operands for the '{1}' operator."
#define STRING_E9_MORE_OP "Found extra operands." #define STRING_E9_MORE_OP "Found extra operands."
// edit
#define STRING_EDIT_NO_CHANGES "No edits were detected."
#define STRING_EDIT_NO_EDITS "No editing performed."
#define STRING_EDIT_COMPLETE "Editing complete."
#define STRING_EDIT_LAUNCHING "Launching '{1}' now..."
#define STRING_EDIT_CHANGES "Edits were detected."
#define STRING_EDIT_UNPARSEABLE "Taskwarrior couldn't handle your edits. Would you like to try again?"
#define STRING_EDIT_UNWRITABLE "Your data.location directory is not writable."
#define STRING_EDIT_TAG_SEP "Separate the tags with spaces, like this: tag1 tag2"
#define STRING_EDIT_DEP_SEP "Dependencies should be a comma-separated list of task IDs, with no spaces."
#define STRING_EDIT_END "End"
#define STRING_EDIT_PROJECT_MOD "Project modified."
#define STRING_EDIT_PROJECT_DEL "Project deleted."
#define STRING_EDIT_PRIORITY_MOD "Priority modified."
#define STRING_EDIT_PRIORITY_DEL "Priority deleted."
#define STRING_EDIT_DESC_MOD "Description modified."
#define STRING_EDIT_DESC_REMOVE_ERR "Cannot remove description."
#define STRING_EDIT_ENTRY_REMOVE_ERR "Cannot remove creation date."
#define STRING_EDIT_ENTRY_MOD "Creation date modified."
#define STRING_EDIT_START_MOD "Start date modified."
#define STRING_EDIT_START_DEL "Start date removed."
#define STRING_EDIT_END_MOD "End date modified."
#define STRING_EDIT_END_DEL "End date removed."
#define STRING_EDIT_END_SET_ERR "Cannot set a done date on a pending task."
#define STRING_EDIT_DUE_MOD "Due date modified."
#define STRING_EDIT_DUE_DEL "Due date removed."
#define STRING_EDIT_DUE_DEL_ERR "Cannot remove a due date from a recurring task."
#define STRING_EDIT_UNTIL_MOD "Until date modified."
#define STRING_EDIT_UNTIL_DEL "Until date removed."
#define STRING_EDIT_RECUR_MOD "Recurrence modified."
#define STRING_EDIT_RECUR_DEL "Recurrence removed."
#define STRING_EDIT_RECUR_DUE_ERR "A recurring task must have a due date."
#define STRING_EDIT_RECUR_ERR "Not a valid recurrence duration."
#define STRING_EDIT_WAIT_MOD "Wait date modified."
#define STRING_EDIT_WAIT_DEL "Wait date removed."
#define STRING_EDIT_PARENT_MOD "Parent UUID modified."
#define STRING_EDIT_PARENT_DEL "Parent UUID removed."
#define STRING_EDIT_FG_MOD "Foreground color modified."
#define STRING_EDIT_FG_DEL "Foreground color removed."
#define STRING_EDIT_BG_MOD "Background color modified."
#define STRING_EDIT_BG_DEL "Background color removed."
// These four blocks can be replaced, but the number of lines must not change.
#define STRING_EDIT_HEADER_1 "The 'task edit <id>' command allows you to modify all aspects of a task"
#define STRING_EDIT_HEADER_2 "using a text editor. Below is a representation of all the task details."
#define STRING_EDIT_HEADER_3 "Modify what you wish, and when you save and quit your editor,"
#define STRING_EDIT_HEADER_4 "taskwarrior will read this file, determine what changed, and apply"
#define STRING_EDIT_HEADER_5 "those changes. If you exit your editor without saving or making"
#define STRING_EDIT_HEADER_6 "modifications, taskwarrior will do nothing."
#define STRING_EDIT_HEADER_7 "Lines that begin with # represent data you cannot change, like ID."
#define STRING_EDIT_HEADER_8 "If you get too creative with your editing, taskwarrior will send you"
#define STRING_EDIT_HEADER_9 "back to the editor to try again."
#define STRING_EDIT_HEADER_10 "Should you find yourself in an endless loop, re-editing the same file,"
#define STRING_EDIT_HEADER_11 "just quit the editor without making any changes. Taskwarrior will"
#define STRING_EDIT_HEADER_12 "notice this and stop the editing."
#define STRING_EDIT_HEADER_13 "Annotations look like this: <date> -- <text> and there can be any number of them."
#define STRING_EDIT_HEADER_14 "The ' -- ' separator between the date and text field should not be removed."
#define STRING_EDIT_HEADER_15 "A \"blank slot\" for adding an annotation follows for your convenience."
// Maintain the same spacing.
#define STRING_EDIT_TABLE_HEADER_1 "Name Editable details"
#define STRING_EDIT_TABLE_HEADER_2 "----------------- ----------------------------------------------------"
// Errors // Errors
// TODO Move each of these to appropriate section. // TODO Move each of these to appropriate section.
#define STRING_ERROR_PREFIX "Error: "
#define STRING_UNKNOWN_ERROR "Unknown error." #define STRING_UNKNOWN_ERROR "Unknown error."
#define STRING_NO_HOME "Could not read home directory from the passwd file." #define STRING_NO_HOME "Could not read home directory from the passwd file."
#define STRING_TRIVIAL_INPUT "You must specify a command or a task to modify." #define STRING_TRIVIAL_INPUT "You must specify a command or a task to modify."