82 UpdateOptions options, QString &err)
87 int similarTextHeuristicCount = 0;
90 outTor.setLanguageCode(tor.languageCode());
91 outTor.setSourceLanguageCode(tor.sourceLanguageCode());
95
96
97
98 for (TranslatorMessage m : tor.messages()) {
99 TranslatorMessage::Type newType = TranslatorMessage::Finished;
101 if (m.sourceText().isEmpty() && m.id().isEmpty()) {
103 int mvi = virginTor.find(m.context());
105 m.setComment(virginTor.constMessage(mvi).comment());
107 TranslatorMessage::ExtraData extras;
108 const TranslatorMessage *mv;
109 int mvi = virginTor.find(m);
111 if (!(options & HeuristicSimilarText)) {
114 case TranslatorMessage::Finished:
115 newType = TranslatorMessage::Vanished;
118 case TranslatorMessage::Unfinished:
119 newType = TranslatorMessage::Obsolete;
128 mvi = virginTor.find(m.context(), m.comment(), m.allReferences());
133 mv = &virginTor.constMessage(mvi);
138 if (getSimilarityScore(m.sourceText(), mv->sourceText()) < textSimilarityThreshold) {
144 extras = mv->extras();
148 newType = TranslatorMessage::Unfinished;
149 ++similarTextHeuristicCount;
154 mv = &virginTor.message(mvi);
155 extras = mv->extras();
156 if (!mv->id().isEmpty()
157 && (mv->context() != m.context()
158 || mv->sourceText() != m.sourceText()
159 || mv->comment() != m.comment())) {
161 newType = TranslatorMessage::Unfinished;
162 m.setContext(mv->context());
163 m.setComment(mv->comment());
164 if (mv->sourceText() != m.sourceText()) {
166 m.setOldSourceText(m.sourceText());
167 m.setSourceText(mv->sourceText());
168 const QString &oldpluralsource = m.extra(QLatin1String(
"po-msgid_plural"));
169 if (!oldpluralsource.isEmpty())
170 extras.insert(QLatin1String(
"po-old_msgid_plural"), oldpluralsource);
174 case TranslatorMessage::Finished:
176 if (m.isPlural() == mv->isPlural()) {
177 newType = TranslatorMessage::Finished;
179 newType = TranslatorMessage::Unfinished;
183 case TranslatorMessage::Unfinished:
184 newType = TranslatorMessage::Unfinished;
187 case TranslatorMessage::Vanished:
188 newType = TranslatorMessage::Finished;
191 case TranslatorMessage::Obsolete:
192 newType = TranslatorMessage::Unfinished;
203 m.setReferences(mv->allReferences());
204 m.setPlural(mv->isPlural());
206 m.setExtraComment(mv->extraComment());
216
217
218
219 for (
const TranslatorMessage &mv : virginTor.messages()) {
220 if (mv.sourceText().isEmpty() && mv.id().isEmpty()) {
221 if (tor.find(mv.context()) >= 0)
224 if (tor.find(mv) >= 0)
226 if (options & HeuristicSimilarText) {
227 int mi = tor.find(mv.context(), mv.comment(), mv.allReferences());
231 if (virginTor.find(tor.constMessage(mi)) < 0) {
232 if (getSimilarityScore(tor.constMessage(mi).sourceText(), mv.sourceText())
233 >= textSimilarityThreshold)
239 if (options & NoLocations)
242 outTor.appendSorted(mv);
243 if (!mv.sourceText().isEmpty() || !mv.id().isEmpty())
248
249
250 for (
const Translator &alf : aliens) {
251 for (TranslatorMessage mv : alf.messages()) {
252 if (mv.sourceText().isEmpty() || !mv.isTranslated())
254 int mvi = outTor.find(mv);
256 TranslatorMessage &tm = outTor.message(mvi);
257 if (tm.type() != TranslatorMessage::Finished && !tm.isTranslated()) {
258 tm.setTranslations(mv.translations());
264
265
266
268
269
270
271 mv.clearReferences();
272 mv.setType(mv.type() == TranslatorMessage::Finished
273 ? TranslatorMessage::Vanished : TranslatorMessage::Obsolete);
274 if (options & NoLocations)
277 outTor.appendSorted(mv);
285
286
287
291 int totalFound = neww + known;
292 err += QStringLiteral(
" Found %1 source text(s) (%2 new and %3 already existing)\n")
293 .arg(totalFound).arg(neww).arg(known);
297 err += QStringLiteral(
" Removed %1 obsolete entries\n").arg(obsoleted);
299 err += QStringLiteral(
" Kept %1 obsolete entries\n").arg(obsoleted);
303 if (sameTextHeuristicCount)
304 err += QStringLiteral(
" Same-text heuristic provided %1 translation(s)\n")
305 .arg(sameTextHeuristicCount);
306 if (similarTextHeuristicCount)
307 err += QStringLiteral(
" Similar-text heuristic provided %1 translation(s)\n")
308 .arg(similarTextHeuristicCount);