[gcompris] Improved the create_nsis_translations.pl. Added the GPL header.



commit 59a4960281f00a970b9f30efde72cfa95a4a2853
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Sat Jul 25 00:08:09 2009 +0200

    Improved the create_nsis_translations.pl. Added the GPL header.
    Added command line parameter and usage for this script.

 Makefile.mingw.in                 |    6 +--
 tools/create_nsis_translations.pl |   99 ++++++++++++++++++++++++++++++++-----
 2 files changed, 89 insertions(+), 16 deletions(-)
---
diff --git a/Makefile.mingw.in b/Makefile.mingw.in
index 95a3da4..7479353 100644
--- a/Makefile.mingw.in
+++ b/Makefile.mingw.in
@@ -74,7 +74,7 @@ config.h: config.h.mingw.in
 
 gcompris-installer.nsi: gcompris-installer.nsi.in nsis_translations.desktop
 	./config.status gcompris-installer.nsi
-	./tools/create_nsis_translations.pl
+	./tools/create_nsis_translations.pl nsis_translations.desktop gcompris-installer.nsi nsis/translations
 
 nsis_translations.desktop: nsis_translations.desktop.in
 	LC_ALL=C /usr/bin/intltool-merge -d -u -c ./po/.intltool-merge-cache ./po nsis_translations.desktop.in nsis_translations.desktop
@@ -150,6 +150,4 @@ prep: Makefile.mingw
 	find $(GCOMPRIS_INSTALL_DIR) -name "Makefile*" -exec rm -f {} \;
 	find $(GCOMPRIS_INSTALL_DIR) -name "*.in" -exec rm -f {} \;
 	find $(GCOMPRIS_INSTALL_DIR) -name "*~" -exec rm -f {} \;
-	cp -r nsis tools Makefile.mingw config.h.mingw $(GCOMPRIS_INSTALL_DIR)
-	mkdir -p $(GCOMPRIS_INSTALL_DIR)/nsis/translations
-	cp "/usr/share/nsis/Contrib/Language files"/* $(GCOMPRIS_INSTALL_DIR)/nsis/translations
+	cp -r tools Makefile.mingw config.h.mingw $(GCOMPRIS_INSTALL_DIR)
diff --git a/tools/create_nsis_translations.pl b/tools/create_nsis_translations.pl
index 119bfe8..db44483 100755
--- a/tools/create_nsis_translations.pl
+++ b/tools/create_nsis_translations.pl
@@ -1,14 +1,89 @@
 #!/usr/bin/perl
-
-# You must 'cd' to the top directory of GCompris before you run it
+#
+# create_nsis_translations.pl
+#
+# Copyright (C) 2000-2009 Bruno Coudoin
+#
+# 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 3 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, see <http://www.gnu.org/licenses/>.
+#
 
 use strict;
-use Data::Dumper;
 
-my $gcompris_root_dir = ".";
-my $ALL_LINGUAS_STR   = `grep "ALL_LINGUAS=" $gcompris_root_dir/configure.in | cut -d= -f2`;
-$ALL_LINGUAS_STR      =~ s/\"//g;
-my @ALL_LINGUAS       = split(' ', $ALL_LINGUAS_STR);
+sub usage {
+    print 'create_nsis_translations.pl translations installer tmp_dir
+  translations
+     This is an input file that contains all the
+     translated strings. If must be formated as a GNU/Linux
+     desktop file and contains multiple strings entry.
+     For example you must have:
+     toBe=To be or not to be
+     toBe[fr]=Etre ou ne pas etre
+
+  installer
+     This is your nsis installer source file. You must include
+     in it the marker @INSERT_TRANSLATIONS@ before you use any
+     translation string.
+     After that you can use the variable $(toBe) in your file.
+
+  tmp_dir
+     This is a directory in which temporary files needed for
+     the translation system.
+     It will be created if non existant.
+     You can remove it once you have created your installer.
+';
+}
+
+my $translations;
+if (! $ARGV[0] || ! -f $ARGV[0])
+{
+    usage();
+}
+else
+{
+    $translations = $ARGV[0];
+}
+
+shift;
+my $installer;
+if (! $ARGV[0] || ! -f $ARGV[0])
+{
+    usage();
+}
+else
+{
+    $installer = $ARGV[0];
+}
+
+shift;
+my $tmp_dir;
+if (! $ARGV[0] )
+{
+    usage();
+}
+else
+{
+    $tmp_dir = $ARGV[0];
+
+    if ( ! -d $tmp_dir )
+    {
+	mkdir $tmp_dir or die "ERROR: '$tmp_dir' $!\n";
+    }
+}
+
+print "Processing translation file '$translations'\n";
+print "          NSIS source file  '$installer'\n";
+print "                Working dir '$tmp_dir'\n";
 
 # Commented out locales that are not available in nsis
 my %localeNames = (
@@ -82,7 +157,7 @@ print "Parsing nsis_translations.desktop\n";
 my %result;
 
 # Create a hash of the keys to translate
-open (MYFILE, 'nsis_translations.desktop');
+open (MYFILE, $translations);
 while (<MYFILE>) {
     chomp $_;
     if ($_ =~ /Encoding=UTF-8/)
@@ -194,7 +269,7 @@ foreach my $lang (@localeKeys) {
 
 # We have all the data, let's replace it
 my $gcomprisInstaller;
-open (MYFILE, 'gcompris-installer.nsi');
+open (MYFILE, $installer);
 while (<MYFILE>) {
     if ($_ =~ /\ INSERT_TRANSLATIONS\@/)
     {
@@ -210,7 +285,7 @@ while (<MYFILE>) {
 close (MYFILE);
 
 # Rewrite the file with the replaced data
-open (MYFILE, '>gcompris-installer.nsi');
+open (MYFILE, ">$installer");
 print MYFILE "$gcomprisInstaller";
 close (MYFILE);
 
@@ -219,7 +294,7 @@ close (MYFILE);
 #
 
 print "Creating the nsh default file\n";
-open (DESC, ">nsis/translations/en.nsh");
+open (DESC, ">$tmp_dir/en.nsh");
 print DESC ";; Auto generated file by create_nsis_translations.pl\n";
 foreach my $keyEn (keys(%$text_en)) {
     my $line = $result{'en'}{$keyEn};
@@ -231,7 +306,7 @@ close DESC;
 print "Creating the nsh locale files\n";
 foreach my $lang (@localeKeys) {
     if ( $lang eq "en" ) { next; }
-    open (DESC, ">nsis/translations/$lang.nsh");
+    open (DESC, ">$tmp_dir/$lang.nsh");
     print DESC ";; Auto generated file by create_nsis_translations.pl\n";
 
     my $text_locale = $result{"$lang"};



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]