本文整理汇总了C++中Translator::setCodecName方法的典型用法代码示例。如果您正苦于以下问题:C++ Translator::setCodecName方法的具体用法?C++ Translator::setCodecName怎么用?C++ Translator::setCodecName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Translator
的用法示例。
在下文中一共展示了Translator::setCodecName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadJava
bool loadJava(Translator &translator, const QString &filename, ConversionData &cd)
{
QFile file(filename);
if (!file.open(QIODevice::ReadOnly)) {
cd.appendError(QString::fromLatin1("Cannot open %1: %2")
.arg(filename, file.errorString()));
return false;
}
yyDefaultContext = cd.m_defaultContext;
yyInPos = -1;
yyFileName = filename;
yyPackage.clear();
yyScope.clear();
yyTok = -1;
yyParenDepth = 0;
yyCurLineNo = 0;
yyParenLineNo = 1;
QTextStream ts(&file);
QByteArray codecName;
if (!cd.m_codecForSource.isEmpty())
codecName = cd.m_codecForSource;
else
codecName = translator.codecName(); // Just because it should be latin1 already
ts.setCodec(QTextCodec::codecForName(codecName));
ts.setAutoDetectUnicode(true);
yyInStr = ts.readAll();
yyInPos = 0;
yyFileName = filename;
yyCurLineNo = 1;
yyParenLineNo = 1;
parse(&translator);
// Java uses UTF-16 internally and Jambi makes UTF-8 for tr() purposes of it.
translator.setCodecName("UTF-8");
return true;
}
示例2: read
bool TSReader::read(Translator &translator)
{
STRING(both);
STRING(byte);
STRING(comment);
STRING(context);
STRING(defaultcodec);
STRING(encoding);
STRING(extracomment);
STRING(filename);
STRING(id);
STRING(language);
STRING(line);
STRING(location);
STRING(message);
STRING(name);
STRING(numerus);
STRING(numerusform);
STRING(obsolete);
STRING(oldcomment);
STRING(oldsource);
STRING(source);
STRING(sourcelanguage);
STRING(translation);
STRING(translatorcomment);
STRING(true);
STRING(TS);
STRING(type);
STRING(unfinished);
STRING(userdata);
STRING(utf8);
STRING(value);
//STRING(version);
STRING(yes);
static const QString strextrans(QLatin1String("extra-"));
static const QString strUtf8(QLatin1String("UTF-8"));
while (!atEnd()) {
readNext();
if (isStartDocument()) {
// <!DOCTYPE TS>
//qDebug() << attributes();
} else if (isEndDocument()) {
// <!DOCTYPE TS>
//qDebug() << attributes();
} else if (isDTD()) {
// <!DOCTYPE TS>
//qDebug() << tokenString();
} else if (elementStarts(strTS)) {
// <TS>
//qDebug() << "TS " << attributes();
QHash<QString, int> currentLine;
QString currentFile;
QXmlStreamAttributes atts = attributes();
//QString version = atts.value(strversion).toString();
translator.setLanguageCode(atts.value(strlanguage).toString());
translator.setSourceLanguageCode(atts.value(strsourcelanguage).toString());
while (!atEnd()) {
readNext();
if (isEndElement()) {
// </TS> found, finish local loop
break;
} else if (isWhiteSpace()) {
// ignore these, just whitespace
} else if (elementStarts(strdefaultcodec)) {
// <defaultcodec>
const QString &codec = readElementText();
if (!codec.isEmpty())
translator.setCodecName(codec.toLatin1());
// </defaultcodec>
} else if (isStartElement()
&& name().toString().startsWith(strextrans)) {
// <extra-...>
QString tag = name().toString();
translator.setExtra(tag.mid(6), readContents());
// </extra-...>
} else if (elementStarts(strcontext)) {
// <context>
QString context;
while (!atEnd()) {
readNext();
if (isEndElement()) {
// </context> found, finish local loop
break;
} else if (isWhiteSpace()) {
// ignore these, just whitespace
} else if (elementStarts(strname)) {
// <name>
context = readElementText();
// </name>
} else if (elementStarts(strmessage)) {
// <message>
TranslatorMessage::References refs;
QString currentMsgFile = currentFile;
TranslatorMessage msg;
msg.setId(attributes().value(strid).toString());
msg.setContext(context);
//.........这里部分代码省略.........
示例3: updateTsFiles
static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames,
const QByteArray &codecForTr, const QString &sourceLanguage, const QString &targetLanguage,
UpdateOptions options, bool *fail)
{
QDir dir;
QString err;
foreach (const QString &fileName, tsFileNames) {
QString fn = dir.relativeFilePath(fileName);
ConversionData cd;
Translator tor;
cd.m_sortContexts = !(options & NoSort);
if (QFile(fileName).exists()) {
if (!tor.load(fileName, cd, QLatin1String("auto"))) {
qWarning( "%s", qPrintable( cd.error() ) );
*fail = true;
continue;
}
tor.resolveDuplicates();
cd.clearErrors();
if (!codecForTr.isEmpty() && codecForTr != tor.codecName())
qWarning("lupdate warning: Codec for tr() '%s' disagrees with "
"existing file's codec '%s'. Expect trouble.",
codecForTr.constData(), tor.codecName().constData());
if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode())
qWarning("lupdate warning: Specified target language '%s' disagrees with "
"existing file's language '%s'. Ignoring.",
qPrintable(targetLanguage), qPrintable(tor.languageCode()));
if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode())
qWarning("lupdate warning: Specified source language '%s' disagrees with "
"existing file's language '%s'. Ignoring.",
qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode()));
} else {
if (!codecForTr.isEmpty())
tor.setCodecName(codecForTr);
if (!targetLanguage.isEmpty())
tor.setLanguageCode(targetLanguage);
if (!sourceLanguage.isEmpty())
tor.setSourceLanguageCode(sourceLanguage);
}
tor.makeFileNamesAbsolute(QFileInfo(fileName).absoluteDir());
if (options & NoLocations)
tor.setLocationsType(Translator::NoLocations);
else if (options & RelativeLocations)
tor.setLocationsType(Translator::RelativeLocations);
else if (options & AbsoluteLocations)
tor.setLocationsType(Translator::AbsoluteLocations);
if (options & Verbose)
printOut(QObject::tr("Updating '%1'...\n").arg(fn));
if (tor.locationsType() == Translator::NoLocations) // Could be set from file
options |= NoLocations;
Translator out = merge(tor, fetchedTor, options, err);
if (!codecForTr.isEmpty())
out.setCodecName(codecForTr);
if ((options & Verbose) && !err.isEmpty()) {
printOut( qPrintable( err ) );
err.clear();
}
if (options & PluralOnly) {
if (options & Verbose)
printOut(QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn));
out.stripNonPluralForms();
}
if (options & NoObsolete)
out.stripObsoleteMessages();
out.stripEmptyContexts();
if (!out.save(fileName, cd, QLatin1String("auto"))) {
qWarning( "%s", qPrintable( cd.error() ) );
*fail = true;
}
}