}
static void updateTsFiles(const Translator &fetchedTor, const QStringList &tsFileNames,
+ const QStringList &alienFiles,
bool setCodec, const QString &sourceLanguage, const QString &targetLanguage,
UpdateOptions options, bool *fail)
{
+ QList<Translator> aliens;
+ foreach (const QString &fileName, alienFiles) {
+ ConversionData cd;
+ Translator tor;
+ if (!tor.load(fileName, cd, QLatin1String("auto"))) {
+ printErr(cd.error());
+ *fail = true;
+ continue;
+ }
+ tor.resolveDuplicates();
+ aliens << tor;
+ }
+
QDir dir;
QString err;
foreach (const QString &fileName, tsFileNames) {
UpdateOptions theseOptions = options;
if (tor.locationsType() == Translator::NoLocations) // Could be set from file
theseOptions |= NoLocations;
- Translator out = merge(tor, fetchedTor, theseOptions, err);
+ Translator out = merge(tor, fetchedTor, aliens, theseOptions, err);
if (setCodec)
out.setCodec(fetchedTor.codec());
}
processProject(false, proFile, option, parser, visitor, options, codecForSource,
targetLanguage, sourceLanguage, &tor, fail);
- updateTsFiles(tor, tsFiles, setCodec, sourceLanguage, targetLanguage, options, fail);
+ updateTsFiles(tor, tsFiles, QStringList(),
+ setCodec, sourceLanguage, targetLanguage, options, fail);
pro->deref();
continue;
}
QSet<QString> projectRoots;
QStringList sourceFiles;
QStringList includePath;
+ QStringList alienFiles;
QString targetLanguage;
QString sourceLanguage;
QByteArray codecForTr;
}
}
} else {
+ foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) {
+ if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) {
+ alienFiles << file;
+ goto gotfile;
+ }
+ }
sourceFiles << QDir::cleanPath(fi.absoluteFilePath());;
projectRoots.insert(fi.absolutePath() + QLatin1Char('/'));
}
}
+ gotfile:
numFiles++;
}
} // for args
cd.m_allCSources = allCSources;
fetchedTor.setCodecName(codecForTr);
processSources(fetchedTor, sourceFiles, cd);
- updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(),
+ updateTsFiles(fetchedTor, tsFileNames, alienFiles, !codecForTr.isEmpty(),
sourceLanguage, targetLanguage, options, &fail);
} else {
if (!sourceFiles.isEmpty() || !includePath.isEmpty()) {
fetchedTor.setCodecName(codecForTr);
processProjects(true, true, proFiles, outDirMap, &option, &parser, options, QByteArray(),
targetLanguage, sourceLanguage, &fetchedTor, &fail);
- updateTsFiles(fetchedTor, tsFileNames, !codecForTr.isEmpty(),
+ updateTsFiles(fetchedTor, tsFileNames, alienFiles, !codecForTr.isEmpty(),
sourceLanguage, targetLanguage, options, &fail);
} else {
processProjects(true, false, proFiles, outDirMap, &option, &parser, options, QByteArray(),
translation yet.
*/
-Translator merge(const Translator &tor, const Translator &virginTor,
+Translator merge(
+ const Translator &tor, const Translator &virginTor, const QList<Translator> &aliens,
UpdateOptions options, QString &err)
{
int known = 0;
}
/*
+ "Alien" translators can be used to augment the vernacular translator.
+ */
+ foreach (const Translator &alf, aliens) {
+ foreach (TranslatorMessage mv, alf.messages()) {
+ if (mv.sourceText().isEmpty() || !mv.isTranslated())
+ continue;
+ int mvi = outTor.find(mv);
+ if (mvi >= 0) {
+ TranslatorMessage &tm = outTor.message(mvi);
+ if (tm.type() != TranslatorMessage::Finished && !tm.isTranslated()) {
+ tm.setTranslations(mv.translations());
+ --neww;
+ ++known;
+ }
+ } else {
+ /*
+ * Don't do simtex search, as the locations are likely to be
+ * completely off anyway, so we'd find nothing.
+ */
+ /*
+ * Add the unmatched messages as obsoletes, so the Linguist GUI
+ * will offer them as possible translations.
+ */
+ mv.clearReferences();
+ mv.setType(TranslatorMessage::Obsolete);
+ if (options & NoLocations)
+ outTor.append(mv);
+ else
+ outTor.appendSorted(mv);
+ ++known;
+ ++obsoleted;
+ }
+ }
+ }
+
+ /*
The same-text heuristic handles cases where a message has an
obsolete counterpart with a different context or comment.
*/