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.
This commit is contained in:
Paul Beckingham 2009-06-06 14:11:18 -04:00
parent 76aa3c535e
commit f43e47a739
9 changed files with 185 additions and 182 deletions

View file

@ -12,6 +12,13 @@
# 1xx task shell # 1xx task shell
100 Unknown Error. 100 Unknown Error.
101 Could not read home directory from the passwd file. 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 # 2xx Commands
200 active 200 active

View file

@ -45,32 +45,32 @@
// upgrade program to make the change, or c) this. // upgrade program to make the change, or c) this.
Config::Config () Config::Config ()
{ {
(*this)["report.long.description"] = "Lists all task, all data, matching the specified criteria"; (*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"; (*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"; (*this)["report.long.labels"] = "ID,Project,Pri,Added,Started,Due,Recur,Age,Tags,Description"; // TODO i18n
(*this)["report.long.sort"] = "due+,priority-,project+"; (*this)["report.long.sort"] = "due+,priority-,project+"; // TODO i18n
(*this)["report.list.description"] = "Lists all tasks matching the specified criteria"; (*this)["report.list.description"] = "Lists all tasks matching the specified criteria"; // TODO i18n
(*this)["report.list.columns"] = "id,project,priority,due,active,age,description"; (*this)["report.list.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n
(*this)["report.list.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; (*this)["report.list.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n
(*this)["report.list.sort"] = "due+,priority-,project+"; (*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.description"] = "Minimal listing of all tasks matching the specified criteria"; // TODO i18n
(*this)["report.ls.columns"] = "id,project,priority,description"; (*this)["report.ls.columns"] = "id,project,priority,description"; // TODO i18n
(*this)["report.ls.labels"] = "ID,Project,Pri,Description"; (*this)["report.ls.labels"] = "ID,Project,Pri,Description"; // TODO i18n
(*this)["report.ls.sort"] = "priority-,project+"; (*this)["report.ls.sort"] = "priority-,project+"; // TODO i18n
(*this)["report.newest.description"] = "Shows the newest tasks"; (*this)["report.newest.description"] = "Shows the newest tasks"; // TODO i18n
(*this)["report.newest.columns"] = "id,project,priority,due,active,age,description"; (*this)["report.newest.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n
(*this)["report.newest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; (*this)["report.newest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n
(*this)["report.newest.sort"] = "id-"; (*this)["report.newest.sort"] = "id-"; // TODO i18n
(*this)["report.newest.limit"] = "10"; (*this)["report.newest.limit"] = "10"; // no i18n
(*this)["report.oldest.description"] = "Shows the oldest tasks"; (*this)["report.oldest.description"] = "Shows the oldest tasks"; // TODO i18n
(*this)["report.oldest.columns"] = "id,project,priority,due,active,age,description"; (*this)["report.oldest.columns"] = "id,project,priority,due,active,age,description"; // TODO i18n
(*this)["report.oldest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; (*this)["report.oldest.labels"] = "ID,Project,Pri,Due,Active,Age,Description"; // TODO i18n
(*this)["report.oldest.sort"] = "id+"; (*this)["report.oldest.sort"] = "id+"; // TODO i18n
(*this)["report.oldest.limit"] = "10"; (*this)["report.oldest.limit"] = "10"; // no i18n
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -93,20 +93,20 @@ bool Config::load (const std::string& file)
while (getline (in, line)) while (getline (in, line))
{ {
// Remove comments. // Remove comments.
std::string::size_type pound = line.find ("#"); std::string::size_type pound = line.find ("#"); // no i18n
if (pound != std::string::npos) if (pound != std::string::npos)
line = line.substr (0, pound); line = line.substr (0, pound);
line = trim (line, " \t"); line = trim (line, " \t"); // no i18n
// Skip empty lines. // Skip empty lines.
if (line.length () > 0) 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) if (equal != std::string::npos)
{ {
std::string key = trim (line.substr (0, 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"); std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n
(*this)[key] = value; (*this)[key] = value;
} }
} }
@ -128,95 +128,95 @@ void Config::createDefault (const std::string& home)
terminatedHome = home.substr (0, home.length () - 1); terminatedHome = home.substr (0, home.length () - 1);
// Determine default names of init file and task directory. // Determine default names of init file and task directory.
std::string rcFile = terminatedHome + "/.taskrc"; std::string rcFile = terminatedHome + "/.taskrc"; // TODO i18n
std::string dataDir = terminatedHome + "/.task";; std::string dataDir = terminatedHome + "/.task"; // TODO i18n
// If rcFile is not found, offer to create one. // If rcFile is not found, offer to create one.
if (-1 == access (rcFile.c_str (), F_OK)) if (-1 == access (rcFile.c_str (), F_OK))
{ {
if (confirm ( if (confirm (
"A configuration file could not be found in " "A configuration file could not be found in " // TODO i18n
+ rcFile + rcFile
+ "\n\n" + "\n\n" // no i18n
+ "Would you like a sample .taskrc created, so task can proceed?")) + "Would you like a sample .taskrc created, so task can proceed?")) // TODO i18n
{ {
// Create a sample .taskrc file. // Create a sample .taskrc file.
FILE* out; FILE* out;
if ((out = fopen (rcFile.c_str (), "w"))) if ((out = fopen (rcFile.c_str (), "w")))
{ {
fprintf (out, "data.location=%s\n", dataDir.c_str ()); fprintf (out, "data.location=%s\n", dataDir.c_str ()); // TODO i18n
fprintf (out, "confirmation=yes\n"); fprintf (out, "confirmation=yes\n"); // TODO i18n
fprintf (out, "echo.command=yes\n"); fprintf (out, "echo.command=yes\n"); // TODO i18n
fprintf (out, "next=2\n"); fprintf (out, "next=2\n"); // TODO i18n
fprintf (out, "dateformat=m/d/Y\n"); fprintf (out, "dateformat=m/d/Y\n"); // TODO i18n
fprintf (out, "#monthsperline=2\n"); fprintf (out, "#monthsperline=2\n"); // TODO i18n
fprintf (out, "#defaultwidth=80\n"); fprintf (out, "#defaultwidth=80\n"); // TODO i18n
fprintf (out, "curses=on\n"); fprintf (out, "curses=on\n"); // TODO i18n
fprintf (out, "color=on\n"); fprintf (out, "color=on\n"); // TODO i18n
fprintf (out, "due=7\n"); fprintf (out, "due=7\n"); // TODO i18n
fprintf (out, "nag=You have higher priority tasks.\n"); fprintf (out, "nag=You have higher priority tasks.\n"); // TODO i18n
fprintf (out, "locking=on\n"); fprintf (out, "locking=on\n"); // TODO i18n
fprintf (out, "#editor=vi\n"); fprintf (out, "#editor=vi\n"); // TODO i18n
fprintf (out, "weekstart=Sunday\n"); fprintf (out, "weekstart=Sunday\n"); // TODO i18n
fprintf (out, "displayweeknumber=yes\n"); fprintf (out, "displayweeknumber=yes\n"); // TODO i18n
fprintf (out, "color.overdue=bold_red\n"); fprintf (out, "color.overdue=bold_red\n"); // TODO i18n
fprintf (out, "color.due=bold_yellow\n"); fprintf (out, "color.due=bold_yellow\n"); // TODO i18n
fprintf (out, "color.pri.H=bold\n"); fprintf (out, "color.pri.H=bold\n"); // TODO i18n
fprintf (out, "#color.pri.M=on_yellow\n"); fprintf (out, "#color.pri.M=on_yellow\n"); // TODO i18n
fprintf (out, "#color.pri.L=on_green\n"); fprintf (out, "#color.pri.L=on_green\n"); // TODO i18n
fprintf (out, "#color.pri.none=white on_blue\n"); fprintf (out, "#color.pri.none=white on_blue\n"); // TODO i18n
fprintf (out, "color.active=bold_cyan\n"); fprintf (out, "color.active=bold_cyan\n"); // TODO i18n
fprintf (out, "color.tagged=yellow\n"); fprintf (out, "color.tagged=yellow\n"); // TODO i18n
fprintf (out, "#color.tag.bug=yellow\n"); fprintf (out, "#color.tag.bug=yellow\n"); // TODO i18n
fprintf (out, "#color.project.garden=on_green\n"); fprintf (out, "#color.project.garden=on_green\n"); // TODO i18n
fprintf (out, "#color.keyword.car=on_blue\n"); fprintf (out, "#color.keyword.car=on_blue\n"); // TODO i18n
fprintf (out, "#color.recurring=on_red\n"); fprintf (out, "#color.recurring=on_red\n"); // TODO i18n
fprintf (out, "#shadow.file=%s/shadow.txt\n", dataDir.c_str ()); fprintf (out, "#shadow.file=%s/shadow.txt\n", dataDir.c_str ()); // TODO i18n
fprintf (out, "#shadow.command=list\n"); fprintf (out, "#shadow.command=list\n"); // TODO i18n
fprintf (out, "#shadow.notify=on\n"); fprintf (out, "#shadow.notify=on\n"); // TODO i18n
fprintf (out, "#default.project=foo\n"); fprintf (out, "#default.project=foo\n"); // TODO i18n
fprintf (out, "#default.priority=M\n"); fprintf (out, "#default.priority=M\n"); // TODO i18n
fprintf (out, "default.command=list\n"); fprintf (out, "default.command=list\n"); // TODO i18n
// Custom reports. // Custom reports.
fprintf (out, "# Fields: id,uuid,project,priority,entry,start,due,recur,age,active,tags,description\n"); fprintf (out, "# Fields: id,uuid,project,priority,entry,start,due,recur,age,active,tags,description\n"); // TODO i18n
fprintf (out, "# description_only\n"); fprintf (out, "# description_only\n"); // TODO i18n
fprintf (out, "# Description: This report is ...\n"); fprintf (out, "# Description: This report is ...\n"); // TODO i18n
fprintf (out, "# Sort: due+,priority-,project+\n"); fprintf (out, "# Sort: due+,priority-,project+\n"); // TODO i18n
fprintf (out, "# Filter: pro:x pri:H +bug\n"); fprintf (out, "# Filter: pro:x pri:H +bug\n"); // TODO i18n
fprintf (out, "# Limit: 10\n"); 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.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"); 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"); 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"); 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.description=Lists all tasks matching the specified criteria\n"); // TODO i18n
fprintf (out, "report.list.labels=ID,Project,Pri,Due,Active,Age,Description\n"); 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"); fprintf (out, "report.list.columns=id,project,priority,due,active,age,description\n"); // TODO i18n
fprintf (out, "report.list.sort=due+,priority-,project+\n"); 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.newest.description=Shows the newest tasks\n"); // TODO i18n
fprintf (out, "report.ls.labels=ID,Project,Pri,Description\n"); fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n
fprintf (out, "report.ls.columns=id,project,priority,description\n"); fprintf (out, "report.newest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n
fprintf (out, "report.ls.sort=priority-,project+\n"); 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.oldest.description=Shows the oldest tasks\n"); // TODO i18n
fprintf (out, "report.newest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); fprintf (out, "report.oldest.labels=ID,Project,Pri,Due,Active,Age,Description\n"); // TODO i18n
fprintf (out, "report.newest.columns=id,project,priority,due,active,age,description\n"); fprintf (out, "report.oldest.columns=id,project,priority,due,active,age,description\n"); // TODO i18n
fprintf (out, "report.newest.sort=id-\n"); fprintf (out, "report.oldest.sort=id+\n"); // TODO i18n
fprintf (out, "report.newest.limit=10\n"); fprintf (out, "report.oldest.limit=10\n"); // TODO i18n
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");
fclose (out); 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 // Get the data.location value from the (potentially newly created) .taskrc
// file. // file.
dataDir = this->get ("data.location", dataDir); dataDir = this->get ("data.location", dataDir); // no i18n
if (-1 == access (dataDir.c_str (), F_OK)) if (-1 == access (dataDir.c_str (), F_OK))
mkdir (dataDir.c_str (), S_IRWXU); 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]); std::string value = lowerCase ((*this)[key]);
if (value == "t" || if (value == "t" || // TODO i18n
value == "true" || value == "true" || // TODO i18n
value == "1" || value == "1" || // no i18n
value == "yes" || value == "yes" || // TODO i18n
value == "on" || value == "on" || // TODO i18n
value == "enable" || value == "enable" || // TODO i18n
value == "enabled") value == "enabled") // TODO i18n
return true; return true;
return false; return false;

View file

@ -306,7 +306,7 @@ Grid::Cell::operator char () const
{ {
switch (mType) 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_CHAR: return mChar;
case CELL_INT: return (char) mInt; case CELL_INT: return (char) mInt;
case CELL_FLOAT: return (char) (int) mFloat; case CELL_FLOAT: return (char) (int) mFloat;
@ -368,7 +368,7 @@ Grid::Cell::operator std::string () const
switch (mType) 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); case CELL_CHAR: sprintf (s, "%c", mChar);
return std::string (s); return std::string (s);
case CELL_INT: sprintf (s, "%d", mInt); case CELL_INT: sprintf (s, "%d", mInt);

View file

@ -31,8 +31,12 @@
#include <ctype.h> #include <ctype.h>
#include "util.h" #include "util.h"
#include "text.h" #include "text.h"
#include "i18n.h"
#include "Context.h"
#include "Sequence.h" #include "Sequence.h"
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
Sequence::Sequence () Sequence::Sequence ()
{ {
@ -66,7 +70,7 @@ void Sequence::parse (const std::string& input)
case 1: case 1:
{ {
if (! validId (range[0])) 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 ()); int id = ::atoi (range[0].c_str ());
this->push_back (id); this->push_back (id);
@ -77,15 +81,15 @@ void Sequence::parse (const std::string& input)
{ {
if (! validId (range[0]) || if (! validId (range[0]) ||
! validId (range[1])) ! 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 low = ::atoi (range[0].c_str ());
int high = ::atoi (range[1].c_str ()); int high = ::atoi (range[1].c_str ());
if (low > high) 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) 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) for (int i = low; i <= high; ++i)
this->push_back (i); this->push_back (i);
@ -93,7 +97,7 @@ void Sequence::parse (const std::string& input)
break; break;
default: default:
throw std::string ("Not a sequence."); throw context.stringtable.get (SEQUENCE_NOT_A_SEQUENCE, "Not a sequence.");
break; break;
} }
} }

View file

@ -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 () StringTable::~StringTable ()
{ {
@ -69,7 +50,7 @@ StringTable::~StringTable ()
// ... // ...
void StringTable::load (const std::string& file) void StringTable::load (const std::string& file)
{ {
mMapping.clear (); // Allows dynamic reload. this->clear (); // Allows dynamic reload.
std::ifstream in; std::ifstream in;
in.open (file.c_str (), 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)) while (getline (in, line))
{ {
// Remove comments. // Remove comments.
std::string::size_type pound = line.find ("#"); std::string::size_type pound = line.find ("#"); // no i18n
if (pound != std::string::npos) if (pound != std::string::npos)
line = line.substr (0, pound); line = line.substr (0, pound);
line = trim (line, " \t"); line = trim (line, " \t"); // no i18n
// Skip empty lines. // Skip empty lines.
if (line.length () > 0) 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) if (equal != std::string::npos)
{ {
int key = ::atoi (trim (line.substr (0, equal), " \t").c_str ()); 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"); std::string value = trim (line.substr (equal+1, line.length () - equal), " \t"); // no i18n
mMapping[key] = value; (*this)[key] = value;
} }
} }
} }
@ -101,15 +82,15 @@ void StringTable::load (const std::string& file)
in.close (); in.close ();
} }
else 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) std::string StringTable::get (int id, const std::string& alternate)
{ {
// Return the right string. // Return the right string.
if (mMapping.find (id) != mMapping.end ()) if (this->find (id) != this->end ())
return mMapping[id]; return (*this)[id];
return alternate; return alternate;
} }

View file

@ -30,19 +30,14 @@
#include <map> #include <map>
#include <string> #include <string>
class StringTable class StringTable : public std::map <int, std::string>
{ {
public: public:
StringTable (); // Default constructor StringTable (); // Default constructor
StringTable (const StringTable&); // Copy constructor
StringTable& operator= (const StringTable&); // Assignment operator
~StringTable (); // Destructor ~StringTable (); // Destructor
void load (const std::string&); void load (const std::string&);
std::string get (int, const std::string&); std::string get (int, const std::string&);
private:
std::map <int, std::string> mMapping;
}; };
#endif #endif

View file

@ -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 () Timer::~Timer ()
{ {
struct timeval end; struct timeval end;
::gettimeofday (&end, NULL); ::gettimeofday (&end, NULL);
std::cout << "Timer " std::cout << "Timer " // No i18n
<< mDescription << mDescription
<< " " << " "
<< std::setprecision (6) << std::setprecision (6)

View file

@ -32,6 +32,14 @@
#define SHELL_UNKNOWN_ERROR 100 #define SHELL_UNKNOWN_ERROR 100
#define SHELL_READ_PASSWD 101 #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 // 2xx Commands
#define CMD_ACTIVE 200 #define CMD_ACTIVE 200
#define CMD_ADD 201 #define CMD_ADD 201

View file

@ -42,12 +42,15 @@
#include "TDB.h" #include "TDB.h"
#include "text.h" #include "text.h"
#include "task.h" #include "task.h"
#include "i18n.h"
#include "../auto.h" #include "../auto.h"
extern Context context;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Uses std::getline, because std::cin eats leading whitespace, and that means // 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 // 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. // std::getline, the newline can be detected, and the prompt re-written.
bool confirm (const std::string& question) bool confirm (const std::string& question)
{ {
@ -55,18 +58,22 @@ bool confirm (const std::string& question)
do do
{ {
std::cout << question << " (y/n) "; std::cout << question
<< " "
<< context.stringtable.get (CONFIRM_YES_NO, "(y/n)")
<< " ";
std::getline (std::cin, answer); std::getline (std::cin, answer);
answer = lowerCase (trim (answer)); answer = lowerCase (trim (answer));
if (answer == "\n") std::cout << "newline\n"; if (answer == "\n") std::cout << "newline\n"; // TODO i18n
} }
while (answer != "y" && while (answer != "y" && // TODO i18n
answer != "ye" && answer != "ye" && // TODO i18n
answer != "yes" && answer != "yes" && // TODO i18n
answer != "n" && answer != "n" && // TODO i18n
answer != "no"); 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; float days = (float) delta / 86400.0;
if (days > 365) if (days > 365)
sprintf (formatted, "%.1f yrs", (days / 365.2422)); sprintf (formatted, "%.1f yrs", (days / 365.2422)); // TODO i18n
else if (days > 84) else if (days > 84)
sprintf (formatted, "%1d mth%s", sprintf (formatted, "%1d mth%s", // TODO i18n
(int) (days / 30.6), (int) (days / 30.6),
((int) (days / 30.6) == 1 ? "" : "s")); ((int) (days / 30.6) == 1 ? "" : "s")); // TODO i18n
else if (days > 13) else if (days > 13)
sprintf (formatted, "%d wk%s", sprintf (formatted, "%d wk%s", // TODO i18n
(int) (days / 7.0), (int) (days / 7.0),
((int) (days / 7.0) == 1 ? "" : "s")); ((int) (days / 7.0) == 1 ? "" : "s")); // TODO i18n
else if (days > 5.0) else if (days > 5.0)
sprintf (formatted, "%d day%s", sprintf (formatted, "%d day%s", // TODO i18n
(int) days, (int) days,
((int) days == 1 ? "" : "s")); ((int) days == 1 ? "" : "s")); // TODO i18n
else if (days > 1.0) else if (days > 1.0)
sprintf (formatted, "%.1f days", days); sprintf (formatted, "%.1f days", days); // TODO i18n
else if (days * 24 > 1.0) 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.0),
((int) (days * 24) == 1 ? "" : "s")); ((int) (days * 24) == 1 ? "" : "s")); // TODO i18n
else if (days * 24 * 60 > 1) 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),
((int) (days * 24 * 60) == 1 ? "" : "s")); ((int) (days * 24 * 60) == 1 ? "" : "s")); // TODO i18n
else if (days * 24 * 60 * 60 > 1) 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),
((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); ((int) (days * 24 * 60 * 60) == 1 ? "" : "s")); // TODO i18n
else else
strcpy (formatted, "-"); strcpy (formatted, "-"); // no i18n
return std::string (formatted); return std::string (formatted);
} }
@ -127,16 +134,16 @@ std::string formatSecondsCompact (time_t delta)
char formatted[24]; char formatted[24];
float days = (float) delta / 86400.0; float days = (float) delta / 86400.0;
if (days > 365) sprintf (formatted, "%.1fy", (days / 365.2422)); if (days > 365) sprintf (formatted, "%.1fy", (days / 365.2422)); // TODO i18n
else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); else if (days > 84) sprintf (formatted, "%1dmo", (int) (days / 30.6)); // TODO i18n
else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); else if (days > 13) sprintf (formatted, "%dwk", (int) (days / 7.0)); // TODO i18n
else if (days > 5.0) sprintf (formatted, "%dd", (int) days); else if (days > 5.0) sprintf (formatted, "%dd", (int) days); // TODO i18n
else if (days > 1.0) sprintf (formatted, "%.1fd", days); else if (days > 1.0) sprintf (formatted, "%.1fd", days); // TODO i18n
else if (days * 24 > 1.0) sprintf (formatted, "%dh", (int) (days * 24.0)); 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)); 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)); else if (days * 24 * 3600 > 1) sprintf (formatted, "%ds", (int) (days * 24 * 60 * 60)); // TODO i18n
else else
strcpy (formatted, "-"); strcpy (formatted, "-"); // no i18n
return std::string (formatted); return std::string (formatted);
} }
@ -198,7 +205,7 @@ const std::string uuid ()
#include <stdlib.h> #include <stdlib.h>
static char randomHexDigit () static char randomHexDigit ()
{ {
static char digits[] = "0123456789abcdef"; static char digits[] = "0123456789abcdef"; // no i18n
#ifdef HAVE_RANDOM #ifdef HAVE_RANDOM
// random is better than rand. // random is better than rand.
return digits[random () % 16]; return digits[random () % 16];
@ -255,6 +262,7 @@ const std::string uuid ()
#endif #endif
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// no i18n
std::string expandPath (const std::string& in) std::string expandPath (const std::string& in)
{ {
std::string copy = in; std::string copy = in;
@ -374,7 +382,7 @@ void spit (const std::string& file, const std::string& contents)
out.close (); out.close ();
} }
else else
throw std::string ("Could not write file '") + file + "'"; throw std::string ("Could not write file '") + file + "'"; // TODO i18n
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////