Changeset 2813

Show
Ignore:
Timestamp:
07/01/08 00:23:09 (6 months ago)
Author:
edmanm
Message:

Fix po2ts so that it uses the same encoding to read in a .po file that it uses
to write out the .ts file. Also make the encoding used an optional parameter
that defaults to 'utf-8'.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vidalia/trunk/src/tools/po2ts/po2ts.cpp

    r2792 r2813  
    1313#include <QDomDocument> 
    1414#include <QTextStream> 
    15  
     15#include <QTextCodec> 
    1616 
    1717#define TS_DOCTYPE                    "TS" 
     
    195195{ 
    196196  QTextStream error(stderr); 
    197   error << "usage: po2ts [-q] -i <infile.po> -o <outfile.ts>\n"; 
     197  error << "usage: po2ts [-q] -i <infile.po> -o <outfile.ts> " 
     198           "[-c <encoding>]\n"; 
    198199  error << "  -q (optional)   Quiet mode (errors are still displayed)\n"; 
    199200  error << "  -i <infile.po>  Input .po file\n"; 
    200201  error << "  -o <outfile.ts> Output .ts file\n"; 
     202  error << "  -c <encoding>   Text encoding (default: utf-8)\n"; 
    201203  error.flush(); 
    202204  exit(1); 
     
    209211  QString errorMessage; 
    210212  char *infile, *outfile; 
     213  QTextCodec *codec = QTextCodec::codecForName("utf-8"); 
    211214  bool quiet = false; 
    212215 
    213216  /* Check for the correct number of input parameters. */ 
    214   if (argc < 5 || argc > 6) 
     217  if (argc < 5 || argc > 8) 
    215218    print_usage_and_exit(); 
    216219  for (int i = 1; i < argc; i++) { 
     
    222225    else if (!arg.compare("-o", Qt::CaseInsensitive) && ++i < argc) 
    223226      outfile = argv[i]; 
    224     else 
     227    else if (!arg.compare("-c", Qt::CaseInsensitive) && ++i < argc) { 
     228      codec = QTextCodec::codecForName(argv[i]); 
     229      if (!codec) { 
     230        error << "Invalid text encoding specified\n"; 
     231        return 1; 
     232      } 
     233    } else 
    225234      print_usage_and_exit();  
    226235  } 
     
    236245  QDomDocument ts; 
    237246  QTextStream po(&poFile); 
     247  po.setCodec(codec); 
    238248  int n_strings = po2ts(&po, &ts, &errorMessage); 
    239249  if (n_strings < 0) { 
     
    253263  /* Write the .ts output. */ 
    254264  QTextStream out(&tsFile); 
    255   out.setCodec("UTF-8"); 
     265  out.setCodec(codec); 
     266  out << QString("<?xml version=\"1.0\" encoding=\"%1\"?>\n") 
     267                                                  .arg(QString(codec->name())); 
    256268  out << ts.toString(4); 
    257269