67 changes: 0 additions & 67 deletions scripts/ts2cpp.pl

This file was deleted.

99 changes: 99 additions & 0 deletions scripts/ts2ui.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#!/usr/bin/env perl
###########################################################################
# ts2cpp.pl
# ---------------------
# begin : April 2009
# copyright : (C) 2009 by Juergen E. Fischer
# email : jef at norbit dot de
###########################################################################
# #
# 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 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################

use strict;
use warnings;
use Carp qw/croak/;
use XML::Simple;
use Data::Dumper;

sub xmlescape {
my $data = shift;
$data =~ s/&/&/sg;
$data =~ s/</&lt;/sg;
$data =~ s/>/&gt;/sg;
$data =~ s/"/&quot;/sg;
return $data;
}

$SIG{__WARN__} = sub { croak @_; };

die "usage: $0 source.ts destdir\n" unless @ARGV==2 && -f $ARGV[0] && -d $ARGV[1];

my $xml = XMLin($ARGV[0], ForceArray=>1);

open CPP, ">$ARGV[1]/numerus-i18n.cpp";
binmode(CPP, ":utf8");

print CPP <<EOF;
/*
This is NOT a proper c++ source code. This file is only designed to be caught
by qmake and included in lupdate. It contains all translateable strings collected
by pylupdate5.
*/
EOF

die "context expected" unless exists $xml->{context};

foreach my $context ( @{ $xml->{context} } ) {
my $name = $context->{name}->[0];

die "$ARGV[1]/$name-i18n.ui already exists" if -f "$ARGV[1]/$name-i18n.ui";
open UI, ">$ARGV[1]/$name-i18n.ui";
binmode(UI, ":utf8");

print UI <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<!--
This is NOT a proper UI code. This file is only designed to be caught
by qmake and included in lupdate. It contains all translateable strings collected
by scripts/ts2ui.pl.
-->
<ui version="4.0">
<class>$name</class>;
EOF

foreach my $message ( @{ $context->{message} } ) {
if( exists $message->{numerus} && $message->{numerus} eq "yes" ) {
$message->{source}->[0] =~ s/"/\\"/g;
$message->{source}->[0] =~ s/\n/\\n/g;

print CPP "translate( \"$context->{name}->[0]\", \"$message->{source}->[0]\"";

if( exists $message->{comment} && $message->{comment}->[0] ne "") {
$message->{comment}->[0] =~ s/"/\\"/g;
$message->{comment}->[0] =~ s/\n/\\n/g;
print CPP ", \"$message->{comment}->[0]\"";
}

print CPP '"",' unless exists $message->{comment} && $message->{comment}->[0] ne "";
print CPP ", 1);\n"

} else {
print UI " <property><string";
print UI " comment=\"" . xmlescape($message->{comment}->[0]) . "\"" if exists $message->{comment} && $message->{comment}->[0] ne "";
print UI ">" . xmlescape($message->{source}->[0]) . "</string></property>\n";
print UI "<!--\n" . $message->{source}->[0] . "\n-->\n";
}
}

print UI "</ui>\n";

close UI;
}

close CPP;
31 changes: 13 additions & 18 deletions scripts/update_ts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,12 @@ cleanup() {
if [ -f i18n/backup.tar ]; then
echo Restoring files...
tar -xf i18n/backup.tar
rm i18n/backup.tar
fi

echo Removing temporary files
for i in \
python/python-i18n.{ts,cpp} \
python/plugins/*/python-i18n.{ts,cpp} \
python/plugins/processing/processing-i18n.{ts,cpp} \
src/plugins/grass/grasslabels-i18n.cpp \
src/app/appinfo-i18n.cpp \
i18n/backup.tar \
qgis_ts.pro
do
[ -f "$i" ] && rm "$i"
done
rm -rf python/tmp python/plugins/processing/tmp python/plugins/*/tmp qgis_ts.pro
find . \( -name "*-i18n.ui" -o -name numerus-i18n.cpp \) -delete

trap "" EXIT
}
Expand Down Expand Up @@ -139,8 +131,9 @@ fi
echo Updating python translations
(
cd python
mkdir -p tmp
pylupdate5 user.py utils.py {console,pyplugin_installer}/*.{py,ui} -ts python-i18n.ts
perl ../scripts/ts2cpp.pl python-i18n.ts python-i18n.cpp
perl ../scripts/ts2ui.pl python-i18n.ts tmp
rm python-i18n.ts
)
for i in python/plugins/*/CMakeLists.txt; do
Expand All @@ -156,29 +149,31 @@ TRANSLATIONS = python-i18n.ts
EOF

pylupdate5 -tr-function trAlgorithm python-i18n.pro
perl ../../../scripts/ts2cpp.pl python-i18n.ts python-i18n.cpp
mkdir -p tmp
perl ../../../scripts/ts2ui.pl python-i18n.ts tmp
rm python-i18n.ts python-i18n.pro
cd ../../..
done

echo Updating GRASS module translations
perl scripts/qgm2cpp.pl >src/plugins/grass/grasslabels-i18n.cpp
perl scripts/qgm2ui.pl >src/plugins/grass/grasslabels-i18n.ui

echo Updating processing translations
perl scripts/processing2cpp.pl python/plugins/processing/processing-i18n.cpp
mkdir -p python/plugins/processing/tmp
perl scripts/processing2ui.pl python/plugins/processing/tmp

echo Updating appinfo files
python scripts/appinfo2cpp.py >src/app/appinfo-i18n.cpp
python scripts/appinfo2ui.py >src/app/appinfo-i18n.ui

echo Creating qmake project file
$QMAKE -project -o qgis_ts.pro -nopwd $PWD/src $PWD/python $PWD/i18n $textcpp

echo "TR_EXCLUDE = $(qmake -query QT_INSTALL_HEADERS)/*" >>qgis_ts.pro

echo Updating translations
$LUPDATE -no-obsolete -locations absolute -verbose qgis_ts.pro
$LUPDATE -no-ui-lines -no-obsolete -locations absolute -verbose qgis_ts.pro

perl -i.bak -ne 'print unless /^\s+<location.*qgs(expression|contexthelp)_texts\.cpp.*$/;' i18n/qgis_*.ts
perl -i.bak -ne 'print unless /^\s+<location.*(qgs(expression|contexthelp)_texts\.cpp|-i18n\.(ui|cpp)).*$/;' i18n/qgis_*.ts

if [ $action = push ]; then
cp i18n/qgis_en.ts /tmp/qgis_en.ts-uploading
Expand Down
155 changes: 0 additions & 155 deletions scripts/update_ts_files.sh

This file was deleted.