From f43e47a739ac5e2681d0136d2bbc16bbec8e6c16 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 6 Jun 2009 14:11:18 -0400 Subject: [PATCH] I18N L10N - Sequence - Sequence object localized. - StringTable changed to inherit from std::map. - StringTable copy constructor, assignment operator removed. - Various source files tagged for further l10n work. --- i18n/strings.en-US | 7 ++ src/Config.cpp | 206 ++++++++++++++++++++++---------------------- src/Grid.cpp | 4 +- src/Sequence.cpp | 14 +-- src/StringTable.cpp | 39 +++------ src/StringTable.h | 7 +- src/Timer.cpp | 4 +- src/i18n.h | 8 ++ src/util.cpp | 78 +++++++++-------- 9 files changed, 185 insertions(+), 182 deletions(-) diff --git a/i18n/strings.en-US b/i18n/strings.en-US index ced94d6d9..ea3f19e4e 100644 --- a/i18n/strings.en-US +++ b/i18n/strings.en-US @@ -12,6 +12,13 @@ # 1xx task shell 100 Unknown Error. 101 Could not read home directory from the passwd file. +102 (y/n) +103 Invalid ID in sequence +104 Invalid ID in range +105 Inverted sequence range high-low +106 ID Range too large +107 Not a sequence. + # 2xx Commands 200 active diff --git a/src/Config.cpp b/src/Config.cpp index 6dcb4c8ba..4ef586fa0 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -45,32 +45,32 @@ // upgrade program to make the change, or c) this. Config::Config () { - (*this)["report.long.description"] = "Lists all task, all data, matching the specified criteria"; - (*this)["report.long.columns"] = "id,project,priority,entry,start,due,recur,age,tags,description"; - (*this)["report.long.labels"] = "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"; - (*this)["report.long.sort"] = "due+,priority-,project+"; + (*this)["report.long.description"] = "Lists all task, all data, matching the specified criteria"; // TODO i18n + (*this)["report.long.columns"] = "id,project,priority,entry,start,due,recur,age,tags,description"; // TODO i18n + (*this)["report.long.labels"] = "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"; // TODO i18n + (*this)["report.long.sort"] = "due+,priority-,project+"; // TODO i18n - (*this)["report.list.description"] = "Lists all tasks matching the specified criteria"; - (*this)["report.list.columns"] = "id,project,priority,due,active,age,description"; - (*this)["report.list.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; - (*this)["report.list.sort"] = "due+,priority-,project+"; + (*this)["report.list.description"] = "Lists all tasks matching the specified criteria"; // TODO i18n + (*this)["report.list.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n + (*this)["report.list.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n + (*this)["report.list.sort"] = "due+,priority-,project+"; // TODO i18n - (*this)["report.ls.description"] = "Minimal listing of all tasks matching the specified criteria"; - (*this)["report.ls.columns"] = "id,project,priority,description"; - (*this)["report.ls.labels"] = "ID,Project,Pri,Description"; - (*this)["report.ls.sort"] = "priority-,project+"; + (*this)["report.ls.description"] = "Minimal listing of all tasks matching the specified criteria"; // TODO i18n + (*this)["report.ls.columns"] = "id,project,priority,description"; // TODO i18n + (*this)["report.ls.labels"] = "ID,Project,Pri,Description"; // TODO i18n + (*this)["report.ls.sort"] = "priority-,project+"; // TODO i18n - (*this)["report.newest.description"] = "Shows the newest tasks"; - (*this)["report.newest.columns"] = "id,project,priority,due,active,age,description"; - (*this)["report.newest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; - (*this)["report.newest.sort"] = "id-"; - (*this)["report.newest.limit"] = "10"; + (*this)["report.newest.description"] = "Shows the newest tasks"; // TODO i18n + (*this)["report.newest.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n + (*this)["report.newest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n + (*this)["report.newest.sort"] = "id-"; // TODO i18n + (*this)["report.newest.limit"] = "10"; // no i18n - (*this)["report.oldest.description"] = "Shows the oldest tasks"; - (*this)["report.oldest.columns"] = "id,project,priority,due,active,age,description"; - (*this)["report.oldest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; - (*this)["report.oldest.sort"] = "id+"; - (*this)["report.oldest.limit"] = "10"; + (*this)["report.oldest.description"] = "Shows the oldest tasks"; // TODO i18n + (*this)["report.oldest.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n + (*this)["report.oldest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n + (*this)["report.oldest.sort"] = "id+"; // TODO i18n + (*this)["report.oldest.limit"] = "10"; // no i18n } //////////////////////////////////////////////////////////////////////////////// @@ -93,20 +93,20 @@ bool Config::load (const std::string& file) while (getline (in, line)) { // Remove comments. - std::string::size_type pound = line.find ("#"); + std::string::size_type pound = line.find ("#"); // no i18n if (pound != std::string::npos) line = line.substr (0, pound); - line = trim (line, " \t"); + line = trim (line, " \t"); // no i18n // Skip empty lines. if (line.length () > 0) { - std::string::size_type equal = line.find ("="); + std::string::size_type equal = line.find ("="); // no i18n if (equal != std::string::npos) { - std::string key = trim (line.substr (0, equal), " \t"); - std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); + std::string key = trim (line.substr (0, equal), " \t"); // no i18n + std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n (*this)[key] = value; } } @@ -128,95 +128,95 @@ void Config::createDefault (const std::string& home) terminatedHome = home.substr (0, home.length () - 1); // Determine default names of init file and task directory. - std::string rcFile = terminatedHome + "/.taskrc"; - std::string dataDir = terminatedHome + "/.task";; + std::string rcFile = terminatedHome + "/.taskrc"; // TODO i18n + std::string dataDir = terminatedHome + "/.task"; // TODO i18n // If rcFile is not found, offer to create one. if (-1 == access (rcFile.c_str (), F_OK)) { if (confirm ( - "A configuration file could not be found in " + "A configuration file could not be found in " // TODO i18n + rcFile - + "\n\n" - + "Would you like a sample .taskrc created, so task can proceed?")) + + "\n\n" // no i18n + + "Would you like a sample .taskrc created, so task can proceed?")) // TODO i18n { // Create a sample .taskrc file. FILE* out; if ((out = fopen (rcFile.c_str (), "w"))) { - fprintf (out, "data.location=%s\n", dataDir.c_str ()); - fprintf (out, "confirmation=yes\n"); - fprintf (out, "echo.command=yes\n"); - fprintf (out, "next=2\n"); - fprintf (out, "dateformat=m/d/Y\n"); - fprintf (out, "#monthsperline=2\n"); - fprintf (out, "#defaultwidth=80\n"); - fprintf (out, "curses=on\n"); - fprintf (out, "color=on\n"); - fprintf (out, "due=7\n"); - fprintf (out, "nag=You have higher priority tasks.\n"); - fprintf (out, "locking=on\n"); - fprintf (out, "#editor=vi\n"); - fprintf (out, "weekstart=Sunday\n"); - fprintf (out, "displayweeknumber=yes\n"); + fprintf (out, "data.location=%s\n", dataDir.c_str ()); // TODO i18n + fprintf (out, "confirmation=yes\n"); // TODO i18n + fprintf (out, "echo.command=yes\n"); // TODO i18n + fprintf (out, "next=2\n"); // TODO i18n + fprintf (out, "dateformat=m/d/Y\n"); // TODO i18n + fprintf (out, "#monthsperline=2\n"); // TODO i18n + fprintf (out, "#defaultwidth=80\n"); // TODO i18n + fprintf (out, "curses=on\n"); // TODO i18n + fprintf (out, "color=on\n"); // TODO i18n + fprintf (out, "due=7\n"); // TODO i18n + fprintf (out, "nag=You have higher priority tasks.\n"); // TODO i18n + fprintf (out, "locking=on\n"); // TODO i18n + fprintf (out, "#editor=vi\n"); // TODO i18n + fprintf (out, "weekstart=Sunday\n"); // TODO i18n + fprintf (out, "displayweeknumber=yes\n"); // TODO i18n - fprintf (out, "color.overdue=bold_red\n"); - fprintf (out, "color.due=bold_yellow\n"); - fprintf (out, "color.pri.H=bold\n"); - fprintf (out, "#color.pri.M=on_yellow\n"); - fprintf (out, "#color.pri.L=on_green\n"); - fprintf (out, "#color.pri.none=white on_blue\n"); - fprintf (out, "color.active=bold_cyan\n"); - fprintf (out, "color.tagged=yellow\n"); - fprintf (out, "#color.tag.bug=yellow\n"); - fprintf (out, "#color.project.garden=on_green\n"); - fprintf (out, "#color.keyword.car=on_blue\n"); - fprintf (out, "#color.recurring=on_red\n"); - fprintf (out, "#shadow.file=%s/shadow.txt\n", dataDir.c_str ()); - fprintf (out, "#shadow.command=list\n"); - fprintf (out, "#shadow.notify=on\n"); - fprintf (out, "#default.project=foo\n"); - fprintf (out, "#default.priority=M\n"); - fprintf (out, "default.command=list\n"); + fprintf (out, "color.overdue=bold_red\n"); // TODO i18n + fprintf (out, "color.due=bold_yellow\n"); // TODO i18n + fprintf (out, "color.pri.H=bold\n"); // TODO i18n + fprintf (out, "#color.pri.M=on_yellow\n"); // TODO i18n + fprintf (out, "#color.pri.L=on_green\n"); // TODO i18n + fprintf (out, "#color.pri.none=white on_blue\n"); // TODO i18n + fprintf (out, "color.active=bold_cyan\n"); // TODO i18n + fprintf (out, "color.tagged=yellow\n"); // TODO i18n + fprintf (out, "#color.tag.bug=yellow\n"); // TODO i18n + fprintf (out, "#color.project.garden=on_green\n"); // TODO i18n + fprintf (out, "#color.keyword.car=on_blue\n"); // TODO i18n + fprintf (out, "#color.recurring=on_red\n"); // TODO i18n + fprintf (out, "#shadow.file=%s/shadow.txt\n", dataDir.c_str ()); // TODO i18n + fprintf (out, "#shadow.command=list\n"); // TODO i18n + fprintf (out, "#shadow.notify=on\n"); // TODO i18n + fprintf (out, "#default.project=foo\n"); // TODO i18n + fprintf (out, "#default.priority=M\n"); // TODO i18n + fprintf (out, "default.command=list\n"); // TODO i18n // Custom reports. - fprintf (out, "# Fields: id,uuid,project,priority,entry,start,due,recur,age,active,tags,description\n"); - fprintf (out, "# description_only\n"); - fprintf (out, "# Description: This report is ...\n"); - fprintf (out, "# Sort: due+,priority-,project+\n"); - fprintf (out, "# Filter: pro:x pri:H +bug\n"); - fprintf (out, "# Limit: 10\n"); + fprintf (out, "# Fields: id,uuid,project,priority,entry,start,due,recur,age,active,tags,description\n"); // TODO i18n + fprintf (out, "# description_only\n"); // TODO i18n + fprintf (out, "# Description: This report is ...\n"); // TODO i18n + fprintf (out, "# Sort: due+,priority-,project+\n"); // TODO i18n + fprintf (out, "# Filter: pro:x pri:H +bug\n"); // TODO i18n + fprintf (out, "# Limit: 10\n"); // TODO i18n - fprintf (out, "report.long.description=Lists all task, all data, matching the specified criteria\n"); - fprintf (out, "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n"); - fprintf (out, "report.long.columns=id,project,priority,entry,start,due,recur,age,tags,description\n"); - fprintf (out, "report.long.sort=due+,priority-,project+\n"); + fprintf (out, "report.long.description=Lists all task, all data, matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.long.labels=ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description\n"); // TODO i18n + fprintf (out, "report.long.columns=id,project,priority,entry,start,due,recur,age,tags,description\n"); // TODO i18n + fprintf (out, "report.long.sort=due+,priority-,project+\n"); // TODO i18n - fprintf (out, "report.list.description=Lists all tasks matching the specified criteria\n"); - fprintf (out, "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n"); - fprintf (out, "report.list.columns=id,project,priority,due,active,age,description\n"); - fprintf (out, "report.list.sort=due+,priority-,project+\n"); + fprintf (out, "report.list.description=Lists all tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.list.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.list.sort=due+,priority-,project+\n"); // TODO i18n + // TODO i18n + fprintf (out, "report.ls.description=Minimal listing of all tasks matching the specified criteria\n"); // TODO i18n + fprintf (out, "report.ls.labels=ID,Project,Pri,Description\n"); // TODO i18n + fprintf (out, "report.ls.columns=id,project,priority,description\n"); // TODO i18n + fprintf (out, "report.ls.sort=priority-,project+\n"); // TODO i18n - fprintf (out, "report.ls.description=Minimal listing of all tasks matching the specified criteria\n"); - fprintf (out, "report.ls.labels=ID,Project,Pri,Description\n"); - fprintf (out, "report.ls.columns=id,project,priority,description\n"); - fprintf (out, "report.ls.sort=priority-,project+\n"); + fprintf (out, "report.newest.description=Shows the newest tasks\n"); // TODO i18n + fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.newest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.newest.sort=id-\n"); // TODO i18n + fprintf (out, "report.newest.limit=10\n"); // TODO i18n - fprintf (out, "report.newest.description=Shows the newest tasks\n"); - fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); - fprintf (out, "report.newest.columns=id,project,priority,due,active,age,description\n"); - fprintf (out, "report.newest.sort=id-\n"); - fprintf (out, "report.newest.limit=10\n"); - - fprintf (out, "report.oldest.description=Shows the oldest tasks\n"); - fprintf (out, "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); - fprintf (out, "report.oldest.columns=id,project,priority,due,active,age,description\n"); - fprintf (out, "report.oldest.sort=id+\n"); - fprintf (out, "report.oldest.limit=10\n"); + fprintf (out, "report.oldest.description=Shows the oldest tasks\n"); // TODO i18n + fprintf (out, "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n + fprintf (out, "report.oldest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n + fprintf (out, "report.oldest.sort=id+\n"); // TODO i18n + fprintf (out, "report.oldest.limit=10\n"); // TODO i18n fclose (out); - std::cout << "Done." << std::endl; + std::cout << "Done." << std::endl; // TODO i18n } } } @@ -225,7 +225,7 @@ void Config::createDefault (const std::string& home) // Get the data.location value from the (potentially newly created) .taskrc // file. - dataDir = this->get ("data.location", dataDir); + dataDir = this->get ("data.location", dataDir); // no i18n if (-1 == access (dataDir.c_str (), F_OK)) mkdir (dataDir.c_str (), S_IRWXU); } @@ -274,13 +274,13 @@ bool Config::get (const std::string& key, bool default_value) { std::string value = lowerCase ((*this)[key]); - if (value == "t" || - value == "true" || - value == "1" || - value == "yes" || - value == "on" || - value == "enable" || - value == "enabled") + if (value == "t" || // TODO i18n + value == "true" || // TODO i18n + value == "1" || // no i18n + value == "yes" || // TODO i18n + value == "on" || // TODO i18n + value == "enable" || // TODO i18n + value == "enabled") // TODO i18n return true; return false; diff --git a/src/Grid.cpp b/src/Grid.cpp index 59e366b32..f87113cf6 100644 --- a/src/Grid.cpp +++ b/src/Grid.cpp @@ -306,7 +306,7 @@ Grid::Cell::operator char () const { switch (mType) { - case CELL_BOOL: return mBool ? 'Y' : 'N'; + case CELL_BOOL: return mBool ? 'Y' : 'N'; // TODO i18n case CELL_CHAR: return mChar; case CELL_INT: return (char) mInt; case CELL_FLOAT: return (char) (int) mFloat; @@ -368,7 +368,7 @@ Grid::Cell::operator std::string () const switch (mType) { - case CELL_BOOL: return mBool ? "true" : "false"; + case CELL_BOOL: return mBool ? "true" : "false"; // TODO i18n case CELL_CHAR: sprintf (s, "%c", mChar); return std::string (s); case CELL_INT: sprintf (s, "%d", mInt); diff --git a/src/Sequence.cpp b/src/Sequence.cpp index 23c9836d4..83309657e 100644 --- a/src/Sequence.cpp +++ b/src/Sequence.cpp @@ -31,8 +31,12 @@ #include #include "util.h" #include "text.h" +#include "i18n.h" +#include "Context.h" #include "Sequence.h" +extern Context context; + //////////////////////////////////////////////////////////////////////////////// Sequence::Sequence () { @@ -66,7 +70,7 @@ void Sequence::parse (const std::string& input) case 1: { if (! validId (range[0])) - throw std::string ("Invalid ID in sequence"); + throw context.stringtable.get (SEQUENCE_BAD_SEQ, "Invalid ID in sequence"); int id = ::atoi (range[0].c_str ()); this->push_back (id); @@ -77,15 +81,15 @@ void Sequence::parse (const std::string& input) { if (! validId (range[0]) || ! validId (range[1])) - throw std::string ("Invalid ID in range"); + throw context.stringtable.get (SEQUENCE_BAD_SEQ, "Invalid ID in range"); int low = ::atoi (range[0].c_str ()); int high = ::atoi (range[1].c_str ()); if (low > high) - throw std::string ("Inverted sequence range high-low"); + throw context.stringtable.get (SEQUENCE_INVERTED, "Inverted sequence range high-low"); if (high - low >= SEQUENCE_MAX) - throw std::string ("ID Range too large"); + throw context.stringtable.get (SEQUENCE_RANGE_MAX, "ID Range too large"); for (int i = low; i <= high; ++i) this->push_back (i); @@ -93,7 +97,7 @@ void Sequence::parse (const std::string& input) break; default: - throw std::string ("Not a sequence."); + throw context.stringtable.get (SEQUENCE_NOT_A_SEQUENCE, "Not a sequence."); break; } } diff --git a/src/StringTable.cpp b/src/StringTable.cpp index 05c1489b6..bfc551ce0 100644 --- a/src/StringTable.cpp +++ b/src/StringTable.cpp @@ -37,25 +37,6 @@ StringTable::StringTable () { } -//////////////////////////////////////////////////////////////////////////////// -StringTable::StringTable (const StringTable& other) -{ - throw std::string ("unimplemented StringTable::StringTable"); - mMapping = other.mMapping; -} - -//////////////////////////////////////////////////////////////////////////////// -StringTable& StringTable::operator= (const StringTable& other) -{ - throw std::string ("unimplemented StringTable::operator="); - if (this != &other) - { - mMapping = other.mMapping; - } - - return *this; -} - //////////////////////////////////////////////////////////////////////////////// StringTable::~StringTable () { @@ -69,7 +50,7 @@ StringTable::~StringTable () // ... void StringTable::load (const std::string& file) { - mMapping.clear (); // Allows dynamic reload. + this->clear (); // Allows dynamic reload. std::ifstream in; in.open (file.c_str (), std::ifstream::in); @@ -79,21 +60,21 @@ void StringTable::load (const std::string& file) while (getline (in, line)) { // Remove comments. - std::string::size_type pound = line.find ("#"); + std::string::size_type pound = line.find ("#"); // no i18n if (pound != std::string::npos) line = line.substr (0, pound); - line = trim (line, " \t"); + line = trim (line, " \t"); // no i18n // Skip empty lines. if (line.length () > 0) { - std::string::size_type equal = line.find (" "); + std::string::size_type equal = line.find (" "); // no i18n if (equal != std::string::npos) { - int key = ::atoi (trim (line.substr (0, equal), " \t").c_str ()); - std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); - mMapping[key] = value; + int key = ::atoi (trim (line.substr (0, equal), " \t").c_str ()); // no i18n + std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n + (*this)[key] = value; } } } @@ -101,15 +82,15 @@ void StringTable::load (const std::string& file) in.close (); } else - throw std::string ("Could not read string file '") + file + "'"; + throw std::string ("Could not read string file '") + file + "'"; // TODO i18n } //////////////////////////////////////////////////////////////////////////////// std::string StringTable::get (int id, const std::string& alternate) { // Return the right string. - if (mMapping.find (id) != mMapping.end ()) - return mMapping[id]; + if (this->find (id) != this->end ()) + return (*this)[id]; return alternate; } diff --git a/src/StringTable.h b/src/StringTable.h index f5226c3f2..e07046665 100644 --- a/src/StringTable.h +++ b/src/StringTable.h @@ -30,19 +30,14 @@ #include #include -class StringTable +class StringTable : public std::map { public: StringTable (); // Default constructor - StringTable (const StringTable&); // Copy constructor - StringTable& operator= (const StringTable&); // Assignment operator ~StringTable (); // Destructor void load (const std::string&); std::string get (int, const std::string&); - -private: - std::map mMapping; }; #endif diff --git a/src/Timer.cpp b/src/Timer.cpp index cbd9f1dc7..e3ad40e88 100644 --- a/src/Timer.cpp +++ b/src/Timer.cpp @@ -37,13 +37,13 @@ Timer::Timer (const std::string& description) } //////////////////////////////////////////////////////////////////////////////// -// Timer stops when the object is desctructed. +// Timer stops when the object is destructed. Timer::~Timer () { struct timeval end; ::gettimeofday (&end, NULL); - std::cout << "Timer " + std::cout << "Timer " // No i18n << mDescription << " " << std::setprecision (6) diff --git a/src/i18n.h b/src/i18n.h index 76395c09d..06d1cd117 100644 --- a/src/i18n.h +++ b/src/i18n.h @@ -32,6 +32,14 @@ #define SHELL_UNKNOWN_ERROR 100 #define SHELL_READ_PASSWD 101 +#define CONFIRM_YES_NO 102 + +#define SEQUENCE_BAD_SEQ 103 +#define SEQUENCE_BAD_RANGE 104 +#define SEQUENCE_INVERTED 105 +#define SEQUENCE_RANGE_MAX 106 +#define SEQUENCE_NOT_A_SEQUENCE 107 + // 2xx Commands #define CMD_ACTIVE 200 #define CMD_ADD 201 diff --git a/src/util.cpp b/src/util.cpp index f839afdee..9e3e167c7 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -42,12 +42,15 @@ #include "TDB.h" #include "text.h" #include "task.h" +#include "i18n.h" #include "../auto.h" +extern Context context; + //////////////////////////////////////////////////////////////////////////////// // Uses std::getline, because std::cin eats leading whitespace, and that means // that if a newline is entered, std::cin eats it and never returns from the -// "std::cin >> answer;" line, but it does disply the newline. This way, with +// "std::cin >> answer;" line, but it does display the newline. This way, with // std::getline, the newline can be detected, and the prompt re-written. bool confirm (const std::string& question) { @@ -55,18 +58,22 @@ bool confirm (const std::string& question) do { - std::cout << question << " (y/n) "; + std::cout << question + << " " + << context.stringtable.get (CONFIRM_YES_NO, "(y/n)") + << " "; + std::getline (std::cin, answer); answer = lowerCase (trim (answer)); - if (answer == "\n") std::cout << "newline\n"; + if (answer == "\n") std::cout << "newline\n"; // TODO i18n } - while (answer != "y" && - answer != "ye" && - answer != "yes" && - answer != "n" && - answer != "no"); + while (answer != "y" && // TODO i18n + answer != "ye" && // TODO i18n + answer != "yes" && // TODO i18n + answer != "n" && // TODO i18n + answer != "no"); // TODO i18n - return (answer == "y" || answer == "ye" || answer == "yes") ? true : false; + return (answer == "y" || answer == "ye" || answer == "yes") ? true : false; // TODO i18n } //////////////////////////////////////////////////////////////////////////////// @@ -87,35 +94,35 @@ std::string formatSeconds (time_t delta) float days = (float) delta / 86400.0; if (days > 365) - sprintf (formatted, "%.1f yrs", (days / 365.2422)); + sprintf (formatted, "%.1f yrs", (days / 365.2422)); // TODO i18n else if (days > 84) - sprintf (formatted, "%1d mth%s", + sprintf (formatted, "%1d mth%s", // TODO i18n (int) (days / 30.6), - ((int) (days / 30.6) == 1 ? "" : "s")); + ((int) (days / 30.6) == 1 ? "" : "s")); // TODO i18n else if (days > 13) - sprintf (formatted, "%d wk%s", + sprintf (formatted, "%d wk%s", // TODO i18n (int) (days / 7.0), - ((int) (days / 7.0) == 1 ? "" : "s")); + ((int) (days / 7.0) == 1 ? "" : "s")); // TODO i18n else if (days > 5.0) - sprintf (formatted, "%d day%s", + sprintf (formatted, "%d day%s", // TODO i18n (int) days, - ((int) days == 1 ? "" : "s")); + ((int) days == 1 ? "" : "s")); // TODO i18n else if (days > 1.0) - sprintf (formatted, "%.1f days", days); + sprintf (formatted, "%.1f days", days); // TODO i18n else if (days * 24 > 1.0) - sprintf (formatted, "%d hr%s", + sprintf (formatted, "%d hr%s", // TODO i18n (int) (days * 24.0), - ((int) (days * 24) == 1 ? "" : "s")); + ((int) (days * 24) == 1 ? "" : "s")); // TODO i18n else if (days * 24 * 60 > 1) - sprintf (formatted, "%d min%s", + sprintf (formatted, "%d min%s", // TODO i18n (int) (days * 24 * 60), - ((int) (days * 24 * 60) == 1 ? "" : "s")); + ((int) (days * 24 * 60) == 1 ? "" : "s")); // TODO i18n else if (days * 24 * 60 * 60 > 1) - sprintf (formatted, "%d sec%s", + sprintf (formatted, "%d sec%s", // TODO i18n (int) (days * 24 * 60 * 60), - ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); + ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); // TODO i18n else - strcpy (formatted, "-"); + strcpy (formatted, "-"); // no i18n return std::string (formatted); } @@ -127,16 +134,16 @@ std::string formatSecondsCompact (time_t delta) char formatted[24]; float days = (float) delta / 86400.0; - if (days > 365) sprintf (formatted, "%.1fy", (days / 365.2422)); - else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); - else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); - else if (days > 5.0) sprintf (formatted, "%dd", (int) days); - else if (days > 1.0) sprintf (formatted, "%.1fd", days); - else if (days * 24 > 1.0) sprintf (formatted, "%dh", (int) (days * 24.0)); - else if (days * 24 * 60 > 1) sprintf (formatted, "%dm", (int) (days * 24 * 60)); - else if (days * 24 * 3600 > 1) sprintf (formatted, "%ds", (int) (days * 24 * 60 * 60)); + if (days > 365) sprintf (formatted, "%.1fy", (days / 365.2422)); // TODO i18n + else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); // TODO i18n + else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); // TODO i18n + else if (days > 5.0) sprintf (formatted, "%dd", (int) days); // TODO i18n + else if (days > 1.0) sprintf (formatted, "%.1fd", days); // TODO i18n + else if (days * 24 > 1.0) sprintf (formatted, "%dh", (int) (days * 24.0)); // TODO i18n + else if (days * 24 * 60 > 1) sprintf (formatted, "%dm", (int) (days * 24 * 60)); // TODO i18n + else if (days * 24 * 3600 > 1) sprintf (formatted, "%ds", (int) (days * 24 * 60 * 60)); // TODO i18n else - strcpy (formatted, "-"); + strcpy (formatted, "-"); // no i18n return std::string (formatted); } @@ -198,7 +205,7 @@ const std::string uuid () #include static char randomHexDigit () { - static char digits[] = "0123456789abcdef"; + static char digits[] = "0123456789abcdef"; // no i18n #ifdef HAVE_RANDOM // random is better than rand. return digits[random () % 16]; @@ -255,6 +262,7 @@ const std::string uuid () #endif //////////////////////////////////////////////////////////////////////////////// +// no i18n std::string expandPath (const std::string& in) { std::string copy = in; @@ -374,7 +382,7 @@ void spit (const std::string& file, const std::string& contents) out.close (); } else - throw std::string ("Could not write file '") + file + "'"; + throw std::string ("Could not write file '") + file + "'"; // TODO i18n } ////////////////////////////////////////////////////////////////////////////////