本文整理汇总了C++中TranslatorMessage::context方法的典型用法代码示例。如果您正苦于以下问题:C++ TranslatorMessage::context方法的具体用法?C++ TranslatorMessage::context怎么用?C++ TranslatorMessage::context使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TranslatorMessage
的用法示例。
在下文中一共展示了TranslatorMessage::context方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: makeMsgId
static QString makeMsgId(const TranslatorMessage &msg)
{
QString id = msg.context() + QLatin1String("//") + elidedId(msg.sourceText(), 100);
if (!msg.comment().isEmpty())
id += QLatin1String("//") + elidedId(msg.comment(), 30);
return id;
}
示例2: addIndex
void Translator::addIndex(int idx, const TranslatorMessage &msg) const
{
if (msg.sourceText().isEmpty() && msg.id().isEmpty()) {
m_ctxCmtIdx[msg.context()] = idx;
} else {
m_msgIdx[TMMKey(msg)] = idx;
if (!msg.id().isEmpty())
m_idMsgIdx[msg.id()] = idx;
}
}
示例3: appendSorted
void Translator::appendSorted(const TranslatorMessage &msg)
{
int msgLine = msg.lineNumber();
if (msgLine < 0) {
append(msg);
return;
}
int bestIdx = 0; // Best insertion point found so far
int bestScore = 0; // Its category: 0 = no hit, 1 = pre or post, 2 = middle
int bestSize = 0; // The length of the region. Longer is better within one category.
// The insertion point to use should this region turn out to be the best one so far
int thisIdx = 0;
int thisScore = 0;
int thisSize = 0;
// Working vars
int prevLine = 0;
int curIdx = 0;
foreach (const TranslatorMessage &mit, m_messages) {
bool sameFile = mit.fileName() == msg.fileName() && mit.context() == msg.context();
int curLine;
if (sameFile && (curLine = mit.lineNumber()) >= prevLine) {
if (msgLine >= prevLine && msgLine < curLine) {
thisIdx = curIdx;
thisScore = thisSize ? 2 : 1;
}
++thisSize;
prevLine = curLine;
} else {
if (thisSize) {
if (!thisScore) {
thisIdx = curIdx;
thisScore = 1;
}
if (thisScore > bestScore || (thisScore == bestScore && thisSize > bestSize)) {
bestIdx = thisIdx;
bestScore = thisScore;
bestSize = thisSize;
}
thisScore = 0;
thisSize = sameFile ? 1 : 0;
prevLine = 0;
}
}
++curIdx;
}
示例4: saveXLIFF
bool MetaTranslator::saveXLIFF( const QString& filename) const
{
QFile f( filename );
if ( !f.open(QIODevice::WriteOnly | QIODevice::Text) )
return false;
int indent = 2;
int currentindent = 0;
QTextStream t( &f );
t.setCodec( QTextCodec::codecForName("ISO-8859-1") );
QMap<QString, TranslatorMessage> mtSortByFileName;
TMM::ConstIterator m = mm.begin();
while ( m != mm.end() ) {
TranslatorMessage msg = m.key();
QString location = msg.fileName() + QLatin1String(msg.context()) + QString::number(msg.lineNumber());
mtSortByFileName.insertMulti(location, msg);
++m;
}
t.setFieldAlignment(QTextStream::AlignRight);
t << "<?xml version=\"1.0\"";
t << " encoding=\"utf-8\"?>\n";
t << "<xliff version=\"1.1\" xmlns=\"" << XLIFF11namespaceURI << "\">\n";
currentindent += indent;
QMap<QString, TranslatorMessage>::iterator mi = mtSortByFileName.begin();
TranslatorMessage msg;
QByteArray ctx;
QString fn;
bool ctxdiffer = false;
bool filediffer = false;
while (mi != mtSortByFileName.end()) {
msg = mi.value();
ctxdiffer = msg.context() != ctx;
filediffer = msg.fileName() != fn;
if (ctxdiffer || filediffer) {
if (!ctx.isEmpty()) {
writeIndent(&t, currentindent);
t << "</group>\n";
currentindent -= indent;
}
}
if (filediffer) {
if (!fn.isEmpty()) {
writeIndent(&t, currentindent);
t << "</body></file>\n";
currentindent -= indent;
}
fn = msg.fileName();
writeIndent(&t, currentindent);
t << "<file original=\"" << fn << "\""
<< " datatype=\"" << dataType(msg) << "\""
<< " source-language=\"" << "en" << "\"" //###
<< " target-language=\"" << languageCode() << "\""
<< "><body>\n";
currentindent += indent;
}
if (ctxdiffer || filediffer) {
ctx = msg.context();
writeIndent(&t, currentindent);
t << "<group restype=\"" << restypeContext << "\""
<< " resname=\"" << evilBytes(ctx, msg.utf8()) << "\""
<< ">\n";
currentindent += indent;
}
writeMessage(&t, msg, currentindent, m_language);
++mi;
}
currentindent-=indent;
writeIndent(&t, currentindent);
t << "</group>\n";
currentindent-=indent;
writeIndent(&t, currentindent);
t << "</body></file>\n";
t << "</xliff>\n";
f.close();
return true;
}