From d455d036089e0b1019dd1115a710952685304ec9 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Thu, 2 May 2013 16:26:36 +0100 Subject: [PATCH] Create new generate_pot.py script for translations * glade3 files require workaround with intltool-extract * webui javascript files are now included * fix multiline string for parse --- .gitattributes | 4 +- .gitignore | 1 + create_potfiles_in.py | 32 ------- deluge/ui/web/js/deluge-all/OptionsManager.js | 10 +-- .../js/deluge-all/preferences/OtherPage.js | 18 ++-- generate_pot.py | 89 +++++++++++++++++++ gettextize.sh | 26 ------ 7 files changed, 105 insertions(+), 75 deletions(-) delete mode 100755 create_potfiles_in.py create mode 100755 generate_pot.py delete mode 100755 gettextize.sh diff --git a/.gitattributes b/.gitattributes index b4a9dd2a4..9c21c1616 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,9 +6,7 @@ docs/source/ export-ignore /tests/ export-ignore deluge/scripts/ export-ignore setup.cfg export-ignore -create_potfiles_in.py export-ignore -gettextize.sh export-ignore -deluge/i18n/deluge.pot export-ignore +generate_pot.py export-ignore deluge/ui/web/css/*-debug.css export-ignore deluge/ui/web/js/*-debug.js export-ignore deluge/ui/web/js/deluge-all/ export-ignore diff --git a/.gitignore b/.gitignore index 4ee1bf4a1..2a19a3ee3 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ dist *.tar.* _trial_temp deluge/i18n/*/ +deluge.pot *.desktop .build_data* osx/app diff --git a/create_potfiles_in.py b/create_potfiles_in.py deleted file mode 100755 index 586192c5f..000000000 --- a/create_potfiles_in.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env python -import os -import re -import sys -# Paths to exclude -EXCLUSIONS = [ - "deluge/scripts", - "deluge/i18n", -] - -POTFILE_IN = "deluge/i18n/POTFILES.in" - -pattern = "deluge\/plugins\/.*\/build" -compiled = re.compile(pattern) - -sys.stdout.write("Creating " + POTFILE_IN + " ... ") -sys.stdout.flush() -to_translate = [] -for (dirpath, dirnames, filenames) in os.walk("deluge"): - for filename in filenames: - if os.path.splitext(filename)[1] in (".py", ".glade", ".in") \ - and dirpath not in EXCLUSIONS \ - and not compiled.match(dirpath): - to_translate.append(os.path.join(dirpath, filename)) - -f = open(POTFILE_IN, "wb") -for line in to_translate: - f.write(line + "\n") - -f.close() - -print "Done" diff --git a/deluge/ui/web/js/deluge-all/OptionsManager.js b/deluge/ui/web/js/deluge-all/OptionsManager.js index fedd439ef..2dde514f4 100644 --- a/deluge/ui/web/js/deluge-all/OptionsManager.js +++ b/deluge/ui/web/js/deluge-all/OptionsManager.js @@ -1,6 +1,6 @@ /*! * Deluge.OptionsManager.js - * + * * Copyright (c) Damien Churchill 2009-2010 * * This program is free software; you can redistribute it and/or modify @@ -40,7 +40,7 @@ Ext.namespace('Deluge'); * @param {Object} config Configuration options */ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { - + constructor: function(config) { config = config || {}; this.binds = {}; @@ -82,7 +82,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { addOptions: function(options) { this.options = Ext.applyIf(this.options, options); }, - + /** * Binds a form field to the specified option. * @param {String} option @@ -262,7 +262,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { * @private */ onFieldChange: function(field, event) { - if (field.field) field = field.field // fix for spinners + if (field.field) field = field.field; // fix for spinners this.update(field._doption, field.getValue()); }, @@ -279,7 +279,7 @@ Deluge.OptionsManager = Ext.extend(Ext.util.Observable, { // If we don't have a bind there's nothing to do. if (Ext.isEmpty(this.binds[option])) return; Ext.each(this.binds[option], function(bind) { - // The field is currently focused so we don't want to + // The field is currently focused so we don't want to // change it. if (bind == this.focused) return; // Set the form field to the new value. diff --git a/deluge/ui/web/js/deluge-all/preferences/OtherPage.js b/deluge/ui/web/js/deluge-all/preferences/OtherPage.js index 105500eb3..60f1a655f 100644 --- a/deluge/ui/web/js/deluge-all/preferences/OtherPage.js +++ b/deluge/ui/web/js/deluge-all/preferences/OtherPage.js @@ -1,6 +1,6 @@ /*! * Deluge.preferences.OtherPage.js - * + * * Copyright (c) Damien Churchill 2009-2010 * * This program is free software; you can redistribute it and/or modify @@ -44,12 +44,12 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { }, config); Deluge.preferences.Other.superclass.constructor.call(this, config); }, - + initComponent: function() { Deluge.preferences.Other.superclass.initComponent.call(this); - + var optMan = deluge.preferences.getOptionsManager(); - + var fieldset = this.add({ xtype: 'fieldset', border: false, @@ -65,7 +65,7 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { name: 'new_release_check', boxLabel: _('Be alerted about new releases') })); - + fieldset = this.add({ xtype: 'fieldset', border: false, @@ -78,9 +78,9 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { xtype: 'panel', border: false, bodyCfg: { - html: _('Help us improve Deluge by sending us your ' - + 'Python version, PyGTK version, OS and processor ' - + 'types. Absolutely no other information is sent.') + html: _('Help us improve Deluge by sending us your \ +Python version, PyGTK version, OS and processor \ +types. Absolutely no other information is sent.') } }); optMan.bind('send_info', fieldset.add({ @@ -90,7 +90,7 @@ Deluge.preferences.Other = Ext.extend(Ext.form.FormPanel, { boxLabel: _('Yes, please send anonymous statistics'), name: 'send_info' })); - + fieldset = this.add({ xtype: 'fieldset', border: false, diff --git a/generate_pot.py b/generate_pot.py new file mode 100755 index 000000000..22b76257e --- /dev/null +++ b/generate_pot.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python +# +# This script creates the deluge.pot template file for translators +# +import os +import re +import sys +from version import get_version +from subprocess import call +from datetime import datetime + +# Paths to exclude +EXCLUSIONS = [ + "deluge/scripts", + "deluge/i18n", + "deluge/tests", +] +webui_js_dir = "deluge/ui/web/js/deluge-all" +infiles_list= "infiles.list" +pot_filepath = os.path.join("deluge", "i18n", "deluge.pot") + +re_exc_plugin_build = re.compile("deluge\/plugins\/.*\/build") + +xgettext_cmd = [ + "xgettext", + "--from-code=UTF-8", + "-kN_:1", + "-f%s" % infiles_list, + "-o%s" % pot_filepath, + "--package-name=%s" % "Deluge", + "--copyright-holder=%s" % "Deluge Team", + "--package-version=%s" % get_version(prefix='deluge-', suffix='.dev0'), + "--msgid-bugs-address=%s" % "http://deluge-torrent.org", +] + +to_translate = [] +for (dirpath, dirnames, filenames) in os.walk("deluge"): + for filename in filenames: + if dirpath not in EXCLUSIONS and not re_exc_plugin_build.match(dirpath): + filepath = os.path.join(dirpath, filename) + if os.path.splitext(filepath)[1] in (".py", ".glade"): + to_translate.append(filepath) + elif filename.endswith(".in"): + call(["intltool-extract", "--quiet", "--type=gettext/ini", filepath]) + to_translate.append(filepath + ".h") + elif filename.endswith(".ui"): + call(["intltool-extract", "--quiet", "--type=gettext/glade", filepath]) + to_translate.append(filepath + ".h") + +with open(infiles_list, "wb") as f: + for line in to_translate: + f.write(line + "\n") + +# Create pot file from file list +call(xgettext_cmd) + +# find javascript files +js_to_translate=[] +for (dirpath, dirnames, filenames) in os.walk(webui_js_dir): + for filename in filenames: + if os.path.splitext(filename)[1] == ".js": + js_to_translate.append(os.path.join(dirpath, filename)) + +with open(infiles_list, "wb") as f: + for line in js_to_translate: + f.write(line + "\n") + +# Force xgettext language to parse javascript and update pot file +output = call(xgettext_cmd + ["--language=Python", "-j"]) +print "====== Javascript 'unterminated string' warnings can be ignored ======" + +# Replace YEAR and PACKAGE in the copyright message +with open(pot_filepath, "r") as f: + lines = f.readlines() +with open(pot_filepath, "w") as f: + for line in lines: + if "YEAR" in line: + line = line.replace("YEAR", str(datetime.now().year)) + elif "PACKAGE" in line: + line = line.replace("PACKAGE", "Deluge") + f.write(line) + +# Clean up temp files +os.remove(infiles_list) +for filepath in to_translate: + if filepath.endswith(".h"): + os.remove(filepath) + +print "Created %s" % pot_filepath diff --git a/gettextize.sh b/gettextize.sh deleted file mode 100755 index 9440af5a9..000000000 --- a/gettextize.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -PACKAGE="Deluge" -PKG_VERSION=`grep "version\ =\ \"" setup.py | cut -d '"' -f2` -PO_DIR="deluge/i18n" -POTFILES_IN="infiles.list" -POT_FILE=deluge.pot - -cp $PO_DIR/POTFILES.in $POTFILES_IN -DESKTOP_FILE=`grep ".*desktop.in$" $POTFILES_IN` - -if [ $DESKTOP_FILE ]; then - sed -i "\:$DESKTOP_FILE:d" $POTFILES_IN - intltool-extract --quiet --type=gettext/ini $DESKTOP_FILE - echo "$DESKTOP_FILE.h" >> $POTFILES_IN -fi - -xgettext --from-code=UTF-8 -kN_:1 -f $POTFILES_IN -o $PO_DIR/$POT_FILE --package-name=$PACKAGE \ - --copyright-holder='Deluge Team' --package-version=$PKG_VERSION \ - --msgid-bugs-address=http://deluge-torrent.org - -# sub the YEAR in the copyright message -sed -i -e '2s/YEAR/'`date +%Y`'/' "$PO_DIR/$POT_FILE" - -rm -f $POTFILES_IN -rm -f "$DESKTOP_FILE.h" -echo "Created $PO_DIR/$POT_FILE"