• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.12
  • kdeedu
  • marble
  • data
  • lang
merge_ts_po.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include <QString>
12 #include <QFileInfo>
13 #include <QTextStream>
14 #include <QDebug>
15 
16 void usage( const QString &app )
17 {
18  qDebug() << "Usage: " << app << " input.ts input.po";
19 }
20 
21 int main( int argc, char** argv )
22 {
23  if ( argc != 3 ) {
24  usage( argv[0] );
25  return 0;
26  }
27 
28  QFileInfo const ts = QFileInfo( QString( argv[1] ) );
29  if ( !ts.exists() ) {
30  usage( argv[0] );
31  return 1;
32  }
33 
34  QFileInfo const po = QFileInfo( QString( argv[2] ) );
35  if ( !po.exists() ) {
36  usage( argv[0] );
37  return 2;
38  }
39 
40  QMap<QString,QString> translations;
41 
42  // Open the .po file and build a map of translations
43  QFile poFile( po.absoluteFilePath() );
44  poFile.open( QFile::ReadOnly );
45  QTextStream poStream( &poFile );
46  poStream.setCodec( "UTF-8" );
47  poStream.setAutoDetectUnicode( true );
48  QString source;
49  bool ignore = false;
50  while( !poStream.atEnd() ) {
51  QString line = poStream.readLine();
52  if ( line.startsWith( QLatin1String( "#, fuzzy" ) ) ) {
53  ignore = true;
54  } else if ( line.startsWith( QLatin1String( "msgid " ) ) ) {
55  source = line.mid( 7, line.size() - 8 );
56  } else if ( !source.isEmpty() && line.startsWith( QLatin1String( "msgstr " ) ) ) {
57  if ( ignore ) {
58  ignore = false;
59  } else {
60  QString translation = line.mid( 8, line.size() - 9 );
61  source.replace( QLatin1Char( '&' ), QLatin1String( "&amp;" ) );
62  translation.replace( QLatin1Char( '&' ), QLatin1String( "&amp; ") );
63  source.replace( QLatin1Char( '<' ), QLatin1String( "&lt;" ) );
64  translation.replace( QLatin1Char( '<' ), QLatin1String( "&lt;" ) );
65  source.replace( QLatin1Char( '>' ), QLatin1String( "&gt;" ) );
66  translation.replace( QLatin1Char( '>' ), QLatin1String( "&gt;" ) );
67  if ( !translation.isEmpty() ) {
68  translations[source] = translation;
69  }
70  }
71  }
72  }
73 
74  QTextStream console( stdout );
75  console.setCodec( "UTF-8" );
76 
77  // Open the .ts file and replace source strings with translations
78  // The modified .to file is dumped to stdout
79  QFile tsFile( ts.absoluteFilePath() );
80  tsFile.open( QFile::ReadOnly );
81  QTextStream tsStream( &tsFile );
82  tsStream.setCodec( "UTF-8" );
83  tsStream.setAutoDetectUnicode( true );
84  source.clear();
85  while( !tsStream.atEnd() ) {
86  QString line = tsStream.readLine().trimmed();
87  if ( line.startsWith( QLatin1String( "<source>" ) ) ) {
88  source = line.mid( 8, line.size() - 17 );
89  console << line << "\n";
90  } else if ( !source.isEmpty() &&
91  line == "<translation type=\"unfinished\"></translation>" &&
92  translations.contains( source ) ) {
93  console << "<translation>" << translations[source] << "</translation>\n";
94  } else if ( !source.isEmpty() &&
95  line == "<translation type=\"unfinished\"></translation>" ) {
96  console << line << "\n";
97  } else {
98  console << line << "\n";
99  }
100  }
101 
102  return 0;
103 }
main
int main(int argc, char **argv)
Definition: merge_ts_po.cpp:21
usage
void usage(const QString &app)
Definition: merge_ts_po.cpp:16
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:51 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal