1
/****************************************************************************
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
5
** This file is part of the linguist application of the Qt Toolkit.
7
** This file may be distributed under the terms of the Q Public License
8
** as defined by Trolltech AS of Norway and appearing in the file
9
** LICENSE.QPL included in the packaging of this file.
11
** This file may be distributed and/or modified under the terms of the
12
** GNU General Public License version 2 as published by the Free Software
13
** Foundation and appearing in the file LICENSE.GPL included in the
14
** packaging of this file.
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
17
** information about Qt Commercial License Agreements.
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
21
** Contact info@trolltech.com if any conditions of this licensing are
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27
****************************************************************************/
29
#include <metatranslator.h>
32
// defined in numberh.cpp
33
extern void applyNumberHeuristic( MetaTranslator *tor, bool verbose );
34
// defined in sametexth.cpp
35
extern void applySameTextHeuristic( MetaTranslator *tor, bool verbose );
37
typedef QList<MetaTranslatorMessage> TML;
40
Merges two MetaTranslator objects into the first one. The first one
41
is a set of source texts and translations for a previous version of
42
the internationalized program; the second one is a set of fresh
43
source texts newly extracted from the source code, without any
47
void merge( MetaTranslator *tor, const MetaTranslator *virginTor, bool verbose )
52
TML all = tor->messages();
56
The types of all the messages from the vernacular translator
57
are updated according to the virgin translator.
59
for ( it = all.begin(); it != all.end(); ++it ) {
60
MetaTranslatorMessage::Type newType;
61
MetaTranslatorMessage m = *it;
63
// skip context comment
64
if ( !QByteArray((*it).sourceText()).isEmpty() ) {
65
if ( !virginTor->contains((*it).context(), (*it).sourceText(),
67
newType = MetaTranslatorMessage::Obsolete;
68
if ( m.type() != MetaTranslatorMessage::Obsolete )
72
case MetaTranslatorMessage::Finished:
73
newType = MetaTranslatorMessage::Finished;
76
case MetaTranslatorMessage::Unfinished:
77
newType = MetaTranslatorMessage::Unfinished;
80
case MetaTranslatorMessage::Obsolete:
81
newType = MetaTranslatorMessage::Unfinished;
86
if ( newType != m.type() ) {
94
Messages found only in the virgin translator are added to the
95
vernacular translator. Among these are all the context comments.
97
all = virginTor->messages();
99
for ( it = all.begin(); it != all.end(); ++it ) {
100
if ( !tor->contains((*it).context(), (*it).sourceText(),
103
if ( !QByteArray((*it).sourceText()).isEmpty() )
109
The same-text heuristic handles cases where a message has an
110
obsolete counterpart with a different context or comment.
112
applySameTextHeuristic( tor, verbose );
115
The number heuristic handles cases where a message has an
116
obsolete counterpart with mostly numbers differing in the
119
applyNumberHeuristic( tor, verbose );
122
fprintf( stderr, " %d known, %d new, and %d obsoleted messages\n", known,