Skip to content

Commit

Permalink
Add support for localization
Browse files Browse the repository at this point in the history
  • Loading branch information
gnunn1 committed Mar 5, 2016
1 parent bb8eef2 commit a1d1509
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 36 deletions.
2 changes: 1 addition & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"buildRequirements": ["allowWarnings"],
"versions": ["StdLoggerDisableTrace"],
"dependencies": {
"gtk-d": ">=3.1.4",
"gtk-d": ">=3.2.2",
"sdlang-d": "~>0.9.3"
}
}
2 changes: 1 addition & 1 deletion dub.selections.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"fileVersion": 1,
"versions": {
"libinputvisitor": "1.2.0",
"gtk-d": "3.2.0",
"gtk-d": "~master",
"sdlang-d": "0.9.3"
}
}
8 changes: 7 additions & 1 deletion dub.userprefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<Properties StartupItem="dub.json">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Default" PreferredExecutionTarget="debug" />
<MonoDevelop.Ide.Workbench />
<MonoDevelop.Ide.Workbench ActiveDocument="source/util/file/search.d">
<Files>
<File FileName="source/gtk/threads.d" Line="1" Column="1" />
<File FileName="source/vg/constants.d" Line="14" Column="50" />
<File FileName="source/util/file/search.d" Line="173" Column="67" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore />
</MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
34 changes: 34 additions & 0 deletions extract-strings.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh
DOMAIN=vgrep
BASEDIR=$(dirname $0)
OUTPUT_FILE=${BASEDIR}/po/${DOMAIN}.pot

echo "Extracting translatable strings... "

# Extract the strings from D source code. Since xgettext does not support D
# as a language we use Vala, which works reasonable well.
find ${BASEDIR}/source -name '*.d' | xgettext \
--join-existing \
--output $OUTPUT_FILE \
--files-from=- \
--directory=$BASEDIR \
--language=Vala \
--from-code=utf-8

xgettext \
--join-existing \
--output $OUTPUT_FILE \
--default-domain=$DOMAIN \
--package-name=$DOMAIN \
--directory=$BASEDIR \
--foreign-user \
--language=Desktop \
${BASEDIR}/pkg/desktop/com.gexperts.VisualGrep.desktop.in

# Merge the messages with existing po files
echo "Merging with existing translations... "
for file in ${BASEDIR}/po/*.po
do
echo -n $file
msgmerge --update $file $OUTPUT_FILE
done
32 changes: 32 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env sh

if [ -z "$1" ]; then
export PREFIX=/usr
# Make sure only root can run our script
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
exit 1
fi
else
export PREFIX=$1
fi

echo "Installing to prefix ${PREFIX}"

# Compile po files
echo "Copying and installing localization files"
for f in po/*.po; do
echo "Processing $f"
LOCALE=$(basename "$f" .po)
mkdir -p ${PREFIX}/share/locale/${LOCALE}/LC_MESSAGES
msgfmt $f -o ${PREFIX}/share/locale/${LOCALE}/LC_MESSAGES/vgrep.mo
done

# Generate desktop file
msgfmt --desktop --template=pkg/desktop/com.gexperts.VisualGrep.desktop.in -d po -o pkg/desktop/com.gexperts.VisualGrep.desktop

# Copy executable and desktop file
mkdir -p ${PREFIX}/bin
cp vgrep ${PREFIX}/bin/vgrep
mkdir -p ${PREFIX}/share/applications
cp pkg/desktop/com.gexperts.VisualGrep.desktop ${PREFIX}/share/applications
18 changes: 18 additions & 0 deletions pkg/createReleaseArchive.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export VGREP_ARCHIVE_PATH="/tmp/vgrep/archive";

rm -rf ${VGREP_ARCHIVE_PATH}

CURRENT_DIR=$(pwd)

echo "Building application..."
cd ..
dub build --build=release

./install.sh ${VGREP_ARCHIVE_PATH}/usr

echo "Creating archive"
cd ${VGREP_ARCHIVE_PATH}
zip -r vgrep.zip *

cp vgrep.zip ${CURRENT_DIR}/vgrep.zip
cd ${CURRENT_DIR}
10 changes: 10 additions & 0 deletions pkg/desktop/com.gexperts.VisualGrep.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Visual Grep
Comment=A simple GTK3 GUI for grep
Exec=vgrep
Terminal=false
Type=Application
StartupNotify=true
Categories=Utilities
Icon=search
Name[en_US]=com.gexperts.VisualGrep.desktop.in
10 changes: 10 additions & 0 deletions pkg/desktop/com.gexperts.VisualGrep.desktop.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Desktop Entry]
Name=Visual Grep
Comment=A simple GTK3 GUI for grep
Exec=vgrep
Terminal=false
Type=Application
StartupNotify=true
Categories=Utilities
Icon=search
Name[en_US]=com.gexperts.VisualGrep.desktop.in
9 changes: 7 additions & 2 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ import gtk.Main;
import gtk.Version;
import gtk.MessageDialog;

import i18n.l10n;

import vg.application;
import vg.constants;

int main(string[] args) {

//Version checking cribbed from grestful, thanks!
string error = Version.checkVersion(GTK_VERSION_MAJOR, GTK_VERSION_MINOR, GTK_VERSION_PATCH);


//textdomain
textdomain("vgrep");

if (error !is null) {
Main.init(args);

Expand All @@ -26,7 +31,7 @@ int main(string[] args) {
DialogFlags.MODAL,
MessageType.ERROR,
ButtonsType.OK,
"Your GTK version is too old, you need at least GTK " ~
_("Your GTK version is too old, you need at least GTK ") ~
to!string(GTK_VERSION_MAJOR) ~ '.' ~
to!string(GTK_VERSION_MINOR) ~ '.' ~
to!string(GTK_VERSION_PATCH) ~ '!',
Expand Down
4 changes: 2 additions & 2 deletions source/util/file/search.d
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ void search(Criteria criteria, MarkupTags markup, Tid tid) {
ulong totalMatchCount = 0;

foreach (DirEntry entry; dirEntries(criteria.path, wildcard, mode, criteria.followSymbolic).filter!(a => a.isFile)) {
info("Searching file ", entry.name);
trace("Searching file ", entry.name);
char[] buf;
string path = dirName(entry.name);
if (!path.equal(currentPath)) {
Expand Down Expand Up @@ -170,7 +170,7 @@ void search(Criteria criteria, MarkupTags markup, Tid tid) {
}

if (matches.length>0) {
info("Found %d matches in %s", matchCount, entry.name);
trace(format("Found %d matches in %s", matchCount, entry.name));
shared Result result = {entry.name, matches, matchCount};
totalMatchCount = totalMatchCount + matchCount;
tid.send(Status.PROGRESS_RESULT, criteria.id, result);
Expand Down
6 changes: 4 additions & 2 deletions source/vg/application.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import gtk.Dialog;

import gtk.util;

import i18n.l10n;

import vg.appwindow;
import vg.constants;
import vg.configuration;
Expand Down Expand Up @@ -123,8 +125,8 @@ private:

with (menu = new Menu())
{
append("About", "app.about");
append("Quit", "app.quit");
append(_("About"), "app.about");
append(_("Quit"), "app.quit");
}

this.setAppMenu(menu);
Expand Down
28 changes: 15 additions & 13 deletions source/vg/appwindow.d
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ import gtk.util;
import gtk.threads;
import util.file.search;

import i18n.l10n;

import vg.configuration;
import vg.finddialog;
import vg.search;
Expand All @@ -69,22 +71,22 @@ private:
//Create header bar
hb = new HeaderBar();
hb.setShowCloseButton(true);
hb.setTitle("Visual Grep");
hb.setTitle(_("Visual Grep"));
this.setTitlebar(hb);

//Create Find button
btnFind = new Button(StockID.FIND);
btnFind.setAlwaysShowImage(true);
btnFind.addOnClicked(&showFindDialog);
btnFind.setTooltipText("Initiate new search");
btnFind.setTooltipText(_("Initiate new search"));

hb.packStart(btnFind);

//Create New Button
Button btnNew = new Button("tab-new-symbolic", IconSize.BUTTON);
btnNew.setAlwaysShowImage(true);
btnNew.addOnClicked(&createNewTab);
btnNew.setTooltipText("Create a new tab");
btnNew.setTooltipText(_("Create a new tab"));

hb.packStart(btnNew);

Expand All @@ -110,7 +112,7 @@ private:
string id = randomUUID.toString();
ResultPage page = new ResultPage(manager, id);
pages[id] = page;
TabLabel label = new TabLabel("Search", page);
TabLabel label = new TabLabel(_("Search"), page);
label.addOnCloseClicked(&closePage);
nb.appendPage(page, label);
nb.showAll();
Expand Down Expand Up @@ -236,7 +238,7 @@ public:
this(Application application) {
super(application);
cbThreadIdle = &this.checkPendingSearches;
setTitle("Visual Grep");
setTitle(_("Visual Grep"));
setIconName("search");

manager = new SearchManager();
Expand Down Expand Up @@ -281,10 +283,10 @@ private:
ScrolledWindow scrollResults = new ScrolledWindow();
scrollResults.add(tvResults);

TreeViewColumn column = new TreeViewColumn("File", new CellRendererText(), "text", 0);
TreeViewColumn column = new TreeViewColumn(_("File"), new CellRendererText(), "text", 0);
column.setExpand(true);
tvResults.appendColumn(column);
tvResults.appendColumn(new TreeViewColumn("Matches", new CellRendererText(), "text", 1));
tvResults.appendColumn(new TreeViewColumn(_("Matches"), new CellRendererText(), "text", 1));
lsResults = new ListStore([GType.STRING, GType.LONG]);
tvResults.setModel(lsResults);

Expand All @@ -303,8 +305,8 @@ private:
ScrolledWindow scrollMatches = new ScrolledWindow();
scrollMatches.add(tvMatches);

tvMatches.appendColumn(new TreeViewColumn("Line", new CellRendererText(), "text", 0));
column = new TreeViewColumn("Match", new CellRendererText(), "markup", 1);
tvMatches.appendColumn(new TreeViewColumn(_("Line"), new CellRendererText(), "text", 0));
column = new TreeViewColumn(_("Match"), new CellRendererText(), "markup", 1);
column.setExpand(true);
tvMatches.appendColumn(column);

Expand All @@ -323,7 +325,7 @@ private:
btnAbort.setRelief(ReliefStyle.NONE);
btnAbort.setFocusOnClick(false);
btnAbort.setSensitive(false);
btnAbort.setTooltipText("Abort the current search");
btnAbort.setTooltipText(_("Abort the current search"));
btnAbort.addOnClicked(&abortSearch);
b.add(btnAbort);

Expand Down Expand Up @@ -405,12 +407,12 @@ public:
void searchStart(Criteria value) {
this._criteria = value;
clear();
sbStatus.push(1, "Starting...");
sbStatus.push(1, _("Starting..."));
btnAbort.setSensitive(true);
}

void searchProgress(string currentPath) {
sbStatus.push(1, format("Search %s", currentPath));
sbStatus.push(1, format(_("Search %s"), currentPath));
}

void searchResult(Result result) {
Expand All @@ -423,7 +425,7 @@ public:

void searchCompleted(bool aborted, ulong total) {
sbStatus.removeAll(1);
sbStatus.push(0, format("%s, total matches found %d", aborted?"Aborted":"Completed", total));
sbStatus.push(0, format(_("%s, total matches found %d"), aborted?"Aborted":"Completed", total));
btnAbort.setSensitive(false);
}
}
2 changes: 1 addition & 1 deletion source/vg/constants.d
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ immutable uint GTK_VERSION_PATCH = 0;
immutable string APPLICATION_ID = "com.gexperts.VisualGrep";

immutable string APPLICATION_NAME = "Visual Grep";
immutable string APPLICATION_VERSION = "0.1";
immutable string APPLICATION_VERSION = "0.3.0";
immutable string APPLICATION_AUTHOR = "Gerald Nunn";
immutable string APPLICATION_COPYRIGHT = "Copyright \xc2\xa9 2015 " ~ APPLICATION_AUTHOR;
immutable string APPLICATION_COMMENTS = "A GTK+ gui for the grep utility";
Expand Down
Loading

0 comments on commit a1d1509

Please sign in to comment.