- Localized a few strings, for fun.
This commit is contained in:
Paul Beckingham 2011-05-25 01:13:19 -04:00
parent 62203a45f8
commit 02065c3cdc
8 changed files with 50 additions and 232 deletions

View file

@ -164,7 +164,7 @@ int Context::run ()
catch (...)
{
footnote ("Unknown error.");
footnote (STRING_UNKNOWN_ERROR);
rc = 3;
}
@ -369,6 +369,7 @@ bool Context::verbose (const std::string& token)
}
////////////////////////////////////////////////////////////////////////////////
// TODO OBSOLETE
void Context::shadow ()
{
// Determine if shadow file is enabled.
@ -536,7 +537,7 @@ void Context::assumeLocations ()
// Set up default locations.
struct passwd* pw = getpwuid (getuid ());
if (!pw)
throw std::string ("Could not read home directory from the passwd file.");
throw std::string (STRING_NO_HOME);
home_dir = pw->pw_dir;
rc_file = File (home_dir + "/.taskrc");
@ -722,7 +723,7 @@ void Context::parse (
foundNonSequence = true;
if (arg->find (',') != std::string::npos)
throw std::string ("Tags are not permitted to contain commas.");
throw std::string (STRING_TAGS_NO_COMMAS);
tagAdditions.push_back (arg->substr (1));
parseTask.addTag (arg->substr (1));
@ -740,7 +741,7 @@ void Context::parse (
foundNonSequence = true;
if (arg->find (',') != std::string::npos)
throw std::string ("Tags are not permitted to contain commas.");
throw std::string (STRING_TAGS_NO_COMMAS);
tagRemovals.push_back (arg->substr (1));
}
@ -900,7 +901,7 @@ void Context::parse (
parse (args, cmd, task, sequence, subst, filter);
}
else
throw std::string ("You must specify a command, or a task ID to modify.");
throw std::string (STRING_TRIVIAL_INPUT);
}
// If the command "task 123" is entered, but with no modifier arguments,
@ -908,7 +909,7 @@ void Context::parse (
else if (!foundNonSequence &&
(parseTask.id != 0 || parseSequence.size () != 0))
{
std::cout << "No command - assuming 'info'.\n";
std::cout << STRING_ASSUME_INFO << "\n";
parseCmd.command = "info";
}
}

View file

@ -28,6 +28,7 @@
#include <sstream>
#include <Context.h>
#include <text.h>
#include <i18n.h>
#include <DOM.h>
#include "../cmake.h"
@ -138,7 +139,7 @@ const std::string DOM::get (const std::string& name)
#elif defined (LINUX)
return "Linux";
#else
return "<unknown>";
return STRING_DOM_UNKNOWN
#endif
else

View file

@ -66,7 +66,8 @@ int CmdHelp::execute (const std::string& command_line, std::string& output)
// Sort alphabetically by usage.
std::sort (all.begin (), all.end ());
foreach (name, all)
std::vector <std::string>::iterator name;
for (name = all.begin (); name != all.end (); ++name)
{
row = view.addRow ();
view.set (row, 1, context.commands[*name]->usage ());

View file

@ -28,6 +28,7 @@
#include <vector>
#include <sstream>
#include <text.h>
#include <i18n.h>
#include <Context.h>
#include <Directory.h>
#include <ViewText.h>
@ -40,8 +41,7 @@ CmdShow::CmdShow ()
{
_keyword = "show";
_usage = "task show [all | substring]";
_description = "Shows the entire task configuration variables or the ones "
"containing substring.";
_description = STRING_CMD_SHOW;
_read_only = true;
_displays_id = false;
}
@ -58,7 +58,7 @@ int CmdShow::execute (const std::string& command_line, std::string& output)
split (args, context.task.get ("description"), ' ');
if (args.size () > 1)
throw std::string ("You can only specify 'all' or a search string.");
throw std::string (STRING_CMD_SHOW_ARGS);
int width = context.getWidth ();
@ -183,12 +183,13 @@ int CmdShow::execute (const std::string& command_line, std::string& output)
out << "\n"
<< view.render ()
<< (view.rows () == 0 ? "No matching configuration variables.\n\n" : "\n");
<< (view.rows () == 0 ? STRING_CMD_SHOW_NONE : "")
<< (view.rows () == 0 ? "\n\n" : "\n");
// Display the unrecognized variables.
if (unrecognized.size ())
{
out << "Your .taskrc file contains these unrecognized variables:\n";
out << STRING_CMD_SHOW_UNREC << "\n";
for (i = unrecognized.begin (); i != unrecognized.end (); ++i)
out << " " << *i << "\n";
@ -201,7 +202,7 @@ int CmdShow::execute (const std::string& command_line, std::string& output)
if (default_values.size ())
{
out << "Some of your .taskrc variables differ from the default values.";
out << STRING_CMD_SHOW_DIFFER;
if (context.color ())
out << " These are highlighted in " << warning.colorize ("color") << " above.";
@ -244,7 +245,7 @@ int CmdShow::execute (const std::string& command_line, std::string& output)
if (missing_scripts.size ())
{
out << "Your .taskrc file contains these missing or unreadable hook scripts:\n";
out << STRING_CMD_SHOW_HOOKS << "\n";
for (i = missing_scripts.begin (); i != missing_scripts.end (); ++i)
out << " " << *i << "\n";
@ -295,7 +296,7 @@ int CmdShow::execute (const std::string& command_line, std::string& output)
if (all.size () == 0)
{
out << "Configuration error: .taskrc contains no entries.\n";
out << STRING_CMD_SHOW_EMPTY << "\n";
rc = 1;
}
else

View file

@ -28,11 +28,16 @@
////////////////////////////////////////////////////////////////////////////////
//
// Strings that should be localized:
// - All text output that the user sees or types
// - text output that the user sees or types
//
// Strings that should NOT be localized:
// - ./taskrc configuration variable names
// - command names
// - extension function names
// - certain literals associated with parsing
// - debug strings
// - attribute names
// - modifier names
//
////////////////////////////////////////////////////////////////////////////////
@ -41,7 +46,26 @@
// To localize, clone and rename this file, then change all the defines below.
#define STRING_UNKNOWN_ERROR "Unknown error."
// Errors
#define STRING_UNKNOWN_ERROR "Unknown error."
#define STRING_NO_HOME "Could not read home directory from the passwd file."
#define STRING_TAGS_NO_COMMAS "Tags are not permitted to contain commas."
#define STRING_TRIVIAL_INPUT "You must specify a command, or a task ID to modify."
#define STRING_ASSUME_INFO "No command - assuming 'info'"
// 'show' command
#define STRING_CMD_SHOW "Shows the entire task configuration variables or the ones containing substring."
#define STRING_CMD_SHOW_ARGS "You can only specify 'all' or a search string."
#define STRING_CMD_SHOW_NONE "No matching configuration variables."
#define STRING_CMD_SHOW_UNREC "Your .taskrc file contains these unrecognized variables:"
#define STRING_CMD_SHOW_DIFFER "Some of your .taskrc variables differ from the default values."
#define STRING_CMD_SHOW_HOOKS "Your .taskrc file contains these missing or unreadable hook scripts:"
#define STRING_CMD_SHOW_EMPTY "Configuration error: .taskrc contains no entries."
// DOM
#define STRING_DOM_UNKNOWN "<unknown>"
#define STRING_DOM_UNREC "DOM: Cannot get unrecognized name '{1}'."
#define STRING_DOM_CANNOT_SET "DOM: Cannot set '{1}'."
#endif

View file

@ -5,8 +5,8 @@ include_directories (${CMAKE_SOURCE_DIR}/src
${CMAKE_SOURCE_DIR}/test
${TASK_INCLUDE_DIRS})
set (test_SRCS att.t autocomplete.t cmd.t color.t config.t date.t directory.t
dom.t duration.t file.t filt.t json.t list.t nibbler.t path.t
set (test_SRCS att.t autocomplete.t color.t config.t date.t directory.t dom.t
duration.t file.t filt.t json.t list.t nibbler.t path.t
record.t rx.t seq.t subst.t t.benchmark.t t.t taskmod.t tdb.t
tdb2.t text.t uri.t util.t variant.t view.t json_test)

View file

@ -1,210 +0,0 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
// All rights reserved.
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 2 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor,
// Boston, MA
// 02110-1301
// USA
//
////////////////////////////////////////////////////////////////////////////////
#include <Context.h>
#include <Cmd.h>
#include <test.h>
Context context;
////////////////////////////////////////////////////////////////////////////////
int main (int argc, char** argv)
{
UnitTest t (86);
// Without Context::initialize, there is no set of defaults loaded into
// Context::Config.
context.initialize ();
context.config.set ("report.foo.columns", "id");
Cmd cmd;
cmd.command = "active";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand active");
t.notok (cmd.isWriteCommand (), "not isWriteCommand active");
cmd.command = "calendar";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand calendar");
t.notok (cmd.isWriteCommand (), "not isWriteCommand calendar");
cmd.command = "colors";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand colors");
t.notok (cmd.isWriteCommand (), "not isWriteCommand colors");
cmd.command = "completed";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand completed");
t.notok (cmd.isWriteCommand (), "not isWriteCommand completed");
cmd.command = "export.csv";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand export.csv");
t.notok (cmd.isWriteCommand (), "not isWriteCommand export.csv");
cmd.command = "export.ical";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand export.ical");
t.notok (cmd.isWriteCommand (), "not isWriteCommand export.ical");
cmd.command = "help";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand help");
t.notok (cmd.isWriteCommand (), "not isWriteCommand help");
cmd.command = "history.monthly";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand history.monthly");
t.notok (cmd.isWriteCommand (), "not isWriteCommand history.monthly");
cmd.command = "history.annual";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand history.annual");
t.notok (cmd.isWriteCommand (), "not isWriteCommand history.annual");
cmd.command = "ghistory.monthly";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand ghistory.monthly");
t.notok (cmd.isWriteCommand (), "not isWriteCommand ghistory.monthly");
cmd.command = "ghistory.annual";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand ghistory.annual");
t.notok (cmd.isWriteCommand (), "not isWriteCommand ghistory.annual");
cmd.command = "info";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand info");
t.notok (cmd.isWriteCommand (), "not isWriteCommand info");
cmd.command = "next";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand next");
t.notok (cmd.isWriteCommand (), "not isWriteCommand next");
cmd.command = "overdue";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand overdue");
t.notok (cmd.isWriteCommand (), "not isWriteCommand overdue");
cmd.command = "projects";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand projects");
t.notok (cmd.isWriteCommand (), "not isWriteCommand projects");
cmd.command = "stats";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand stats");
t.notok (cmd.isWriteCommand (), "not isWriteCommand stats");
cmd.command = "summary";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand summary");
t.notok (cmd.isWriteCommand (), "not isWriteCommand summary");
cmd.command = "tags";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand tags");
t.notok (cmd.isWriteCommand (), "not isWriteCommand tags");
cmd.command = "timesheet";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand timesheet");
t.notok (cmd.isWriteCommand (), "not isWriteCommand timesheet");
cmd.command = "version";
t.ok (cmd.isReadOnlyCommand (), "isReadOnlyCommand version");
t.notok (cmd.isWriteCommand (), "not isWriteCommand version");
cmd.command = "_projects";
t.ok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand _projects");
t.notok (cmd.isWriteCommand (), "isWriteCommand _projects");
cmd.command = "_tags";
t.ok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand _tags");
t.notok (cmd.isWriteCommand (), "isWriteCommand _tags");
cmd.command = "add";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand add");
t.ok (cmd.isWriteCommand (), "isWriteCommand add");
cmd.command = "log";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand log");
t.ok (cmd.isWriteCommand (), "isWriteCommand log");
cmd.command = "append";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand append");
t.ok (cmd.isWriteCommand (), "isWriteCommand append");
cmd.command = "annotate";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand annotate");
t.ok (cmd.isWriteCommand (), "isWriteCommand annotate");
cmd.command = "delete";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand delete");
t.ok (cmd.isWriteCommand (), "isWriteCommand delete");
cmd.command = "done";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand done");
t.ok (cmd.isWriteCommand (), "isWriteCommand done");
cmd.command = "duplicate";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand duplicate");
t.ok (cmd.isWriteCommand (), "isWriteCommand duplicate");
cmd.command = "edit";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand edit");
t.ok (cmd.isWriteCommand (), "isWriteCommand edit");
cmd.command = "import";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand import");
t.ok (cmd.isWriteCommand (), "isWriteCommand import");
cmd.command = "start";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand start");
t.ok (cmd.isWriteCommand (), "isWriteCommand start");
cmd.command = "stop";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand stop");
t.ok (cmd.isWriteCommand (), "isWriteCommand stop");
cmd.command = "undo";
t.notok (cmd.isReadOnlyCommand (), "not isReadOnlyCommand undo");
t.ok (cmd.isWriteCommand (), "isWriteCommand undo");
t.ok (cmd.valid ("annotate"), "Cmd::valid annotate");
t.ok (cmd.valid ("annotat"), "Cmd::valid annotat");
t.ok (cmd.valid ("annota"), "Cmd::valid annota");
t.ok (cmd.valid ("annot"), "Cmd::valid annot");
t.ok (cmd.valid ("anno"), "Cmd::valid anno");
t.ok (cmd.valid ("ann"), "Cmd::valid ann");
t.ok (cmd.valid ("an"), "Cmd::valid an");
t.ok (cmd.valid ("ANNOTATE"), "Cmd::valid ANNOTATE");
t.ok (cmd.valid ("ANNOTAT"), "Cmd::valid ANNOTAT");
t.ok (cmd.valid ("ANNOTA"), "Cmd::valid ANNOTA");
t.ok (cmd.valid ("ANNOT"), "Cmd::valid ANNOT");
t.ok (cmd.valid ("ANNO"), "Cmd::valid ANNO");
t.ok (cmd.valid ("ANN"), "Cmd::valid ANN");
t.ok (cmd.valid ("AN"), "Cmd::valid AN");
t.ok (cmd.validCustom ("foo"), "Cmd::validCustom foo");
t.notok (cmd.validCustom ("bar"), "Cmd::validCustom bar -> fail");
bool good = true;
try { cmd.parse ("a"); } catch (...) { good = false; }
t.notok (good, "Cmd::parse a -> fail");
good = true;
try { cmd.parse ("add"); } catch (...) { good = false; }
t.ok (good, "Cmd::parse add");
return 0;
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -27,8 +27,8 @@
#include <iostream>
#include <unistd.h>
#include "main.h"
#include "test.h"
#include <main.h>
#include <test.h>
Context context;