diff --git a/src/Color.cpp b/src/Color.cpp index df21cdda7..a53730461 100644 --- a/src/Color.cpp +++ b/src/Color.cpp @@ -24,6 +24,9 @@ // USA // //////////////////////////////////////////////////////////////////////////////// + +#define L10N // Localization complete. + #include #include #include @@ -150,7 +153,7 @@ Color::Color (const std::string& spec) { index = atoi (word.substr (4).c_str ()); if (index < 0 || index > 23) - throw std::string ("The color '") + *it + "' is not recognized."; + throw format (STRING_COLOR_UNRECOGNIZED, *it); if (bg) { @@ -172,7 +175,7 @@ Color::Color (const std::string& spec) index = atoi (word.substr (3).c_str ()); if (word.length () != 6 || index < 0 || index > 555) - throw std::string ("The color '") + *it + "' is not recognized."; + throw format (STRING_COLOR_UNRECOGNIZED, *it); int r = atoi (word.substr (3, 1).c_str ()); int g = atoi (word.substr (4, 1).c_str ()); @@ -180,7 +183,7 @@ Color::Color (const std::string& spec) if (r < 0 || r > 5 || g < 0 || g > 5 || b < 0 || b > 5) - throw std::string ("The color '") + *it + "' is not recognized."; + throw format (STRING_COLOR_UNRECOGNIZED, *it); index = 16 + r*36 + g*6 + b; @@ -203,7 +206,7 @@ Color::Color (const std::string& spec) { index = atoi (word.substr (5).c_str ()); if (index < 0 || index > 255) - throw std::string ("The color '") + *it + "' is not recognized."; + throw format (STRING_COLOR_UNRECOGNIZED, *it); upgrade (); @@ -221,7 +224,7 @@ Color::Color (const std::string& spec) } } else if (word != "") - throw std::string ("The color '") + *it + "' is not recognized."; + throw format (STRING_COLOR_UNRECOGNIZED, *it); } // Now combine the fg and bg into a single color. diff --git a/src/Permission.cpp b/src/Permission.cpp index 4b706f272..181002e10 100644 --- a/src/Permission.cpp +++ b/src/Permission.cpp @@ -29,8 +29,11 @@ #include #include #include +#include #include +#define L10N // Localization complete. + extern Context context; //////////////////////////////////////////////////////////////////////////////// @@ -56,16 +59,14 @@ bool Permission::confirmed (const Task& task, const std::string& question) if (allConfirmed) return true; - std::cout << "\nTask " - << task.id - << " \"" - << task.get ("description") - << "\""; + std::cout << "\n" + << format (STRING_PERM_TASK_LINE, task.id, task.get ("description")); if (task.getStatus () == Task::recurring || task.has ("parent")) { - std::cout << " (Recurring)"; + std::cout << " " + << STRING_PERM_RECURRING; } std::cout << std::endl; // Flush. diff --git a/src/Taskmod.cpp b/src/Taskmod.cpp index 6b312fcac..191829fb5 100644 --- a/src/Taskmod.cpp +++ b/src/Taskmod.cpp @@ -25,8 +25,11 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include +#include #include #include @@ -130,9 +133,7 @@ bool Taskmod::isValid () std::string Taskmod::getUuid () { if (!bAfterSet) - { - throw std::string ("Taskmod::getUuid(): Task object not initialized."); - } + throw std::string (STRING_TASKMOD_BAD_INIT); return after.get ("uuid"); } @@ -143,14 +144,14 @@ std::string Taskmod::toString () assert (bAfterSet); std::stringstream stream; - stream << "time " << timestamp << "\n"; + stream << STRING_TASKMOD_TIME << timestamp << "\n"; if (bBeforeSet) { - stream << "old " << before.composeF4(); + stream << STRING_TASKMOD_OLD << before.composeF4(); } - stream << "new " << after.composeF4(); + stream << STRING_TASKMOD_NEW << after.composeF4(); stream << "---\n"; return stream.str (); @@ -202,3 +203,5 @@ std::string Taskmod::getTimeStr () const return sstream.str (); } + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/Transport.cpp b/src/Transport.cpp index 35c50049b..ae6f57bbb 100644 --- a/src/Transport.cpp +++ b/src/Transport.cpp @@ -25,6 +25,8 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include diff --git a/src/Uri.cpp b/src/Uri.cpp index a159e1b50..46357ac9e 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -25,7 +25,11 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include +#include +#include #include extern Context context; @@ -231,7 +235,7 @@ void Uri::parse () } else { - throw std::string ("Could not parse uri '") + data + "', wrong usage of single quotes."; + throw std::string (format (STRING_URI_QUOTES, data)); } } else @@ -252,7 +256,7 @@ void Uri::parse () } else { - throw std::string ("The uri '") + data + "' is not in the expected format."; + throw std::string (format (STRING_URI_BAD_FORMAT, data)); } // path is absolute for ssh:// syntax diff --git a/src/ViewTask.cpp b/src/ViewTask.cpp index b87add4df..bffadbfed 100644 --- a/src/ViewTask.cpp +++ b/src/ViewTask.cpp @@ -25,6 +25,8 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include @@ -104,8 +106,6 @@ std::string ViewTask::render (std::vector & data, std::vector & seque // Determine minimal, ideal column widths. std::vector minimal; std::vector ideal; -// std::vector avg_ideal; -// int cumulative_ideal = 0; std::vector ::iterator i; for (i = _columns.begin (); i != _columns.end (); ++i) @@ -129,17 +129,10 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (min > global_min) global_min = min; if (ideal > global_ideal) global_ideal = ideal; - -// cumulative_ideal += ideal; } minimal.push_back (global_min); ideal.push_back (global_ideal); - -// if (data.size ()) -// avg_ideal.push_back ((int) (cumulative_ideal / data.size ())); -// else -// avg_ideal.push_back (0); } // Sum the minimal widths. @@ -163,7 +156,6 @@ std::string ViewTask::render (std::vector & data, std::vector & seque if (_width == 0 || sum_ideal <= overage) widths = ideal; else if (sum_minimal > overage || overage < 0) -// throw std::string ("There is not enough horizontal width to display the results."); widths = minimal; else if (overage > 0) { diff --git a/src/ViewText.cpp b/src/ViewText.cpp index 287942b3b..a00445047 100644 --- a/src/ViewText.cpp +++ b/src/ViewText.cpp @@ -25,6 +25,8 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include @@ -152,7 +154,6 @@ std::string ViewText::render () if (sum_ideal <= overage) widths = ideal; else if (sum_minimal > overage || overage < 0) -// throw std::string ("There is not enough horizontal width to display the results."); widths = minimal; else if (overage > 0) { diff --git a/src/commands/CmdExec.cpp b/src/commands/CmdExec.cpp index 5ee2e40ce..9f55f3df4 100644 --- a/src/commands/CmdExec.cpp +++ b/src/commands/CmdExec.cpp @@ -25,8 +25,11 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include +#include #include extern Context context; @@ -36,7 +39,7 @@ CmdExec::CmdExec () { _keyword = "execute"; _usage = "task execute "; - _description = "Executes external commands and scripts"; + _description = STRING_CMD_EXEC_USAGE; _read_only = false; _displays_id = true; } diff --git a/src/commands/CmdUrgency.cpp b/src/commands/CmdUrgency.cpp index 54c9137ef..01bb242e0 100644 --- a/src/commands/CmdUrgency.cpp +++ b/src/commands/CmdUrgency.cpp @@ -25,10 +25,14 @@ // //////////////////////////////////////////////////////////////////////////////// +#define L10N // Localization complete. + #include #include #include #include +#include +#include #include extern Context context; @@ -38,7 +42,7 @@ CmdUrgency::CmdUrgency () { _keyword = "_urgency"; _usage = "task _urgency "; - _description = "Displays the urgency measure of a task."; + _description = STRING_CMD_URGENCY_USAGE; _read_only = true; _displays_id = false; } @@ -60,7 +64,7 @@ int CmdUrgency::execute (std::string& output) if (filtered.size () == 0) { - context.footnote ("No tasks specified."); + context.footnote (STRING_CMD_URGENCY_NO_TASKS); return 1; } @@ -68,10 +72,7 @@ int CmdUrgency::execute (std::string& output) std::stringstream out; std::vector ::iterator task; for (task = filtered.begin (); task != filtered.end (); ++task) - out << "task " - << task->id - << " urgency " - << task->urgency () + out << format (STRING_CMD_URGENCY_RESULT, task->id, task->urgency ()) << "\n"; output = out.str (); diff --git a/src/en-US.h b/src/en-US.h index 3c346ed58..62b23af6f 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -102,6 +102,9 @@ #define STRING_API_WARNING "Warning: {1}" #define STRING_API_ERROR "Error: {1}" +// Color +#define STRING_COLOR_UNRECOGNIZED "The color '{1}' is not recognized." + // columns/Col* #define STRING_COLUMN_BAD_NAME "Unrecognized column name '{1}'" #define STRING_COLUMN_BAD_FORMAT "Unrecognized column format '{1}.{2}'" @@ -150,6 +153,10 @@ #define STRING_CMD_VERSION_COPY2 "Portions of this software Copyright (C) 1994 – 2008 Lua.org, PUC-Rio." #define STRING_CMD_LOGO_USAGE "Displays the Taskwarrior logo" #define STRING_CMD_LOGO_COLOR_REQ "The logo command requires that color support is enabled." +#define STRING_CMD_EXEC_USAGE "Executes external commands and scripts" +#define STRING_CMD_URGENCY_USAGE "Displays the urgency measure of a task." +#define STRING_CMD_URGENCY_NO_TASKS "No tasks specified." +#define STRING_CMD_URGENCY_RESULT "task {1} urgency {2}" // Config #define STRING_CONFIG_OVERNEST "Configuration file nested to more than 10 levels deep - this has to be a mistake." @@ -182,6 +189,10 @@ #define STRING_LUA_BAD_HOOK_DEF "Malformed hook definition '{1}'." #define STRING_LUA_BAD_EVENT "Unrecognized hook event '{1}'." +// Permission +#define STRING_PERM_TASK_LINE "task {1} \"{2}\"" +#define STRING_PERM_RECURRING "(Recurring)" + // Record #define STRING_RECORD_EMPTY "Empty record in input." #define STRING_RECORD_JUNK_AT_EOL "Unrecognized characters at end of line." @@ -202,10 +213,20 @@ #define STRING_CMD_SHOW_CONF_VAR "Config Variable" #define STRING_CMD_SHOW_CONF_VALUE "Value" +// Taskmod +#define STRING_TASKMOD_BAD_INIT "Taskmod::getUuid(): Task object not initialized." +#define STRING_TASKMOD_TIME "time " +#define STRING_TASKMOD_OLD "old " +#define STRING_TASKMOD_NEW "new " + // text // A comma-separated list of commands is appended. #define STRING_TEXT_AMBIGUOUS "Ambiguous {1} '{2}' - could be either of " +// Uri +#define STRING_URI_QUOTES "Could not parse uri '{1}', wrong usage of single quotes." +#define STRING_URI_BAD_FORMAT "The uri '{1}' is not in the expected format." + // utf8 #define STRING_UTF8_INVALID_CP_REP "Invalid codepoint representation." #define STRING_UTF8_INVALID_CP "Invalid Unicode codepoint." diff --git a/src/text.cpp b/src/text.cpp index 6041a3fab..daf908018 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -890,6 +890,18 @@ const std::string format ( return output; } +//////////////////////////////////////////////////////////////////////////////// +const std::string format ( + const std::string& fmt, + int arg1, + double arg2) +{ + std::string output = fmt; + replace_positional (output, "{1}", format (arg1)); + replace_positional (output, "{2}", format (arg2, 6, 3)); + return output; +} + //////////////////////////////////////////////////////////////////////////////// const std::string format ( const std::string& fmt, diff --git a/src/text.h b/src/text.h index 556244856..073917fe6 100644 --- a/src/text.h +++ b/src/text.h @@ -78,6 +78,7 @@ const std::string format (const std::string&, const std::string&, const std::str const std::string format (const std::string&, const std::string&, int); const std::string format (const std::string&, int, const std::string&); const std::string format (const std::string&, int, int); +const std::string format (const std::string&, int, double); const std::string format (const std::string&, const std::string&, const std::string&, const std::string&); std::string leftJustify (const int, const int);