SIP4 python bindings for TQt
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
3.2KB

  1. /**********************************************************************
  2. ** Copyright (C) 2000 Trolltech AS. All rights reserved.
  3. **
  4. ** merge.cpp
  5. **
  6. ** This file is part of TQt Linguist.
  7. **
  8. ** See the file LICENSE included in the distribution for the usage
  9. ** and distribution terms.
  10. **
  11. ** The file is provided AS IS with NO WARRANTY OF ANY KIND,
  12. ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR
  13. ** A PARTICULAR PURPOSE.
  14. **
  15. **********************************************************************/
  16. #include <metatranslator.h>
  17. // defined in numberh.cpp
  18. extern void applyNumberHeuristic( MetaTranslator *tor, bool verbose );
  19. // defined in sametexth.cpp
  20. extern void applySameTextHeuristic( MetaTranslator *tor, bool verbose );
  21. typedef TQValueList<MetaTranslatorMessage> TML;
  22. /*
  23. Merges two MetaTranslator objects into the first one. The first one is a set
  24. of source texts and translations for a previous version of the
  25. internationalized program; the second one is a set of fresh source text newly
  26. extracted from the source code, without any translation yet.
  27. */
  28. void merge( MetaTranslator *tor, const MetaTranslator *virginTor, bool verbose )
  29. {
  30. int known = 0;
  31. int neww = 0;
  32. int obsoleted = 0;
  33. TML all = tor->messages();
  34. TML::Iterator it;
  35. /*
  36. The types of all the messages from the vernacular translator are updated
  37. according to the virgin translator.
  38. */
  39. for ( it = all.begin(); it != all.end(); ++it ) {
  40. MetaTranslatorMessage::Type newType = MetaTranslatorMessage::Unfinished;
  41. MetaTranslatorMessage m = *it;
  42. // skip context comment
  43. if ( !TQCString((*it).sourceText()).isEmpty() ) {
  44. if ( !virginTor->contains((*it).context(), (*it).sourceText(),
  45. (*it).comment()) ) {
  46. newType = MetaTranslatorMessage::Obsolete;
  47. if ( m.type() != MetaTranslatorMessage::Obsolete )
  48. obsoleted++;
  49. } else {
  50. switch ( m.type() ) {
  51. case MetaTranslatorMessage::Finished:
  52. newType = MetaTranslatorMessage::Finished;
  53. known++;
  54. break;
  55. case MetaTranslatorMessage::Unfinished:
  56. newType = MetaTranslatorMessage::Unfinished;
  57. known++;
  58. break;
  59. case MetaTranslatorMessage::Obsolete:
  60. newType = MetaTranslatorMessage::Unfinished;
  61. neww++;
  62. }
  63. }
  64. if ( newType != m.type() ) {
  65. m.setType( newType );
  66. tor->insert( m );
  67. }
  68. }
  69. }
  70. /*
  71. Messages found only in the virgin translator are added to the
  72. vernacular translator. Among these are all the context comments.
  73. */
  74. all = virginTor->messages();
  75. for ( it = all.begin(); it != all.end(); ++it ) {
  76. if ( !tor->contains((*it).context(), (*it).sourceText(),
  77. (*it).comment()) ) {
  78. tor->insert( *it );
  79. if ( !TQCString((*it).sourceText()).isEmpty() )
  80. neww++;
  81. }
  82. }
  83. /*
  84. The same-text heuristic handles cases where a message has an
  85. obsolete counterpart with a different context or comment.
  86. */
  87. applySameTextHeuristic( tor, verbose );
  88. /*
  89. The number heuristic handles cases where a message has an
  90. obsolete counterpart with mostly numbers differing in the
  91. source text.
  92. */
  93. applyNumberHeuristic( tor, verbose );
  94. if ( verbose )
  95. qWarning( " %d known, %d new and %d obsoleted messages",
  96. known, neww, obsoleted );
  97. }