Skip to content

Commit

Permalink
Prepare i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
thjaeger committed Dec 30, 2008
1 parent 26af02a commit 11faa9d
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ desktop.c
dbus-server.h
debug.mk
*.gz
po/de
po/POTFILES.in
38 changes: 34 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ PREFIX = /usr/local
BINDIR = $(PREFIX)/bin
ICONDIR = $(PREFIX)/share/icons/hicolor/scalable/apps
MENUDIR = $(PREFIX)/share/applications
LOCALEDIR= $(PREFIX)/share/locale
DFLAGS =
OFLAGS = -Os
AOFLAGS = -O3
CXXFLAGS = -Wall $(DFLAGS) `pkg-config gtkmm-2.4 dbus-glib-1 --cflags`
CXXFLAGS = -Wall $(DFLAGS) -DLOCALEDIR=\"$(LOCALEDIR)\" `pkg-config gtkmm-2.4 dbus-glib-1 --cflags`
LDFLAGS = $(DFLAGS)

LIBS = $(DFLAGS) -lboost_serialization -lXtst `pkg-config gtkmm-2.4 dbus-glib-1 --libs`
Expand All @@ -31,9 +32,13 @@ MENU = easystroke.desktop
MANPAGE = easystroke.1

CCFILES = $(wildcard *.cc)
HFILES = $(wildcard *.h)
OFILES = $(patsubst %.cc,%.o,$(CCFILES)) gui.o desktop.o version.o
POFILES = $(wildcard po/*.po)
MOFILES = $(patsubst po/%.po,po/%/LC_MESSAGES/easystroke.mo,$(POFILES))
MODIRS = $(patsubst po/%.po,po/%,$(POFILES))
DEPFILES = $(wildcard *.Po)
GENFILES = gui.c desktop.c dbus-server.h
GENFILES = gui.c desktop.c dbus-server.h po/POTFILES.in
GZFILES = $(wildcard *.gz)

VERSION = $(shell test -e debian/changelog && grep '(.*)' debian/changelog | sed 's/.*(//' | sed 's/).*//' | head -n1 || (test -e version && cat version || git describe))
Expand All @@ -43,12 +48,13 @@ ARCH = $(shell uname -m)

-include debug.mk

all: $(BINARY)
all: $(BINARY) $(MOFILES)

.PHONY: all clean snapshot release
.PHONY: all clean snapshot release translate

clean:
$(RM) $(OFILES) $(BINARY) $(GENFILES) $(DEPFILES) $(MANPAGE) $(GZFILES)
$(RM) -r $(MODIRS)

include $(DEPFILES)

Expand Down Expand Up @@ -79,6 +85,24 @@ dbus-server.cc: dbus-server.h
dbus-server.h: dbus.xml
dbus-binding-tool --prefix=server --mode=glib-server --output=$@ $<

po/POTFILES.in: $(CCFILES) $(HFILES)
$(RM) $@
for f in `grep -El "\<_\(" $(CCFILES) $(HFILES)`; do echo $$f >> $@; done
echo gui.glade >> $@
# echo easystroke.desktop >> $@

translate: po/POTFILES.in
cd po && intltool-update --pot --gettext-package=easystroke

update-translations: po/POTFILES.in
cd po && for f in $(POFILES); do \
intltool-update `echo $$f | sed "s|po/\(.*\)\.po$$|\1|"`; \
done

po/%/LC_MESSAGES/easystroke.mo: po/%.po
mkdir -p po/$*/LC_MESSAGES
msgfmt -c $< -o $@

man: $(MANPAGE)

$(MANPAGE): $(BINARY)
Expand All @@ -88,11 +112,17 @@ install: all
install -Ds $(BINARY) $(DESTDIR)$(BINDIR)/$(BINARY)
install -D -m 644 $(ICON) $(DESTDIR)$(ICONDIR)/$(ICON)
install -D -m 644 $(MENU) $(DESTDIR)$(MENUDIR)/$(MENU)
for f in $(MOFILES); do \
install -D -m 644 $$f `echo $$f | sed "s|^po/|$(DESTDIR)$(LOCALEDIR)/|"`; \
done

uninstall:
$(RM) $(DESTDIR)$(BINDIR)/$(BINARY)
$(RM) $(DESTDIR)$(ICONDIR)/$(ICON)
$(RM) $(DESTDIR)$(MENUDIR)/$(MENU)
for f in $(MOFILES); do \
$(RM) `echo $$f | sed "s|^po/|$(DESTDIR)$(LOCALEDIR)/|"`; \
done

snapshot: $(DIST)_$(ARCH).tar.gz

Expand Down
21 changes: 12 additions & 9 deletions actiondb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "actiondb.h"
#include "main.h"
#include "win.h"
#include <glibmm/i18n.h>

#include <iostream>
#include <fstream>
Expand Down Expand Up @@ -115,7 +116,7 @@ void Command::run() {
execlp("/bin/sh", "sh", "-c", cmd.c_str(), NULL);
exit(1);
case -1:
printf("Error: can't execute command %s: fork failed\n", cmd.c_str());
printf(_("Error: can't execute command \"%s\": fork() failed\n"), cmd.c_str());
}
}

Expand Down Expand Up @@ -165,7 +166,7 @@ template<class Archive> void ActionDB::load(Archive & ar, const unsigned int ver

root.fix_tree(version == 2);
root.add_apps(apps);
root.name = "Default";
root.name = _("Default");
}

template<class Archive> void ActionDB::save(Archive & ar, const unsigned int version) const {
Expand All @@ -189,7 +190,7 @@ void ActionDBWatcher::init() {
printf("Loaded actions.\n");
}
} catch (exception &e) {
printf("Error: Couldn't read action database: %s.\n", e.what());
printf(_("Error: Couldn't read action database: %s.\n"), e.what());
}
watch(action_dummy);
}
Expand All @@ -202,15 +203,17 @@ void ActionDBWatcher::timeout() {
boost::archive::text_oarchive oa(ofs);
oa << (const ActionDB &)actions;
if (rename(tmp.c_str(), filename.c_str()))
throw std::runtime_error("rename() failed");
throw std::runtime_error(_("rename() failed"));
if (verbosity >= 2)
printf("Saved actions.\n");
} catch (exception &e) {
printf("Error: Couldn't save action database: %s.\n", e.what());
printf(_("Error: Couldn't save action database: %s.\n"), e.what());
if (!good_state)
return;
good_state = false;
new ErrorDialog("Couldn't save actions. Your changes will be lost. \nMake sure that "+config_dir+" is a directory and that you have write access to it.\nYou can change the configuration directory using the -c or --config-dir command line options.");
new ErrorDialog(
_("Couldn't save actions. Your changes will be lost. \nMake sure that ")+config_dir+
_(" is a directory and that you have write access to it.\nYou can change the configuration directory using the -c or --config-dir command line options."));
}
}

Expand Down Expand Up @@ -310,14 +313,14 @@ RAction ActionListDiff::handle(RStroke s, Ranking &r) const {
}
if (!r.action && s->trivial()) {
r.action = RAction(new Click);
r.name = "click (default)";
r.name = _("click (default)");
}
if (r.action) {
if (verbosity >= 1)
cout << "Excecuting Action " << r.name << "..." << endl;
printf("Executing Action %s\n", r.name.c_str());
} else {
if (verbosity >= 1)
cout << "Couldn't find matching stroke." << endl;
printf(_("Couldn't find matching stroke.\n"));
}
return r.action;
}
Expand Down
89 changes: 47 additions & 42 deletions actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
#include "win.h"
#include "main.h"
#include "prefdb.h"
#include <glibmm/i18n.h>

#include <iostream>
#include <sstream>
#include <typeinfo>

class CellEditableAccel : public Gtk::EventBox, public Gtk::CellEditable {
Expand All @@ -31,7 +30,7 @@ class CellEditableAccel : public Gtk::EventBox, public Gtk::CellEditable {
Glib::ObjectBase(typeid(CellEditableAccel)),
parent(parent_), path(path_)
{
WIDGET(Gtk::Label, label, "Key combination...");
WIDGET(Gtk::Label, label, _("Key combination..."));
label.set_alignment(0.0, 0.5);
add(label);
modify_bg(Gtk::STATE_NORMAL, widget.get_style()->get_bg(Gtk::STATE_SELECTED));
Expand Down Expand Up @@ -105,39 +104,39 @@ Gtk::CellEditable* CellRendererTextish::start_editing_vfunc(GdkEvent *event, Gtk
return 0;
}

const char *KEY = "Key";
const char *COMMAND = "Command";
const char *SCROLL = "Scroll";
const char *IGNORE = "Ignore";
const char *BUTTON = "Button";
const char *MISC = "Misc";
char *KEY = 0;
char *COMMAND = 0;
char *SCROLL = 0;
char *IGNORE = 0;
char *BUTTON = 0;
char *MISC = 0;

struct NameType {
const char *name;
char **name;
const std::type_info *type;
};

NameType name_type[7] = {
{ COMMAND, &typeid(Command) },
{ KEY, &typeid(SendKey) },
{ SCROLL, &typeid(Scroll) },
{ IGNORE, &typeid(Ignore) },
{ BUTTON, &typeid(Button) },
{ MISC, &typeid(Misc) },
{ 0, 0 }
{ &COMMAND, &typeid(Command) },
{ &KEY, &typeid(SendKey) },
{ &SCROLL, &typeid(Scroll) },
{ &IGNORE, &typeid(Ignore) },
{ &BUTTON, &typeid(Button) },
{ &MISC, &typeid(Misc) },
{ 0, 0 }
};

const std::type_info *name_to_type(Glib::ustring name) {
for (NameType *i = name_type; i->name; i++)
if (i->name == name)
if (*i->name == name)
return i->type;
return 0;
}

const char *type_to_name(const std::type_info *type) {
for (NameType *i = name_type; i->name; i++)
if (i->type == type)
return i->name;
return *i->name;
return "";
}

Expand All @@ -148,6 +147,13 @@ Actions::Actions() :
editing(false),
action_list(actions.get_root())
{
KEY = _("Key");
COMMAND = _("Command");
SCROLL = _("Scroll");
IGNORE = _("Ignore");
BUTTON = _("Button");
MISC = _("Misc");

widgets->get_widget("treeview_actions", tv);
widgets->get_widget("treeview_apps", apps_view);

Expand Down Expand Up @@ -179,13 +185,13 @@ Actions::Actions() :
tv->set_row_separator_func(sigc::mem_fun(*this, &Actions::on_row_separator));

int n;
n = tv->append_column("Stroke", cols.stroke);
n = tv->append_column(_("Stroke"), cols.stroke);
tv->get_column(n-1)->set_sort_column(cols.id);
tm->set_sort_func(cols.id, sigc::mem_fun(*this, &Actions::compare_ids));
tm->set_default_sort_func(sigc::mem_fun(*this, &Actions::compare_ids));
tm->set_sort_column(Gtk::TreeSortable::DEFAULT_SORT_COLUMN_ID, Gtk::SORT_ASCENDING);

n = tv->append_column("Name", cols.name);
n = tv->append_column(_("Name"), cols.name);
Gtk::CellRendererText *name_renderer = dynamic_cast<Gtk::CellRendererText *>(tv->get_column_cell_renderer(n-1));
name_renderer->property_editable() = true;
name_renderer->signal_edited().connect(sigc::mem_fun(*this, &Actions::on_name_edited));
Expand All @@ -198,7 +204,7 @@ Actions::Actions() :

type_store = Gtk::ListStore::create(type);
for (NameType *i = name_type; i->name; i++)
(*(type_store->append()))[type.type] = i->name;
(*(type_store->append()))[type.type] = *i->name;

Gtk::CellRendererCombo *type_renderer = Gtk::manage(new Gtk::CellRendererCombo);
type_renderer->property_model() = type_store;
Expand All @@ -209,13 +215,13 @@ Actions::Actions() :
type_renderer->signal_editing_started().connect(sigc::mem_fun(*this, &Actions::on_something_editing_started));
type_renderer->signal_editing_canceled().connect(sigc::mem_fun(*this, &Actions::on_something_editing_canceled));

n = tv->append_column("Type", *type_renderer);
n = tv->append_column(_("Type"), *type_renderer);
Gtk::TreeView::Column *col_type = tv->get_column(n-1);
col_type->add_attribute(type_renderer->property_text(), cols.type);
col_type->set_cell_data_func(*type_renderer, sigc::mem_fun(*this, &Actions::on_cell_data_type));

CellRendererTextish *arg_renderer = Gtk::manage(new CellRendererTextish);
n = tv->append_column("Details", *arg_renderer);
n = tv->append_column(_("Details"), *arg_renderer);
Gtk::TreeView::Column *col_arg = tv->get_column(n-1);
col_arg->add_attribute(arg_renderer->property_text(), cols.arg);
col_arg->set_cell_data_func(*arg_renderer, sigc::mem_fun(*this, &Actions::on_cell_data_arg));
Expand All @@ -237,7 +243,7 @@ Actions::Actions() :

load_app_list(apps_model->children(), actions.get_root());

apps_view->append_column_editable("Application", ca.app);
apps_view->append_column_editable(_("Application"), ca.app);
apps_view->get_column(0)->set_cell_data_func(
*apps_view->get_column_cell_renderer(0), sigc::mem_fun(*this, &Actions::on_cell_data_apps));
Gtk::CellRendererText *app_name_renderer =
Expand Down Expand Up @@ -412,15 +418,15 @@ void Actions::on_type_edited(const Glib::ustring &path, const Glib::ustring &new
void Actions::on_button_delete() {
int n = tv->get_selection()->count_selected_rows();

std::stringstream msg;
Glib::ustring str;
if (n == 1)
msg << "Action \"" << get_selected_row()[cols.name] << "\" is";
str = Glib::ustring::compose(_("Action \"%1\" is"), get_selected_row()[cols.name]);
else
msg << n << " actions are";
str = Glib::ustring::compose(_("%1 actions are"), n);

Gtk::Dialog *dialog;
widgets->get_widget("dialog_delete", dialog);
FormatLabel foo(widgets, "label_delete", "an Action", msg.str().c_str());
FormatLabel foo(widgets, "label_delete", _("an Action"), str.c_str());
Gtk::Button *del;
widgets->get_widget("button_delete_delete", del);

Expand Down Expand Up @@ -460,14 +466,13 @@ void Actions::on_remove_app() {
if (size) {
Gtk::Dialog *dialog;
widgets->get_widget("dialog_delete", dialog);
std::stringstream msg;
if (action_list->app)
msg << "The application \"" << action_list->name;
else
msg << "The group \"" << action_list->name;
msg << "\" (containing " << size << " action" << (size == 1 ? "" : "s") << ") is";
FormatLabel foo(widgets, "label_delete", action_list->app ? "an Application" : "an Application Group",
msg.str().c_str());
Glib::ustring str = Glib::ustring::compose(_("%1 \"%2\" (containing %3 %4) is"),
action_list->app ? _("The application") : _("The group"),
action_list->name,
size,
(size == 1 ? "action" : "actions"));
FormatLabel foo(widgets, "label_delete", action_list->app ? _("an Application") : _("an Application Group"),
str.c_str());
Gtk::Button *del;
widgets->get_widget("button_delete_delete", del);
dialog->show();
Expand Down Expand Up @@ -531,7 +536,7 @@ void Actions::on_app_selected(std::string name) {

void Actions::on_add_group() {
ActionListDiff *parent = action_list->app ? actions.get_root() : action_list;
Glib::ustring name = "Group";
Glib::ustring name = _("Group");
ActionListDiff *child = parent->add_child(name, false);
const Gtk::TreeNodeChildren &ch = parent == actions.get_root() ?
apps_model->children().begin()->children() :
Expand Down Expand Up @@ -724,7 +729,7 @@ void Actions::on_button_new() {
if (action_list != actions.get_root())
name = action_list->name + " ";
char buf[16];
snprintf(buf, 15, "Gesture %d", action_list->order_size());
snprintf(buf, 15, _("Gesture %d"), action_list->order_size());
action_list->set_name(id, name + buf);

update_row(row);
Expand Down Expand Up @@ -854,16 +859,16 @@ const Glib::ustring SendKey::get_label() const {

const Glib::ustring ModAction::get_label() const {
if (!mods)
return "No Modifiers";
return _("No Modifiers");
Glib::ustring label = Gtk::AccelGroup::get_label(0, mods);
return label.substr(0,label.size()-1);
}

Glib::ustring ButtonInfo::get_button_text() const {
Glib::ustring str = state == AnyModifier ?
"(Any Modifier +) " :
Glib::ustring() + "(" + _("Any Modifier") + " +) " :
Gtk::AccelGroup::get_label(0, (Gdk::ModifierType)state);
char name[16];
snprintf(name, 15, "Button %d", button);
snprintf(name, sizeof(name), _("Button %d"), button);
return str + name;
}
Loading

0 comments on commit 11faa9d

Please sign in to comment.