Skip to content

Commit e44f20c

Browse files
author
jef
committed
add translations strings for python plugins automatically.
git-svn-id: http://svn.osgeo.org/qgis/trunk@10633 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent eb73afc commit e44f20c

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

scripts/ts2cpp.pl

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/perl
2+
3+
use XML::Simple;
4+
use Data::Dumper;
5+
6+
die "usage: $0 source.ts dest.cpp\n" unless @ARGV==2 && -f $ARGV[0];
7+
8+
my $xml = XMLin($ARGV[0], ForceArray=>1);
9+
10+
open F, ">$ARGV[1]";
11+
12+
print F <<EOF;
13+
/*
14+
This is NOT a proper c++ source code. This file is only designed to be caught
15+
by qmake and included in lupdate. It contains all translateable strings collected
16+
by pylupdate4.
17+
*/
18+
19+
EOF
20+
21+
die "context expected" unless exists $xml->{context};
22+
23+
foreach my $context ( @{ $xml->{context} } ) {
24+
print F "\n// context: $context->{name}->[0]\n\n";
25+
26+
foreach my $message ( @{ $context->{message} } ) {
27+
$message->{source}->[0] =~ s/"/\\"/g;
28+
$message->{source}->[0] =~ s/\n/\\n/g;
29+
30+
print F "translate( \"$context->{name}->[0]\", \"$message->{source}->[0]\");\n";
31+
}
32+
}
33+
34+
close F;

scripts/update_ts_files.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
# Update the translation files with strings used in QGIS
33
# 1. create a clean Qt .pro file for the project
44
# 2. run lupdate using the .pro file from step 1
@@ -14,10 +14,21 @@ PATH=$QTDIR/bin:$PATH
1414
echo Creating qt_ts.tar
1515
tar -cvf i18n/qt_ts.tar i18n/qt_*.ts
1616
rm i18n/qt_*.ts
17+
echo Updating python plugin translations
18+
P=$PWD
19+
for i in python/plugins/*/.; do
20+
cd $i
21+
pylupdate4 $(find . -name "*.py") -ts i18n.ts
22+
perl $P/scripts/ts2cpp.pl i18n.ts i18n.cpp
23+
rm i18n.ts
24+
cd ../../..
25+
done
1726
echo Creating qmake project file
1827
qmake -project -o qgis_ts.pro
1928
echo Updating translation files
2029
lupdate -verbose qgis_ts.pro
30+
echo Removing temporary python plugin translation files
31+
rm python/plugins/*/i18n.cpp
2132
echo Removing qmake project file
2233
rm qgis_ts.pro
2334
echo Unpacking qt_ts.tar

0 commit comments

Comments
 (0)