~cypheon/elfelli

73af328471dc9b04bb6eaa443e453e4b6fefd6b0 — Johann Rudloff 15 years ago 1a58afa
Added i18n using gettext.
7 files changed, 255 insertions(+), 28 deletions(-)

M SConstruct
A po/.gitignore
A po/de.po
A po/elfelli.pot
M src/Application.cpp
M src/Application.h
A update_i18n.py
M SConstruct => SConstruct +5 -2
@@ 51,7 51,8 @@ else:

paths = {
        "bindir": env['prefix']+'/bin',
        "datadir": env['prefix']+'/share/elfelli'}
        "datadir": env['prefix']+'/share/elfelli',
        "localedir": env['prefix']+'/share/locale'}

if 'install' in targets:
        try:


@@ 64,10 65,12 @@ if 'install' in targets:
        except OSError,e:
                print 'Error %d: %s' % (e[0],e[1])
                Exit(1)
        os.system('./update_i18n.py install %s' % paths['localedir'])


env.AppendUnique(CPPFLAGS=r'-DDATADIR=\"%s\" '%paths['datadir'])
env.Alias("install", [paths['bindir'],paths['datadir']])
env.AppendUnique(CPPFLAGS=r'-DLOCALEDIR=\"%s\" '%paths['localedir'])
env.Alias("install", paths.values())

Help("""
scons        Build the program.

A po/.gitignore => po/.gitignore +1 -0
@@ 0,0 1,1 @@
/locale

A po/de.po => po/de.po +86 -0
@@ 0,0 1,86 @@
# German translations for Elfelli
# German messages for Elfelli.
# Copyright (C) 2006 Johann Rudloff
# This file is distributed under the same license as the Elfelli package.
# Johann Rudloff <cypheon@gmx.net>, 2006.
#
msgid ""
msgstr ""
"Project-Id-Version: elfelli 01\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-11-10 23:43+0100\n"
"PO-Revision-Date: 2006-11-07 20:30+0100\n"
"Last-Translator: Johann Rudloff <cypheon@gmx.net>\n"
"Language-Team: German <translation-team-de@lists.sourceforge.net>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: src/Application.cpp:94
msgid "Export PNG"
msgstr "PNG exportieren"

#: src/Application.cpp:133
msgid ""
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"at your option) any later version.\n"
msgstr ""
"Dieses Programm ist freie Software. Sie können es unter den Bedingungen\n"
"der GNU General Public License, wie von der Free Software Foundation ver-\n"
"öffentlicht, weitergeben und/oder modifizieren; entweder gemäß Version 2\n"
"der Lizenz, oder (nach Ihrem Ermessen) gemäß jeder späteren Version.\n"

#: src/Application.cpp:138
msgid ""
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
"GNU General Public License for more details.\n"
msgstr ""
"Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, dass es\n"
"Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne\n"
"die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN\n"
"BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.\n"

#: src/Application.cpp:143
msgid ""
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  "
"USA\n"
msgstr ""
"Sie sollten ein Exemplar der GNU General Public License zusammen mit\n"
"diesem Programm erhalten haben, Falls nicht, schreiben Sie an die\n"
"Free Software Foundation, Inc.\n"
"51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.\n"

#: src/Application.cpp:177
msgid "_Scene"
msgstr "_Szene"

#: src/Application.cpp:181
msgid "Export _PNG"
msgstr "_PNG exportieren"

#: src/Application.cpp:182
msgid "Export S_VG"
msgstr "S_VG exportieren"

#: src/Application.cpp:185
msgid "E_dit"
msgstr "_Bearbeiten"

#: src/Application.cpp:187
msgid "Negative body"
msgstr "Negativer Körper"

#: src/Application.cpp:188
msgid "Positive body"
msgstr "Positiver Körper"

#: src/Application.cpp:190
msgid "_Help"
msgstr "_Hilfe"

A po/elfelli.pot => po/elfelli.pot +73 -0
@@ 0,0 1,73 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2006-11-10 23:55+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/Application.cpp:94
msgid "Export PNG"
msgstr ""

#: src/Application.cpp:133
msgid ""
"This program is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
"at your option) any later version.\n"
msgstr ""

#: src/Application.cpp:138
msgid ""
"This program is distributed in the hope that it will be useful,\n"
"but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
"MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
"GNU General Public License for more details.\n"
msgstr ""

#: src/Application.cpp:143
msgid ""
"You should have received a copy of the GNU General Public License\n"
"along with this program; if not, write to the Free Software\n"
"Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  "
"USA\n"
msgstr ""

#: src/Application.cpp:177
msgid "_Scene"
msgstr ""

#: src/Application.cpp:181
msgid "Export _PNG"
msgstr ""

#: src/Application.cpp:182
msgid "Export S_VG"
msgstr ""

#: src/Application.cpp:185
msgid "E_dit"
msgstr ""

#: src/Application.cpp:187
msgid "Negative body"
msgstr ""

#: src/Application.cpp:188
msgid "Positive body"
msgstr ""

#: src/Application.cpp:190
msgid "_Help"
msgstr ""

M src/Application.cpp => src/Application.cpp +40 -26
@@ 37,9 37,24 @@ Application::Application(int argc, char **argv):
  gtk_main(argc, argv),
  save_dlg(main_win, "", FILE_CHOOSER_ACTION_SAVE)
{
  setup_gettext();
  build_gui();
}

void Application::setup_gettext()
{
  setlocale(LC_ALL, "");

  std::ifstream in("po/locale/de/LC_MESSAGES/elfelli.mo");
  if(in)
    bindtextdomain("elfelli", "po/locale");
  else
    bindtextdomain("elfelli", LOCALEDIR);
  in.close();

  textdomain("elfelli");
}

const std::string Application::find_datafile(const std::string& fname)
{
  std::vector<std::string> dirs;


@@ 76,7 91,7 @@ void Application::on_export_png_activate()
{
  std::string filename = "";

  save_dlg.set_title("PNG exportieren");
  save_dlg.set_title(_("Export PNG"));

  int result = save_dlg.run();
  if(result == RESPONSE_OK)


@@ 114,26 129,25 @@ void Application::on_about_activate()
{
  AboutDialog dlg;

  const std::string license_parts[3] = {
    "Dieses Programm ist freie Software. Sie können es unter den Bedingungen\n"
    "der GNU General Public License, wie von der Free Software Foundation ver-\n"
    "öffentlicht, weitergeben und/oder modifizieren; entweder gemäß Version 2\n"
    "der Lizenz, oder (nach Ihrem Ermessen) gemäß jeder späteren Version.\n",

    "Die Veröffentlichung dieses Programms erfolgt in der Hoffnung, dass es\n"
    "Ihnen von Nutzen sein wird, aber OHNE IRGENDEINE GARANTIE, sogar ohne\n"
    "die implizite Garantie der MARKTREIFE oder der VERWENDBARKEIT FÜR EINEN\n"
    "BESTIMMTEN ZWECK. Details finden Sie in der GNU General Public License.\n",

    "Sie sollten ein Exemplar der GNU General Public License zusammen mit\n"
    "diesem Programm erhalten haben, Falls nicht, schreiben Sie an die\n"
    "Free Software Foundation, Inc.\n"
    "51 Franklin Street, Fifth Floor, Boston, MA 02110, USA.\n"};
  const char *license_parts[] = {
    N_("This program is free software; you can redistribute it and/or modify\n"
       "it under the terms of the GNU General Public License as published by\n"
       "the Free Software Foundation; either version 2 of the License, or\n"
       "at your option) any later version.\n"),
 
    N_("This program is distributed in the hope that it will be useful,\n"
       "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
       "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n"
       "GNU General Public License for more details.\n"),

    N_("You should have received a copy of the GNU General Public License\n"
       "along with this program; if not, write to the Free Software\n"
       "Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n")};

  const std::string license_text =
    license_parts[0] + "\n"
    + license_parts[1] + "\n"
    + license_parts[2];
    std::string(_(license_parts[0])) + "\n"
    + _(license_parts[1]) + "\n"
    + _(license_parts[2]);

  dlg.set_name(appname);
  dlg.set_version(version);


@@ 160,20 174,20 @@ bool Application::setup_ui_actions()
{
  action_group = ActionGroup::create();

  action_group->add( Action::create("MenuScene", "_Szene") );
  action_group->add( Action::create("MenuScene", _("_Scene")) );
  action_group->add( Action::create("New", Stock::NEW) , sigc::mem_fun(*this, &Application::reset_simulation));
  action_group->add( Action::create("Open", Stock::OPEN) );
  action_group->add( Action::create("SaveAs", Stock::SAVE_AS) );
  action_group->add( Action::create("ExportPNG", "Exportieren als _PNG") , sigc::mem_fun(*this, &Application::on_export_png_activate));
  action_group->add( Action::create("ExportSVG", "Exportieren als S_VG") );
  action_group->add( Action::create("ExportPNG", _("Export _PNG")) , sigc::mem_fun(*this, &Application::on_export_png_activate));
  action_group->add( Action::create("ExportSVG", _("Export S_VG")) );
  action_group->add( Action::create("Quit", Stock::QUIT) , sigc::mem_fun(*this, &Application::quit));

  action_group->add( Action::create("MenuEdit", "_Bearbeiten") );
  action_group->add( Action::create("MenuEdit", _("E_dit")) );
  action_group->add( Action::create("Clear", Stock::CLEAR) , sigc::mem_fun(*this, &Application::reset_simulation));
  action_group->add( Action::create("AddNegative", "Negativer Körper") , sigc::mem_fun(*this, &Application::on_add_negative_body_clicked));
  action_group->add( Action::create("AddPositive", "Positiver Körper") , sigc::mem_fun(*this, &Application::on_add_positive_body_clicked));
  action_group->add( Action::create("AddNegative", _("Negative body")) , sigc::mem_fun(*this, &Application::on_add_negative_body_clicked));
  action_group->add( Action::create("AddPositive", _("Positive body")) , sigc::mem_fun(*this, &Application::on_add_positive_body_clicked));

  action_group->add( Action::create("MenuHelp", "_Hilfe") );
  action_group->add( Action::create("MenuHelp", _("_Help")) );
  action_group->add( Action::create("About", Stock::ABOUT) , sigc::mem_fun(*this, &Application::on_about_activate));

  ui_manager = UIManager::create();

M src/Application.h => src/Application.h +6 -0
@@ 20,6 20,10 @@

#include <gtkmm.h>

#include <libintl.h>
#define _(String) gettext(String)
#define N_(String) String

#include "SimulationCanvas.h"

namespace Elfelli


@@ 39,6 43,8 @@ class Application
  static const std::string datadir;

 private:
  void setup_gettext();

  bool build_gui();
  bool setup_ui_actions();
  void setup_file_chooser_dialogs();

A update_i18n.py => update_i18n.py +44 -0
@@ 0,0 1,44 @@
#!/usr/bin/env python

import os, sys
from glob import glob

def find_locales():
    po_files = glob('po/*.po')
    locales = [file[3:-3] for file in po_files]
    return locales

def make_mo(locale):
    print 'Generating binary %s message catalog...' % locale
    if not os.path.isdir('po/locale/%s/LC_MESSAGES' % locale):
        os.makedirs('po/locale/%s/LC_MESSAGES' % locale, 0755)
    os.system('msgfmt -o po/locale/%s/LC_MESSAGES/elfelli.mo po/%s.po' % (locale,locale))

def update_pot():
    print 'Updating po/elfelli.pot...'
    os.system('xgettext -o po/elfelli.pot -kN_ -k_ --c++ src/*.cpp src/*.h')

def update_po_files(locales):
    print 'Updating po files...'
    for lang in locales:
        os.system('msgmerge --update po/%s.po po/elfelli.pot' % lang)

def compile_po_files(locales):
    for locale in locales:
        make_mo(locale)

def install_mo_files(locales, dest):
    for locale in locales:
        o = ''
        if os.geteuid() == 0:
            o = '-oroot -groot '
        os.system('install -v -m644 %s -D po/locale/%s/LC_MESSAGES/elfelli.mo %s/%s/LC_MESSAGES/elfelli.mo' % (o, locale, dest, locale))

if __name__ == '__main__':
    locales = find_locales();
    if len(sys.argv) == 1 or sys.argv[1] == 'update':
        update_pot()
        update_po_files(locales)
        compile_po_files(locales)
    elif len(sys.argv) == 3 and sys.argv[1] == 'install':
        install_mo_files(locales, sys.argv[2]);