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.

79 lines
2.2KB

  1. /**********************************************************************
  2. ** Copyright (C) 2000 Trolltech AS. All rights reserved.
  3. **
  4. ** sametexth.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 <qcstring.h>
  17. #include <qmap.h>
  18. #include <metatranslator.h>
  19. typedef TQMap<TQCString, MetaTranslatorMessage> TMM;
  20. typedef TQValueList<MetaTranslatorMessage> TML;
  21. /*
  22. Augments a MetaTranslator with trivially derived translations.
  23. For example, if "Enabled:" is consistendly translated as "Eingeschaltet:" no
  24. matter the context or the comment, "Eingeschaltet:" is added as the
  25. translation of any untranslated "Enabled:" text and is marked Unfinished.
  26. */
  27. void applySameTextHeuristic( MetaTranslator *tor, bool verbose )
  28. {
  29. TMM translated, avoid;
  30. TMM::Iterator t;
  31. TML untranslated;
  32. TML::Iterator u;
  33. TML all = tor->messages();
  34. TML::Iterator it;
  35. int inserted = 0;
  36. for ( it = all.begin(); it != all.end(); ++it ) {
  37. if ( (*it).type() == MetaTranslatorMessage::Unfinished ) {
  38. if ( (*it).translation().isEmpty() )
  39. untranslated.append( *it );
  40. } else {
  41. TQCString key = (*it).sourceText();
  42. t = translated.find( key );
  43. if ( t != translated.end() ) {
  44. /*
  45. The same source text is translated at least two
  46. different ways. Do nothing then.
  47. */
  48. if ( (*t).translation() != (*it).translation() ) {
  49. translated.remove( key );
  50. avoid.insert( key, *it );
  51. }
  52. } else if ( !avoid.contains(key) ) {
  53. translated.insert( key, *it );
  54. }
  55. }
  56. }
  57. for ( u = untranslated.begin(); u != untranslated.end(); ++u ) {
  58. TQCString key = (*u).sourceText();
  59. t = translated.find( key );
  60. if ( t != translated.end() ) {
  61. MetaTranslatorMessage m( *u );
  62. m.setTranslation( (*t).translation() );
  63. tor->insert( m );
  64. inserted++;
  65. }
  66. }
  67. if ( verbose && inserted != 0 )
  68. qWarning( " same-text heuristic provided %d translation%s",
  69. inserted, inserted == 1 ? "" : "s" );
  70. }