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; }
static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames, bool setCodec, 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"))) { printErr(cd.error()); *fail = true; continue; } tor.resolveDuplicates(); cd.clearErrors(); if (setCodec && fetchedTor.codec() != tor.codec()) printErr(LU::tr("lupdate warning: Codec for tr() '%1' disagrees with" " existing file's codec '%2'. Expect trouble.\n") .arg(QString::fromLatin1(fetchedTor.codecName()), QString::fromLatin1(tor.codecName()))); if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode()) printErr(LU::tr("lupdate warning: Specified target language '%1' disagrees with" " existing file's language '%2'. Ignoring.\n") .arg(targetLanguage, tor.languageCode())); if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode()) printErr(LU::tr("lupdate warning: Specified source language '%1' disagrees with" " existing file's language '%2'. Ignoring.\n") .arg(sourceLanguage, tor.sourceLanguageCode())); } else { if (setCodec) tor.setCodec(fetchedTor.codec()); if (!targetLanguage.isEmpty()) tor.setLanguageCode(targetLanguage); else tor.setLanguageCode(Translator::guessLanguageCodeFromFileName(fileName)); 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(LU::tr("Updating '%1'...\n").arg(fn)); UpdateOptions theseOptions = options; if (tor.locationsType() == Translator::NoLocations) // Could be set from file theseOptions |= NoLocations; Translator out = merge(tor, fetchedTor, theseOptions, err); if (setCodec) out.setCodec(fetchedTor.codec()); if ((options & Verbose) && !err.isEmpty()) { printOut(err); err.clear(); } if (options & PluralOnly) { if (options & Verbose) printOut(LU::tr("Stripping non plural forms in '%1'...\n").arg(fn)); out.stripNonPluralForms(); } if (options & NoObsolete) out.stripObsoleteMessages(); out.stripEmptyContexts(); out.normalizeTranslations(cd); if (!cd.errors().isEmpty()) { printErr(cd.error()); cd.clearErrors(); } if (!out.save(fileName, cd, QLatin1String("auto"))) { printErr(cd.error()); *fail = true; } }
UiReader(Translator &translator, ConversionData &cd) : m_translator(translator), m_cd(cd), m_lineNumber(-1), m_isTrString(false), m_needUtf8(translator.codecName() != "UTF-8") {}