本文整理汇总了C++中QTranslator::save方法的典型用法代码示例。如果您正苦于以下问题:C++ QTranslator::save方法的具体用法?C++ QTranslator::save怎么用?C++ QTranslator::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTranslator
的用法示例。
在下文中一共展示了QTranslator::save方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: translate
void translate( const QString& filename, const QString& qmfile )
{
QFile f(filename);
if ( !f.open( IO_ReadOnly) )
return;
QTranslator* translator = new QTranslator(0);
QTextCodec *codec = 0;
for (int pass = 0; pass < 2; pass++) {
f.at(0);
QTextStream t( &f );
QString line;
QString msgid;
QString msgstr;
if ( codec != 0 ) {
t.setCodec( codec );
}
while ( !t.atEnd() || !line.isEmpty() ) {
if (line.isEmpty()) {
t.skipWhiteSpace();
line = t.readLine();
}
if ( hasHandle( line, "msgid") ) {
msgstr = QString::null;
msgid = extractContents( line );
if (!t.atEnd()) {
t.skipWhiteSpace();
line = t.readLine();
}
else
line = QString::null;
while ( hasHandle( line, "\"") ) {
msgid += extractContents( line );
if (!t.atEnd()) {
t.skipWhiteSpace();
line = t.readLine();
}
else
line = QString::null;
}
}
else if ( hasHandle( line, "msgstr") ) {
msgstr = extractContents( line );
if (!t.atEnd()) {
t.skipWhiteSpace();
line = t.readLine();
}
else
line = QString::null;
while ( hasHandle( line, "\"") ) {
msgstr += extractContents( line );
if (!t.atEnd()) {
t.skipWhiteSpace();
line = t.readLine();
}
else
line = QString::null;
}
if ( pass == 1 )
addTranslation( translator, msgid, msgstr);
if ( pass == 0 && msgid.isEmpty() ) {
// Check for the encoding.
int cpos = msgstr.find( "charset=" );
if ( cpos >= 0 ) {
cpos = cpos + 8; //skip "charset="
int i = cpos;
int len = msgstr.length();
while ( i < len && !msgstr[i].isSpace() )
i++;
QString charset = msgstr.mid( cpos, i-cpos );
codec = QTextCodec::codecForName( charset.ascii() );
if ( codec ) {
debug( "PO file character set: %s. Codec: %s",
charset.ascii(), codec->name() );
} else {
debug( "No codec for %s", charset.ascii() );
}
}
break;
}
}
else
line = QString::null;
}
}
f.close();
translator->save( qmfile );
}