bool FLTranslator::loadTsContent(const QString &key)
{
  QString tsFile(AQ_DISKCACHE_FILEPATH(key));
  QString qmFile(AQ_DISKCACHE_DIRPATH + '/' +
                 key + QString::fromLatin1(".qm"));
  FLTranslations trans;

  if (!QFile::exists(qmFile)) {
    if (tsFile.isEmpty())
      return false;
    trans.lrelease(tsFile, qmFile, !multiLang_);
  }

  return QTranslator::load(qmFile);
}
void
Sintatico::Analisador::TransformaLexico(QString _filename)
{
    QFile
    arquivo;
    arquivo.setFileName(_filename);
    arquivo.open(QIODevice::ReadOnly);

    QTextStream tsFile(&arquivo);
    while(!tsFile.atEnd()){
        QString line = tsFile.readLine();
        //remove o nome do arquivo
        while(line[0]!=':'){
            line.remove(0,1);
        }
        line.remove(0,1);
        //tranforma string em Stream
        QTextStream tsLine(&line,QIODevice::ReadOnly);
        //Contador de linhas
        int lineCount;
        //le o numero da linha
        tsLine>>lineCount;
        //remove caracteres de controle
        line.remove(0,2);
        line.replace(',',' ');
        line.replace('[',' ');
        line.replace(']',' ');
        //lê os tokens
        while(!tsLine.atEnd()){
        //remove '['
            Tokens temp;
            temp.linha = lineCount;
            tsLine>>temp.token_class;
            tsLine>>temp.value;
            if(!temp.value.isEmpty()){
                this->valores_lexico.append(temp);
//                qDebug()<<temp.value<<" - "<<temp.token_class;
            }
        }

    }
}
void Transforma(QFile &arquivo, QList<Tokens*> * tokens)
{
    QTextStream tsFile(&arquivo);
    while(!tsFile.atEnd()){
        QString line = tsFile.readLine();
        //remove o nome do arquivo
        while(line[0]!=':'){
            line.remove(0,1);
        }
        line.remove(0,1);
        //tranforma string em Stream
        QTextStream tsLine(&line,QIODevice::ReadOnly);
        //Contador de linhas
        int lineCount;
        //le o numero da linha
        tsLine>>lineCount;
        //remove caracteres de controle
        line.remove(0,2);
        line.replace(',',' ');
        line.replace('[',' ');
        line.replace(']',' ');
        //lê os tokens
        while(!tsLine.atEnd()){
        //remove '['
            Tokens * temp = new Tokens();
            temp->linha = lineCount;
            tsLine>>temp->Classificacao;
            tsLine>>temp->token;
            if(!temp->token.isEmpty()){
                tokens->append(temp);
                qDebug()<<temp->token<<" - "<<temp->Classificacao;
            }
        }

    }
}
Beispiel #4
0
int main( int argc, char** argv )
{
    if ( argc != 3 ) {
        usage( argv[0] );
        return 0;
    }

    QFileInfo const ts = QFileInfo( QString( argv[1] ) );
    if ( !ts.exists() ) {
        usage( argv[0] );
        return 1;
    }

    QFileInfo const po = QFileInfo( QString( argv[2] ) );
    if ( !po.exists() ) {
        usage( argv[0] );
        return 2;
    }

    QMap<QString,QString> translations;

    // Open the .po file and build a map of translations
    QFile poFile( po.absoluteFilePath() );
    poFile.open( QFile::ReadOnly );
    QTextStream poStream( &poFile );
    poStream.setCodec( "UTF-8" );
    poStream.setAutoDetectUnicode( true );
    QString source;
    bool ignore = false;
    while( !poStream.atEnd() ) {
        QString line = poStream.readLine();
        if ( line.startsWith( "#, fuzzy" ) ) {
            ignore = true;
        } else if ( line.startsWith( "msgid " ) ) {
            source = line.mid( 7, line.size() - 8 );
        } else if ( !source.isEmpty() && line.startsWith( "msgstr " ) ) {
            if ( ignore ) {
                ignore = false;
            } else {
                QString translation = line.mid( 8, line.size() - 9 );
                source.replace( "&", "&amp;" );
                translation.replace( "&", "&amp;" );
                source.replace( "<", "&lt;" );
                translation.replace( "<", "&lt;" );
                source.replace( ">", "&gt;" );
                translation.replace( ">", "&gt;" );
                if ( !translation.isEmpty() ) {
                    translations[source] = translation;
                }
            }
        }
    }

    QTextStream console( stdout );
    console.setCodec( "UTF-8" );

    // Open the .ts file and replace source strings with translations
    // The modified .to file is dumped to stdout
    QFile tsFile( ts.absoluteFilePath() );
    tsFile.open( QFile::ReadOnly );
    QTextStream tsStream( &tsFile );
    tsStream.setCodec( "UTF-8" );
    tsStream.setAutoDetectUnicode( true );
    source = QString();
    while( !tsStream.atEnd() ) {
        QString line = tsStream.readLine().trimmed();
        if ( line.startsWith( "<source>" ) ) {
            source = line.mid( 8, line.size() - 17 );
            console << line << "\n";
        } else if ( !source.isEmpty() &&
                   line == "<translation type=\"unfinished\"></translation>" &&
                   translations.contains( source ) ) {
            console << "<translation>" << translations[source] << "</translation>\n";
        } else if ( !source.isEmpty() &&
                   line == "<translation type=\"unfinished\"></translation>" ) {
            console << line << "\n";
        } else {
            console << line << "\n";
        }
    }

    return 0;
}
Beispiel #5
0
int
main(int argc, char *argv[])
{
  QTextStream error(stderr);
  QString errorMessage;
  char *infile, *outfile;
  QTextCodec *codec = QTextCodec::codecForName("utf-8");
  bool quiet = false;

  /* Check for the correct number of input parameters. */
  if (argc < 5 || argc > 8)
    print_usage_and_exit();
  for (int i = 1; i < argc; i++) {
    QString arg(argv[i]);
    if (!arg.compare("-q", Qt::CaseInsensitive))
      quiet = true;
    else if (!arg.compare("-i", Qt::CaseInsensitive) && ++i < argc)
      infile = argv[i];
    else if (!arg.compare("-o", Qt::CaseInsensitive) && ++i < argc)
      outfile = argv[i];
    else if (!arg.compare("-c", Qt::CaseInsensitive) && ++i < argc) {
      codec = QTextCodec::codecForName(argv[i]);
      if (!codec) {
        error << "Invalid text encoding specified\n";
        return 1;
      }
    } else
      print_usage_and_exit(); 
  }

  /* Open the input PO file for reading. */
  QFile poFile(infile);
  if (!poFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
    error << QString("Unable to open '%1' for reading: %2\n").arg(infile)
                                                .arg(poFile.errorString());
    return 2;
  }

  QDomDocument ts;
  QTextStream po(&poFile);
  po.setCodec(codec);
  int n_strings = po2ts(&po, &ts, &errorMessage);
  if (n_strings < 0) {
    error << QString("Unable to convert '%1': %2\n").arg(infile)
                                                    .arg(errorMessage);
    return 3;
  }

  /* Open the TS file for writing. */
  QFile tsFile(outfile);
  if (!tsFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
    error << QString("Unable to open '%1' for writing: %2\n").arg(outfile)
                                                .arg(tsFile.errorString());
    return 4;
  }

  /* Write the .ts output. */
  QTextStream out(&tsFile);
  out.setCodec(codec);
  out << QString("<?xml version=\"1.0\" encoding=\"%1\"?>\n")
                                                  .arg(QString(codec->name()));
  out << ts.toString(4);

  if (!quiet) {
    QTextStream results(stdout);
    results << QString("Converted %1 strings from %2 to %3.\n").arg(n_strings)
                                                               .arg(infile)
                                                               .arg(outfile);
  }
  return 0;
}