Skip to content

Commit

Permalink
grass modules i18n
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@12658 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Dec 31, 2009
1 parent b07d7d7 commit 57e37f8
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 10 deletions.
58 changes: 58 additions & 0 deletions scripts/qgm2cpp.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

print <<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 pylupdate4.
*/
EOF

my %labels;
my $file;

sub parse {
foreach my $a (@_) {
if( ref($a) eq "ARRAY" ) {
foreach my $b ( @$a ) {
parse($b);
}
} elsif( ref($a) eq "HASH" ) {
foreach my $b ( keys %$a ) {
if( $b eq "label" ) {
my $label = $a->{$b};
die "expected string" unless ref($label) eq "";
print STDERR "warning[$file]: '$label' should start with a uppercase character or digit and not start or end with whitespaces"
if $label =~ /^\s+/ || $label =~ /\s+$/ || $label !~ /^[A-Z0-9(]/;
$label =~ s/^\s+//;
$label =~ s/\s+$//;
$label =~ ucfirst $label;
$labels{$label} = 1;
} else {
parse($a->{$b});
}
}
# } elsif(ref($a) eq "") {
# warn "found: " . $a;
# } else {
# warn "found: " . ref($a) . " " . Dumper($a);
}
}
}

open I, "find src/plugins/grass -name '*.qgm' -o -name '*.qgc'|";
while($file = <I>) {
print STDERR "$file\n";
chop $file;
parse XMLin($file, ForceArray=>1);
print STDERR "$file DONE\n";
}
close I;

foreach (sort keys %labels) {
print "translate( \"grasslabel\", \"$_\" );\n";
}
1 change: 0 additions & 1 deletion scripts/ts2cpp.pl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/perl

use XML::Simple;
use Data::Dumper;

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

Expand Down
3 changes: 2 additions & 1 deletion scripts/update_ts_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ for i in python/plugins/*/CMakeLists.txt; do
rm python-i18n.ts
cd ../../..
done
perl scripts/qgm2cpp.pl >src/plugins/grass/grasslabels-i18n.cpp
echo Creating qmake project file
qmake -project -o qgis_ts.pro -nopwd src python i18n
echo Updating translation files
lupdate$opts -verbose qgis_ts.pro
echo Removing temporary python translation files
perl -i.bak -ne 'print unless /^\s+<location.*python-i18n\.cpp.*$/;' i18n/qgis_*.ts
rm python/python-i18n.cpp python/plugins/*/python-i18n.cpp i18n/qgis_*.ts.bak
rm python/python-i18n.cpp python/plugins/*/python-i18n.cpp i18n/qgis_*.ts.bak src/plugins/grass/grasslabels-i18n.cpp
echo Removing qmake project file
rm qgis_ts.pro
echo Unpacking qt_ts.tar
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrassmapcalc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,7 +1314,7 @@ void QgsGrassMapcalc::load()
{
case QgsGrassMapcalcObject::Map:
{
QString label = e.attribute( "label", "???" );
QString label = QApplication::translate( "grasslabel", e.attribute( "label", "???" ).toUtf8() );
obj->setValue( value, label );
break;
}
Expand Down
10 changes: 4 additions & 6 deletions src/plugins/grass/qgsgrassmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ QString QgsGrassModule::label( QString path )
qFile.close();
QDomElement qDocElem = qDoc.documentElement();

return ( qDocElem.attribute( "label" ) );
return QApplication::translate( "grasslabel", qDocElem.attribute( "label" ).toUtf8() );
}

QPixmap QgsGrassModule::pixmap( QString path, int height )
Expand Down Expand Up @@ -2503,24 +2503,22 @@ QgsGrassModuleItem::QgsGrassModuleItem( QgsGrassModule *module, QString key,
QString label, description;
if ( !qdesc.attribute( "label" ).isEmpty() )
{
label = qdesc.attribute( "label" );
label = QApplication::translate( "grasslabel", qdesc.attribute( "label" ).toUtf8() );
}
if ( label.isEmpty() )
{
QDomNode n = gnode.namedItem( "label" );
if ( !n.isNull() )
{
QDomElement e = n.toElement();
label = e.text().trimmed();
label.replace( 0, 1, label.left( 1 ).toUpper() );
label = QApplication::translate( "grasslabel", e.text().toUtf8() );
}
}
QDomNode n = gnode.namedItem( "description" );
if ( !n.isNull() )
{
QDomElement e = n.toElement();
description = e.text().trimmed();
description.replace( 0, 1, description.left( 1 ).toUpper() );
description = QApplication::translate( "grasslabel", e.text().toUtf8() );
}

if ( !label.isEmpty() )
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/grass/qgsgrasstools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ void QgsGrassTools::addModules( QTreeWidgetItem *parent, QDomElement &element )

if ( e.tagName() == "section" )
{
QString label = e.attribute( "label" );
QString label = QApplication::translate( "grasslabel", e.attribute( "label" ).toUtf8() );
QgsDebugMsg( QString( "label = %1" ).arg( label ) );
item->setText( 0, label );
item->setExpanded( false );
Expand Down

0 comments on commit 57e37f8

Please sign in to comment.