/*
  Augments a MetaTranslator with translations easily derived from
  similar existing (probably obsolete) translations.

  For example, if "TeX 3.0" is translated as "XeT 3.0" and "TeX 3.1"
  has no translation, "XeT 3.1" is added to the translator and is
  marked Unfinished.
*/
void applyNumberHeuristic( MetaTranslator* tor, bool verbose )
{
	TMM translated, untranslated;
	TMM::Iterator t, u;
	TML all = tor->messages();
	TML::Iterator it;
	int inserted = 0;

	for ( it = all.begin(); it != all.end(); ++it )
	{
		if ( ( *it ).type() == MetaTranslatorMessage::Unfinished )
		{
			if ( ( *it ).translation().isEmpty() )
				untranslated.insert( QCString( ( *it ).context() ) + "\n" + ( *it ).sourceText() + "\n" + ( *it ).comment(), *it );
		}
		else if ( !( *it ).translation().isEmpty() )
		{
			translated.insert( zeroKey( ( *it ).sourceText() ), *it );
		}
	}

	for ( u = untranslated.begin(); u != untranslated.end(); ++u )
	{
		t = translated.find( zeroKey( ( *u ).sourceText() ) );
		if ( t != translated.end() && !t.key().isEmpty() && qstrcmp( ( *t ).sourceText(), ( *u ).sourceText() ) != 0 )
		{
			MetaTranslatorMessage m( *u );
			m.setTranslation( translationAttempt( ( *t ).translation(), ( *t ).sourceText(), ( *u ).sourceText() ) );
			tor->insert( m );
			inserted++;
		}
	}
	if ( verbose && inserted != 0 )
		fprintf( stderr, " number heuristic provided %d translation%s\n", inserted, inserted == 1 ? "" : "s" );
}
Beispiel #2
0
/*
  Augments a MetaTranslator with translations easily derived from
  similar existing (probably obsolete) translations.

  For example, if "TeX 3.0" is translated as "XeT 3.0" and "TeX 3.1"
  has no translation, "XeT 3.1" is added to the translator and is
  marked Unfinished.

  Returns the number of additional messages that this heuristic translated.
*/
int applyNumberHeuristic( MetaTranslator *tor )
{
    TMM translated, untranslated;
    TMM::Iterator t, u;
    TML all = tor->messages();
    TML::Iterator it;
    int inserted = 0;

    for ( it = all.begin(); it != all.end(); ++it ) {
        bool hasTranslation = (*it).isTranslated();
        if ( (*it).type() == MetaTranslatorMessage::Unfinished ) {
            if ( !hasTranslation )
                untranslated.insert(QByteArray((*it).context()) + "\n" + (*it).sourceText() + "\n"
                                    + (*it).comment(), *it);
        } else if ( hasTranslation && (*it).translations().count() == 1 ) {
            translated.insert( zeroKey((*it).sourceText()), *it );
        }
    }

    for ( u = untranslated.begin(); u != untranslated.end(); ++u ) {
        t = translated.find( zeroKey((*u).sourceText()) );
        if ( t != translated.end() && !t.key().isEmpty() &&
             qstrcmp((*t).sourceText(), (*u).sourceText()) != 0 ) {
            MetaTranslatorMessage m( *u );
            m.setTranslation(translationAttempt((*t).translation(), (*t).sourceText(),
                                                (*u).sourceText()));
            tor->insert( m );
            inserted++;
        }
    }
    return inserted;
}