Changeset 846 for trunk/tools/linguist/lupdate
- Timestamp:
- May 5, 2011, 5:36:53 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/vendor/nokia/qt/4.7.2 (added) merged: 845 /branches/vendor/nokia/qt/current merged: 844 /branches/vendor/nokia/qt/4.6.3 removed
- Property svn:mergeinfo changed
-
trunk/tools/linguist/lupdate/cpp.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 51 51 #include <QtCore/QTextCodec> 52 52 #include <QtCore/QTextStream> 53 #include <QtCore/QCoreApplication> 54 55 #include <iostream> 53 56 54 57 #include <ctype.h> // for isXXX() 55 58 56 59 QT_BEGIN_NAMESPACE 60 61 class LU { 62 Q_DECLARE_TR_FUNCTIONS(LUpdate) 63 }; 57 64 58 65 /* qmake ignore Q_OBJECT */ … … 226 233 int elseLine; 227 234 }; 235 236 std::ostream &yyMsg(int line = 0); 228 237 229 238 uint getChar(); … … 353 362 } 354 363 364 365 std::ostream &CppParser::yyMsg(int line) 366 { 367 return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": "; 368 } 369 355 370 void CppParser::setInput(const QString &in) 356 371 { … … 475 490 STRING(friend); 476 491 STRING(namespace); 492 STRING(operator); 477 493 STRING(qtTrId); 478 494 STRING(return); … … 614 630 || yyBraceDepth != is.braceDepth1st 615 631 || yyParenDepth != is.parenDepth1st) 616 qWarning("%s:%d: Parenthesis/bracket/brace mismatch between "617 "#if and #else branches; using #if branch\n",618 qPrintable(yyFileName), is.elseLine);632 yyMsg(is.elseLine) 633 << qPrintable(LU::tr("Parenthesis/bracket/brace mismatch between " 634 "#if and #else branches; using #if branch\n")); 619 635 } else { 620 636 is.bracketDepth1st = yyBracketDepth; … … 637 653 || yyBraceDepth != is.braceDepth1st 638 654 || yyParenDepth != is.parenDepth1st) 639 qWarning("%s:%d: Parenthesis/brace mismatch between "640 "#if and #else branches; using #if branch\n",641 qPrintable(yyFileName), is.elseLine);655 yyMsg(is.elseLine) 656 << qPrintable(LU::tr("Parenthesis/brace mismatch between " 657 "#if and #else branches; using #if branch\n")); 642 658 yyBracketDepth = is.bracketDepth1st; 643 659 yyBraceDepth = is.braceDepth1st; … … 665 681 yyCh = getChar(); 666 682 if (yyCh == EOF) { 667 qWarning("%s:%d: Unterminated C++ comment\n", 668 qPrintable(yyFileName), yyLineNo); 683 yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n")); 669 684 break; 670 685 } … … 740 755 return Tok_namespace; 741 756 break; 757 case 'o': 758 if (yyWord == stroperator) { 759 // Operator overload declaration/definition. 760 // We need to prevent those characters from confusing the followup 761 // parsing. Actually using them does not add value, so just eat them. 762 while (isspace(yyCh)) 763 yyCh = getChar(); 764 while (yyCh == '+' || yyCh == '-' || yyCh == '*' || yyCh == '/' || yyCh == '%' 765 || yyCh == '=' || yyCh == '<' || yyCh == '>' || yyCh == '!' 766 || yyCh == '&' || yyCh == '|' || yyCh == '~' || yyCh == '^' 767 || yyCh == '[' || yyCh == ']') 768 yyCh = getChar(); 769 } 770 break; 742 771 case 'q': 743 772 if (yyWord == strqtTrId) … … 796 825 yyCh = getChar(); 797 826 if (yyCh == EOF) { 798 qWarning("%s:%d: Unterminated C++ comment\n", 799 qPrintable(yyFileName), yyLineNo); 827 yyMsg() << qPrintable(LU::tr("Unterminated C++ comment\n")); 800 828 break; 801 829 } … … 830 858 831 859 if (yyCh != '"') 832 qWarning("%s:%d: Unterminated C++ string\n", 833 qPrintable(yyFileName), yyLineNo); 860 yyMsg() << qPrintable(LU::tr("Unterminated C++ string\n")); 834 861 else 835 862 yyCh = getChar(); … … 868 895 forever { 869 896 if (yyCh == EOF || yyCh == '\n') { 870 qWarning("%s:%d: Unterminated C++ character\n", 871 qPrintable(yyFileName), yyLineNo); 897 yyMsg() << "Unterminated C++ character\n"; 872 898 break; 873 899 } … … 888 914 if (yyBraceDepth == yyMinBraceDepth) { 889 915 if (!inDefine) 890 qWarning("%s:%d: Excess closing brace in C++ code"891 " (or abuse of the C++ preprocessor)\n",892 qPrintable(yyFileName), yyCurLineNo);916 yyMsg(yyCurLineNo) 917 << qPrintable(LU::tr("Excess closing brace in C++ code" 918 " (or abuse of the C++ preprocessor)\n")); 893 919 // Avoid things getting messed up even more 894 920 yyCh = getChar(); … … 906 932 case ')': 907 933 if (yyParenDepth == 0) 908 qWarning("%s:%d: Excess closing parenthesis in C++ code"909 " (or abuse of the C++ preprocessor)\n",910 qPrintable(yyFileName), yyCurLineNo);934 yyMsg(yyCurLineNo) 935 << qPrintable(LU::tr("Excess closing parenthesis in C++ code" 936 " (or abuse of the C++ preprocessor)\n")); 911 937 else 912 938 yyParenDepth--; … … 921 947 case ']': 922 948 if (yyBracketDepth == 0) 923 qWarning("%s:%d: Excess closing bracket in C++ code"924 " (or abuse of the C++ preprocessor)\n",925 qPrintable(yyFileName), yyCurLineNo);949 yyMsg(yyCurLineNo) 950 << qPrintable(LU::tr("Excess closing bracket in C++ code" 951 " (or abuse of the C++ preprocessor)\n")); 926 952 else 927 953 yyBracketDepth--; … … 1291 1317 1292 1318 if (inclusions.contains(cleanFile)) { 1293 qWarning("%s:%d: circular inclusion of %s\n", 1294 qPrintable(yyFileName), yyLineNo, qPrintable(cleanFile)); 1319 yyMsg() << qPrintable(LU::tr("circular inclusion of %1\n").arg(cleanFile)); 1295 1320 return; 1296 1321 } … … 1316 1341 QFile f(cleanFile); 1317 1342 if (!f.open(QIODevice::ReadOnly)) { 1318 qWarning("%s:%d: Cannot open %s: %s\n", 1319 qPrintable(yyFileName), yyLineNo, 1320 qPrintable(cleanFile), qPrintable(f.errorString())); 1343 yyMsg() << qPrintable(LU::tr("Cannot open %1: %2\n").arg(cleanFile, f.errorString())); 1321 1344 return; 1322 1345 } … … 1657 1680 NamespaceList nsl; 1658 1681 if (!fullyQualify(namespaces, quali, true, &nsl, 0)) { 1659 qWarning("%s:%d: Ignoring definition of undeclared qualified class\n", 1660 qPrintable(yyFileName), yyLineNo); 1682 yyMsg() << "Ignoring definition of undeclared qualified class\n"; 1661 1683 break; 1662 1684 } … … 1672 1694 prospectiveContext.clear(); 1673 1695 pendingContext.clear(); 1696 1697 yyTok = getToken(); 1674 1698 } 1675 1699 break; … … 1685 1709 namespaceDepths.push(namespaces.count()); 1686 1710 enterNamespace(&namespaces, ns); 1711 1712 functionContext = namespaces; 1713 functionContextUnresolved.clear(); 1714 prospectiveContext.clear(); 1715 pendingContext.clear(); 1687 1716 yyTok = getToken(); 1688 1717 } else if (yyTok == Tok_Equals) { … … 1758 1787 goto case_default; 1759 1788 if (!sourcetext.isEmpty()) 1760 qWarning("%s:%d: //%% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n", 1761 qPrintable(yyFileName), yyLineNo); 1789 yyMsg() << qPrintable(LU::tr("//% cannot be used with tr() / QT_TR_NOOP(). Ignoring\n")); 1762 1790 utf8 = (yyTok == Tok_trUtf8); 1763 1791 line = yyLineNo; … … 1780 1808 if (!fullyQualify(namespaces, pendingContext, true, &functionContext, &unresolved)) { 1781 1809 functionContextUnresolved = unresolved.join(strColons); 1782 qWarning("%s:%d: Qualifying with unknown namespace/class %s::%s\n", 1783 qPrintable(yyFileName), yyLineNo, 1784 qPrintable(stringifyNamespace(functionContext)), 1785 qPrintable(unresolved.first())); 1810 yyMsg() << qPrintable(LU::tr("Qualifying with unknown namespace/class %1::%2\n") 1811 .arg(stringifyNamespace(functionContext)).arg(unresolved.first())); 1786 1812 } 1787 1813 pendingContext.clear(); … … 1791 1817 int idx = functionContext.length(); 1792 1818 if (idx < 2) { 1793 qWarning("%s:%d: tr() cannot be called without context\n", 1794 qPrintable(yyFileName), yyLineNo); 1819 yyMsg() << qPrintable(LU::tr("tr() cannot be called without context\n")); 1795 1820 break; 1796 1821 } … … 1801 1826 fctx = findNamespace(functionContext)->classDef; 1802 1827 if (!fctx->complained) { 1803 qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", 1804 qPrintable(yyFileName), yyLineNo, 1805 qPrintable(context)); 1828 yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n") 1829 .arg(context)); 1806 1830 fctx->complained = true; 1807 1831 } … … 1831 1855 QString className = prefix.mid(last == -1 ? 0 : last + 2); 1832 1856 if (!className.isEmpty() && className == functionName) { 1833 qWarning("%s::%d: It is not recommended to call tr() from within a constructor '%s::%s' ", 1834 qPrintable(yyFileName), yyLineNo, 1835 className.constData(), functionName.constData()); 1857 yyMsg() << qPrintable(LU::tr("It is not recommended to call tr() from within a constructor '%1::%2'\n") 1858 .arg(className).arg(functionName)); 1836 1859 } 1837 1860 #endif … … 1848 1871 } 1849 1872 if (!fctx->hasTrFunctions && !fctx->complained) { 1850 qWarning("%s:%d: Class '%s' lacks Q_OBJECT macro\n", 1851 qPrintable(yyFileName), yyLineNo, 1852 qPrintable(context)); 1873 yyMsg() << qPrintable(LU::tr("Class '%1' lacks Q_OBJECT macro\n").arg(context)); 1853 1874 fctx->complained = true; 1854 1875 } … … 1862 1883 recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural); 1863 1884 } 1885 sourcetext.clear(); // Will have warned about that already 1864 1886 extracomment.clear(); 1865 1887 msgid.clear(); … … 1871 1893 goto case_default; 1872 1894 if (!sourcetext.isEmpty()) 1873 qWarning("%s:%d: //%% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n", 1874 qPrintable(yyFileName), yyLineNo); 1895 yyMsg() << qPrintable(LU::tr("//% cannot be used with translate() / QT_TRANSLATE_NOOP(). Ignoring\n")); 1875 1896 utf8 = (yyTok == Tok_translateUtf8); 1876 1897 line = yyLineNo; … … 1918 1939 recordMessage(line, context, text, comment, extracomment, msgid, extra, utf8, plural); 1919 1940 } 1941 sourcetext.clear(); // Will have warned about that already 1920 1942 extracomment.clear(); 1921 1943 msgid.clear(); … … 1926 1948 goto case_default; 1927 1949 if (!msgid.isEmpty()) 1928 qWarning("%s:%d: //= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n", 1929 qPrintable(yyFileName), yyLineNo); 1950 yyMsg() << qPrintable(LU::tr("//= cannot be used with qtTrId() / QT_TRID_NOOP(). Ignoring\n")); 1930 1951 //utf8 = false; // Maybe use //%% or something like that 1931 1952 line = yyLineNo; … … 1994 2015 continue; 1995 2016 if (c != '"') { 1996 qWarning("%s:%d: Unexpected character in meta string\n", 1997 qPrintable(yyFileName), yyLineNo); 2017 yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n")); 1998 2018 break; 1999 2019 } … … 2001 2021 if (p >= yyWord.length()) { 2002 2022 whoops: 2003 qWarning("%s:%d: Unterminated meta string\n", 2004 qPrintable(yyFileName), yyLineNo); 2023 yyMsg() << qPrintable(LU::tr("Unterminated meta string\n")); 2005 2024 break; 2006 2025 } … … 2055 2074 yyTok = getToken(); 2056 2075 if (yyTok == Tok_tr || yyTok == Tok_trUtf8) 2057 qWarning("%s:%d: Cannot invoke tr() like this\n", 2058 qPrintable(yyFileName), yyLineNo); 2076 yyMsg() << qPrintable(LU::tr("Cannot invoke tr() like this\n")); 2059 2077 break; 2060 2078 case Tok_ColonColon: … … 2088 2106 prospectiveContext.clear(); 2089 2107 prefix.clear(); 2090 extracomment.clear(); 2091 msgid.clear(); 2092 extra.clear(); 2108 if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) { 2109 yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n")); 2110 sourcetext.clear(); 2111 extracomment.clear(); 2112 msgid.clear(); 2113 extra.clear(); 2114 } 2093 2115 yyTokColonSeen = false; 2094 2116 yyTok = getToken(); … … 2124 2146 2125 2147 if (yyBraceDepth != 0) 2126 qWarning("%s:%d: Unbalanced opening brace in C++ code"2127 " (or abuse of the C++ preprocessor)\n",2128 qPrintable(yyFileName), yyBraceLineNo);2148 yyMsg(yyBraceLineNo) 2149 << qPrintable(LU::tr("Unbalanced opening brace in C++ code" 2150 " (or abuse of the C++ preprocessor)\n")); 2129 2151 else if (yyParenDepth != 0) 2130 qWarning("%s:%d: Unbalanced opening parenthesis in C++ code"2131 " (or abuse of the C++ preprocessor)\n",2132 qPrintable(yyFileName), yyParenLineNo);2152 yyMsg(yyParenLineNo) 2153 << qPrintable(LU::tr("Unbalanced opening parenthesis in C++ code" 2154 " (or abuse of the C++ preprocessor)\n")); 2133 2155 else if (yyBracketDepth != 0) 2134 qWarning("%s:%d: Unbalanced opening bracket in C++ code"2135 " (or abuse of the C++ preprocessor)\n",2136 qPrintable(yyFileName), yyBracketLineNo);2156 yyMsg(yyBracketLineNo) 2157 << qPrintable(LU::tr("Unbalanced opening bracket in C++ code" 2158 " (or abuse of the C++ preprocessor)\n")); 2137 2159 } 2138 2160 … … 2195 2217 QFile file(filename); 2196 2218 if (!file.open(QIODevice::ReadOnly)) { 2197 cd.appendError(QString::fromLatin1("Cannot open %1: %2") 2198 .arg(filename, file.errorString())); 2219 cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); 2199 2220 continue; 2200 2221 } -
trunk/tools/linguist/lupdate/java.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 51 51 #include <QtCore/QString> 52 52 #include <QtCore/QTextCodec> 53 #include <QtCore/QCoreApplication> 54 55 #include <iostream> 53 56 54 57 #include <ctype.h> 55 58 56 59 QT_BEGIN_NAMESPACE 60 61 class LU { 62 Q_DECLARE_TR_FUNCTIONS(LUpdate) 63 }; 57 64 58 65 enum { Tok_Eof, Tok_class, Tok_return, Tok_tr, … … 107 114 static QStack<Scope*> yyScope; 108 115 static QString yyDefaultContext; 116 117 std::ostream &yyMsg(int line = 0) 118 { 119 return std::cerr << qPrintable(yyFileName) << ':' << (line ? line : yyLineNo) << ": "; 120 } 109 121 110 122 static QChar getChar() … … 190 202 yyCh = getChar(); 191 203 if ( yyCh == EOF ) { 192 qFatal( "%s: Unterminated Java comment starting at" 193 " line %d\n", 194 qPrintable(yyFileName), yyLineNo ); 195 204 yyMsg() << qPrintable(LU::tr("Unterminated Java comment.\n")); 196 205 return Tok_Comment; 197 206 } … … 229 238 int sub(yyCh.toLower().toAscii() - 87); 230 239 if( sub > 15 || sub < 10) { 231 qFatal( "%s:%d: Invalid Unicode",232 qPrintable(yyFileName), yyLineNo );240 yyMsg() << qPrintable(LU::tr("Invalid Unicode value.\n")); 241 break; 233 242 } 234 243 unicode += sub; … … 252 261 253 262 if ( yyCh != QLatin1Char('"') ) 254 qFatal( "%s:%d: Unterminated string", 255 qPrintable(yyFileName), yyLineNo ); 263 yyMsg() << qPrintable(LU::tr("Unterminated string.\n")); 256 264 257 265 yyCh = getChar(); … … 366 374 s += yyString; 367 375 else { 368 qWarning( "%s:%d: String used in translation can only contain strings"369 " concatenated with other strings, not expressions or numbers.",370 qPrintable(yyFileName), yyLineNo);376 yyMsg() << qPrintable(LU::tr( 377 "String used in translation can contain only literals" 378 " concatenated with other literals, not expressions or numbers.\n")); 371 379 return false; 372 380 } … … 476 484 } 477 485 else { 478 qFatal( "%s:%d: Class must be followed by a classname",479 qPrintable(yyFileName), yyLineNo );486 yyMsg() << qPrintable(LU::tr("'class' must be followed by a class name.\n")); 487 break; 480 488 } 481 489 while (!match(Tok_LeftBrace)) { … … 548 556 case Tok_RightBrace: 549 557 if ( yyScope.isEmpty() ) { 550 qFatal( "%s:%d: Unbalanced right brace in Java code\n", 551 qPrintable(yyFileName), yyLineNo ); 558 yyMsg() << qPrintable(LU::tr("Excess closing brace.\n")); 552 559 } 553 560 else … … 578 585 break; 579 586 default: 580 qFatal( "%s:%d: Package keyword should be followed by com.package.name;", 581 qPrintable(yyFileName), yyLineNo ); 587 yyMsg() << qPrintable(LU::tr("'package' must be followed by package name.\n")); 582 588 break; 583 589 } … … 592 598 593 599 if ( !yyScope.isEmpty() ) 594 qFatal( "%s:%d: Unbalanced braces in Java code\n", 595 qPrintable(yyFileName), yyScope.top()->line ); 600 yyMsg(yyScope.top()->line) << qPrintable(LU::tr("Unbalanced opening brace.\n")); 596 601 else if ( yyParenDepth != 0 ) 597 qFatal( "%s:%d: Unbalanced parentheses in Java code\n", 598 qPrintable(yyFileName), yyParenLineNo ); 602 yyMsg(yyParenLineNo) << qPrintable(LU::tr("Unbalanced opening parenthesis.\n")); 599 603 } 600 604 … … 604 608 QFile file(filename); 605 609 if (!file.open(QIODevice::ReadOnly)) { 606 cd.appendError(QString::fromLatin1("Cannot open %1: %2") 607 .arg(filename, file.errorString())); 610 cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); 608 611 return false; 609 612 } -
trunk/tools/linguist/lupdate/lupdate.h
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 80 80 bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd); 81 81 bool loadUI(Translator &translator, const QString &filename, ConversionData &cd); 82 bool loadQml(Translator &translator, const QString &filename, ConversionData &cd); 82 83 83 84 QT_END_NAMESPACE -
trunk/tools/linguist/lupdate/lupdate.pro
r561 r846 16 16 include(../shared/proparser.pri) 17 17 18 include($$QT_SOURCE_TREE/src/declarative/qml/parser/parser.pri) 19 INCLUDEPATH += $$QT_SOURCE_TREE/src/declarative/qml $$QT_BUILD_TREE/include/QtDeclarative 20 18 21 SOURCES += \ 19 22 main.cpp \ … … 24 27 java.cpp \ 25 28 qscript.cpp \ 29 qdeclarative.cpp \ 26 30 ui.cpp 27 31 -
trunk/tools/linguist/lupdate/main.cpp
r769 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 53 53 #include <QtCore/QStringList> 54 54 #include <QtCore/QTextCodec> 55 #include <QtCore/QTranslator> 56 #include <QtCore/QLibraryInfo> 55 57 56 58 #include <iostream> … … 58 60 static QString m_defaultExtensions; 59 61 60 static void printErr(const QString & out)61 {62 qWarning("%s", qPrintable(out));63 }64 65 62 static void printOut(const QString & out) 66 63 { 67 64 std::cerr << qPrintable(out); 68 65 } 66 67 class LU { 68 Q_DECLARE_TR_FUNCTIONS(LUpdate) 69 }; 69 70 70 71 static void recursiveFileInfoList(const QDir &dir, … … 81 82 static void printUsage() 82 83 { 83 printOut( QObject::tr(84 printOut(LU::tr( 84 85 "Usage:\n" 85 86 " lupdate [options] [project-file]...\n" 86 " lupdate [options] [source-file|path ]... -ts ts-files\n\n"87 " lupdate [options] [source-file|path|@lst-file]... -ts ts-files|@lst-file\n\n" 87 88 "lupdate is part of Qt's Linguist tool chain. It extracts translatable\n" 88 89 "messages from Qt UI files, C++, Java and JavaScript/QtScript source code.\n" … … 133 134 " -version\n" 134 135 " Display the version of lupdate and exit.\n" 136 " @lst-file\n" 137 " Read additional file names (one per line) from lst-file.\n" 135 138 ).arg(m_defaultExtensions)); 136 139 } … … 149 152 if (QFile(fileName).exists()) { 150 153 if (!tor.load(fileName, cd, QLatin1String("auto"))) { 151 print Err(cd.error());154 printOut(cd.error()); 152 155 *fail = true; 153 156 continue; … … 156 159 cd.clearErrors(); 157 160 if (setCodec && fetchedTor.codec() != tor.codec()) 158 qWarning("lupdate warning: Codec for tr() '%s' disagrees with " 159 "existing file's codec '%s'. Expect trouble.", 160 fetchedTor.codecName().constData(), tor.codecName().constData()); 161 printOut(LU::tr("lupdate warning: Codec for tr() '%1' disagrees with" 162 " existing file's codec '%2'. Expect trouble.\n") 163 .arg(QString::fromLatin1(fetchedTor.codecName()), 164 QString::fromLatin1(tor.codecName()))); 161 165 if (!targetLanguage.isEmpty() && targetLanguage != tor.languageCode()) 162 qWarning("lupdate warning: Specified target language '%s' disagrees with"163 "existing file's language '%s'. Ignoring.",164 qPrintable(targetLanguage), qPrintable(tor.languageCode()));166 printOut(LU::tr("lupdate warning: Specified target language '%1' disagrees with" 167 " existing file's language '%2'. Ignoring.\n") 168 .arg(targetLanguage, tor.languageCode())); 165 169 if (!sourceLanguage.isEmpty() && sourceLanguage != tor.sourceLanguageCode()) 166 qWarning("lupdate warning: Specified source language '%s' disagrees with"167 "existing file's language '%s'. Ignoring.",168 qPrintable(sourceLanguage), qPrintable(tor.sourceLanguageCode()));170 printOut(LU::tr("lupdate warning: Specified source language '%1' disagrees with" 171 " existing file's language '%2'. Ignoring.\n") 172 .arg(sourceLanguage, tor.sourceLanguageCode())); 169 173 } else { 170 174 if (setCodec) … … 185 189 tor.setLocationsType(Translator::AbsoluteLocations); 186 190 if (options & Verbose) 187 printOut( QObject::tr("Updating '%1'...\n").arg(fn));191 printOut(LU::tr("Updating '%1'...\n").arg(fn)); 188 192 189 193 UpdateOptions theseOptions = options; … … 200 204 if (options & PluralOnly) { 201 205 if (options & Verbose) 202 printOut( QObject::tr("Stripping non plural forms in '%1'...\n").arg(fn));206 printOut(LU::tr("Stripping non plural forms in '%1'...\n").arg(fn)); 203 207 out.stripNonPluralForms(); 204 208 } … … 209 213 out.normalizeTranslations(cd); 210 214 if (!cd.errors().isEmpty()) { 211 print Err(cd.error());215 printOut(cd.error()); 212 216 cd.clearErrors(); 213 217 } 214 218 if (!out.save(fileName, cd, QLatin1String("auto"))) { 215 print Err(cd.error());219 printOut(cd.error()); 216 220 *fail = true; 217 221 } … … 268 272 || it->endsWith(QLatin1String(".qs"), Qt::CaseInsensitive)) 269 273 loadQScript(fetchedTor, *it, cd); 274 else if (it->endsWith(QLatin1String(".qml"), Qt::CaseInsensitive)) 275 loadQml(fetchedTor, *it, cd); 270 276 else 271 277 sourceFilesCpp << *it; … … 293 299 codecForSource = tmp.last().toLatin1(); 294 300 if (!QTextCodec::codecForName(codecForSource)) { 295 qWarning("lupdate warning: Codec for source '%s' is invalid. " 296 "Falling back to codec for tr().", codecForSource.constData()); 301 printOut(LU::tr("lupdate warning: Codec for source '%1' is invalid." 302 " Falling back to codec for tr().\n") 303 .arg(QString::fromLatin1(codecForSource))); 297 304 codecForSource.clear(); 298 305 } … … 344 351 visitor.setVerbose(options & Verbose); 345 352 353 QHash<QString, QStringList> lupdateConfig; 354 lupdateConfig.insert(QLatin1String("CONFIG"), QStringList(QLatin1String("lupdate_run"))); 355 visitor.addVariables(lupdateConfig); 356 346 357 QFileInfo pfi(proFile); 347 358 ProFile pro(pfi.absoluteFilePath()); … … 355 366 if (parentTor) { 356 367 if (topLevel) { 357 std::cerr << "lupdate warning: TS files from command line "358 "will override TRANSLATIONS in " << qPrintable(proFile) << ".\n";368 std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line " 369 "will override TRANSLATIONS in %1.\n").arg(proFile)); 359 370 goto noTrans; 360 371 } else if (nestComplain) { 361 std::cerr << "lupdate warning: TS files from command line "362 "prevent recursing into " << qPrintable(proFile) << ".\n";372 std::cerr << qPrintable(LU::tr("lupdate warning: TS files from command line " 373 "prevent recursing into %1.\n").arg(proFile)); 363 374 continue; 364 375 } … … 391 402 if (!parentTor) { 392 403 if (topLevel) 393 std::cerr << "lupdate warning: no TS files specified. Only diagnostics "394 "will be produced for '" << qPrintable(proFile) << "'.\n";404 std::cerr << qPrintable(LU::tr("lupdate warning: no TS files specified. Only diagnostics " 405 "will be produced for '%1'.\n").arg(proFile)); 395 406 Translator tor; 396 407 processProject(nestComplain, pfi, visitor, options, codecForSource, … … 406 417 { 407 418 QCoreApplication app(argc, argv); 408 m_defaultExtensions = QLatin1String("ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx"); 419 #ifndef Q_OS_WIN32 420 QTranslator translator; 421 QTranslator qtTranslator; 422 QString sysLocale = QLocale::system().name(); 423 QString resourceDir = QLibraryInfo::location(QLibraryInfo::TranslationsPath); 424 if (translator.load(QLatin1String("linguist_") + sysLocale, resourceDir) 425 && qtTranslator.load(QLatin1String("qt_") + sysLocale, resourceDir)) { 426 app.installTranslator(&translator); 427 app.installTranslator(&qtTranslator); 428 } 429 #endif // Q_OS_WIN32 430 431 m_defaultExtensions = QLatin1String("java,jui,ui,c,c++,cc,cpp,cxx,ch,h,h++,hh,hpp,hxx,js,qs,qml"); 409 432 410 433 QStringList args = app.arguments(); … … 449 472 ++i; 450 473 if (i == argc) { 451 qWarning("The option -target-language requires a parameter.");474 printOut(LU::tr("The option -target-language requires a parameter.\n")); 452 475 return 1; 453 476 } … … 457 480 ++i; 458 481 if (i == argc) { 459 qWarning("The option -source-language requires a parameter.");482 printOut(LU::tr("The option -source-language requires a parameter.\n")); 460 483 return 1; 461 484 } … … 465 488 ++i; 466 489 if (i == argc) { 467 qWarning("The option -disable-heuristic requires a parameter.");490 printOut(LU::tr("The option -disable-heuristic requires a parameter.\n")); 468 491 return 1; 469 492 } … … 476 499 options &= ~HeuristicNumber; 477 500 } else { 478 qWarning("Invalid heuristic name passed to -disable-heuristic.");501 printOut(LU::tr("Invalid heuristic name passed to -disable-heuristic.\n")); 479 502 return 1; 480 503 } … … 483 506 ++i; 484 507 if (i == argc) { 485 qWarning("The option -locations requires a parameter.");508 printOut(LU::tr("The option -locations requires a parameter.\n")); 486 509 return 1; 487 510 } … … 493 516 options |= AbsoluteLocations; 494 517 } else { 495 qWarning("Invalid parameter passed to -locations.");518 printOut(LU::tr("Invalid parameter passed to -locations.\n")); 496 519 return 1; 497 520 } … … 519 542 ++i; 520 543 if (i == argc) { 521 qWarning("The -codecfortr option should be followed by a codec name.");544 printOut(LU::tr("The -codecfortr option should be followed by a codec name.\n")); 522 545 return 1; 523 546 } … … 530 553 ++i; 531 554 if (i == argc) { 532 qWarning("The -extensions option should be followed by an extension list.");555 printOut(LU::tr("The -extensions option should be followed by an extension list.\n")); 533 556 return 1; 534 557 } … … 538 561 ++i; 539 562 if (i == argc) { 540 qWarning("The -pro option should be followed by a filename of .pro file.");563 printOut(LU::tr("The -pro option should be followed by a filename of .pro file.\n")); 541 564 return 1; 542 565 } … … 548 571 ++i; 549 572 if (i == argc) { 550 qWarning("The -I option should be followed by a path.");573 printOut(LU::tr("The -I option should be followed by a path.\n")); 551 574 return 1; 552 575 } … … 557 580 continue; 558 581 } else if (arg.startsWith(QLatin1String("-")) && arg != QLatin1String("-")) { 559 qWarning("Unrecognized option '%s'", qPrintable(arg));582 printOut(LU::tr("Unrecognized option '%1'.\n").arg(arg)); 560 583 return 1; 561 584 } 562 585 586 QStringList files; 587 if (arg.startsWith(QLatin1String("@"))) { 588 QFile lstFile(arg.mid(1)); 589 if (!lstFile.open(QIODevice::ReadOnly)) { 590 printOut(LU::tr("lupdate error: List file '%1' is not readable.\n") 591 .arg(lstFile.fileName())); 592 return 1; 593 } 594 while (!lstFile.atEnd()) 595 files << QString::fromLocal8Bit(lstFile.readLine().trimmed()); 596 } else { 597 files << arg; 598 } 563 599 if (metTsFlag) { 564 bool found = false; 565 foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) { 566 if (arg.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) { 567 QFileInfo fi(arg); 568 if (!fi.exists() || fi.isWritable()) { 569 tsFileNames.append(QFileInfo(arg).absoluteFilePath()); 570 } else { 571 qWarning("lupdate warning: For some reason, '%s' is not writable.\n", 572 qPrintable(arg)); 600 foreach (const QString &file, files) { 601 bool found = false; 602 foreach (const Translator::FileFormat &fmt, Translator::registeredFileFormats()) { 603 if (file.endsWith(QLatin1Char('.') + fmt.extension, Qt::CaseInsensitive)) { 604 QFileInfo fi(file); 605 if (!fi.exists() || fi.isWritable()) { 606 tsFileNames.append(QFileInfo(file).absoluteFilePath()); 607 } else { 608 printOut(LU::tr("lupdate warning: For some reason, '%1' is not writable.\n") 609 .arg(file)); 610 } 611 found = true; 612 break; 573 613 } 574 found = true;575 break;576 614 } 577 } 578 if (!found) { 579 qWarning("lupdate error: File '%s' has no recognized extension\n", 580 qPrintable(arg)); 581 return 1; 582 } 583 } else if (arg.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) 584 || arg.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { 585 proFiles << arg; 615 if (!found) { 616 printOut(LU::tr("lupdate error: File '%1' has no recognized extension.\n") 617 .arg(file)); 618 return 1; 619 } 620 } 586 621 numFiles++; 587 622 } else { 588 QFileInfo fi(arg); 589 if (!fi.exists()) { 590 qWarning("lupdate error: File '%s' does not exists\n", qPrintable(arg)); 591 return 1; 592 } else if (fi.isDir()) { 593 if (options & Verbose) 594 printOut(QObject::tr("Scanning directory '%1'...").arg(arg)); 595 QDir dir = QDir(fi.filePath()); 596 projectRoots.insert(dir.absolutePath() + QLatin1Char('/')); 597 if (extensionsNameFilters.isEmpty()) { 598 foreach (QString ext, extensions.split(QLatin1Char(','))) { 599 ext = ext.trimmed(); 600 if (ext.startsWith(QLatin1Char('.'))) 601 ext.remove(0, 1); 602 extensionsNameFilters.insert(ext); 623 foreach (const QString &file, files) { 624 QFileInfo fi(file); 625 if (!fi.exists()) { 626 printOut(LU::tr("lupdate error: File '%1' does not exist.\n").arg(file)); 627 return 1; 628 } 629 if (file.endsWith(QLatin1String(".pro"), Qt::CaseInsensitive) 630 || file.endsWith(QLatin1String(".pri"), Qt::CaseInsensitive)) { 631 proFiles << file; 632 } else if (fi.isDir()) { 633 if (options & Verbose) 634 printOut(LU::tr("Scanning directory '%1'...\n").arg(file)); 635 QDir dir = QDir(fi.filePath()); 636 projectRoots.insert(dir.absolutePath() + QLatin1Char('/')); 637 if (extensionsNameFilters.isEmpty()) { 638 foreach (QString ext, extensions.split(QLatin1Char(','))) { 639 ext = ext.trimmed(); 640 if (ext.startsWith(QLatin1Char('.'))) 641 ext.remove(0, 1); 642 extensionsNameFilters.insert(ext); 643 } 603 644 } 645 QDir::Filters filters = QDir::Files | QDir::NoSymLinks; 646 if (recursiveScan) 647 filters |= QDir::AllDirs | QDir::NoDotAndDotDot; 648 QFileInfoList fileinfolist; 649 recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist); 650 int scanRootLen = dir.absolutePath().length(); 651 foreach (const QFileInfo &fi, fileinfolist) { 652 QString fn = QDir::cleanPath(fi.absoluteFilePath()); 653 sourceFiles << fn; 654 655 if (!fn.endsWith(QLatin1String(".java")) 656 && !fn.endsWith(QLatin1String(".jui")) 657 && !fn.endsWith(QLatin1String(".ui")) 658 && !fn.endsWith(QLatin1String(".js")) 659 && !fn.endsWith(QLatin1String(".qs")) 660 && !fn.endsWith(QLatin1String(".qml"))) { 661 int offset = 0; 662 int depth = 0; 663 do { 664 offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1); 665 QString ffn = fn.mid(offset + 1); 666 allCSources.insert(ffn, fn); 667 } while (++depth < 3 && offset > scanRootLen); 668 } 669 } 670 } else { 671 sourceFiles << QDir::cleanPath(fi.absoluteFilePath());; 672 projectRoots.insert(fi.absolutePath() + QLatin1Char('/')); 604 673 } 605 QDir::Filters filters = QDir::Files | QDir::NoSymLinks;606 if (recursiveScan)607 filters |= QDir::AllDirs | QDir::NoDotAndDotDot;608 QFileInfoList fileinfolist;609 recursiveFileInfoList(dir, extensionsNameFilters, filters, &fileinfolist);610 int scanRootLen = dir.absolutePath().length();611 foreach (const QFileInfo &fi, fileinfolist) {612 QString fn = QDir::cleanPath(fi.absoluteFilePath());613 sourceFiles << fn;614 615 if (!fn.endsWith(QLatin1String(".java"))616 && !fn.endsWith(QLatin1String(".ui"))617 && !fn.endsWith(QLatin1String(".js"))618 && !fn.endsWith(QLatin1String(".qs"))) {619 int offset = 0;620 int depth = 0;621 do {622 offset = fn.lastIndexOf(QLatin1Char('/'), offset - 1);623 QString ffn = fn.mid(offset + 1);624 allCSources.insert(ffn, fn);625 } while (++depth < 3 && offset > scanRootLen);626 }627 }628 } else {629 sourceFiles << QDir::cleanPath(fi.absoluteFilePath());;630 674 } 631 675 numFiles++; … … 639 683 640 684 if (!targetLanguage.isEmpty() && tsFileNames.count() != 1) 641 std::cerr << "lupdate warning: -target-language usually only"642 "makes sense with exactly one TS file.\n";685 printOut(LU::tr("lupdate warning: -target-language usually only" 686 " makes sense with exactly one TS file.\n")); 643 687 if (!codecForTr.isEmpty() && tsFileNames.isEmpty()) 644 std::cerr << "lupdate warning: -codecfortr has no effect without -ts.\n";688 printOut(LU::tr("lupdate warning: -codecfortr has no effect without -ts.\n")); 645 689 646 690 bool fail = false; 647 691 if (proFiles.isEmpty()) { 648 692 if (tsFileNames.isEmpty()) 649 std::cerr << "lupdate warning: no TS files specified."650 "Only diagnostics will be produced.\n";693 printOut(LU::tr("lupdate warning:" 694 " no TS files specified. Only diagnostics will be produced.\n")); 651 695 652 696 Translator fetchedTor; … … 662 706 } else { 663 707 if (!sourceFiles.isEmpty() || !includePath.isEmpty()) { 664 qWarning("lupdate error: Both project and source files / include paths specified.\n"); 708 printOut(LU::tr("lupdate error:" 709 " Both project and source files / include paths specified.\n")); 665 710 return 1; 666 711 } -
trunk/tools/linguist/lupdate/merge.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 45 45 #include "translator.h" 46 46 47 #include <QtCore/QCoreApplication> 47 48 #include <QtCore/QDebug> 48 49 #include <QtCore/QMap> … … 51 52 #include <QtCore/QVector> 52 53 53 54 54 QT_BEGIN_NAMESPACE 55 56 class LU { 57 Q_DECLARE_TR_FUNCTIONS(LUpdate) 58 }; 55 59 56 60 static bool isDigitFriendly(QChar c) … … 486 490 if (options & Verbose) { 487 491 int totalFound = neww + known; 488 err += QObject::tr(" Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known);492 err += LU::tr(" Found %n source text(s) (%1 new and %2 already existing)\n", 0, totalFound).arg(neww).arg(known); 489 493 490 494 if (obsoleted) { 491 495 if (options & NoObsolete) { 492 err += QObject::tr(" Removed %n obsolete entries\n", 0, obsoleted);496 err += LU::tr(" Removed %n obsolete entries\n", 0, obsoleted); 493 497 } else { 494 err += QObject::tr(" Kept %n obsolete entries\n", 0, obsoleted);498 err += LU::tr(" Kept %n obsolete entries\n", 0, obsoleted); 495 499 } 496 500 } 497 501 498 502 if (sameNumberHeuristicCount) 499 err += QObject::tr(" Number heuristic provided %n translation(s)\n",503 err += LU::tr(" Number heuristic provided %n translation(s)\n", 500 504 0, sameNumberHeuristicCount); 501 505 if (sameTextHeuristicCount) 502 err += QObject::tr(" Same-text heuristic provided %n translation(s)\n",506 err += LU::tr(" Same-text heuristic provided %n translation(s)\n", 503 507 0, sameTextHeuristicCount); 504 508 if (similarTextHeuristicCount) 505 err += QObject::tr(" Similar-text heuristic provided %n translation(s)\n",509 err += LU::tr(" Similar-text heuristic provided %n translation(s)\n", 506 510 0, similarTextHeuristicCount); 507 511 } -
trunk/tools/linguist/lupdate/qscript.cpp
r651 r846 2 2 /**************************************************************************** 3 3 ** 4 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).4 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 5 5 ** All rights reserved. 6 6 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 40 40 ** 41 41 ****************************************************************************/ 42 43 44 #define Q_SCRIPT_REGEXPLITERAL_RULE1 7 45 46 #define Q_SCRIPT_REGEXPLITERAL_RULE2 8 47 48 #include <translator.h> 49 50 #include <QtCore/QCoreApplication> 51 #include <QtCore/qdebug.h> 52 #include <QtCore/qnumeric.h> 53 #include <QtCore/qstring.h> 54 #include <QtCore/qtextcodec.h> 55 #include <QtCore/qvariant.h> 56 57 #include <iostream> 58 59 #include <ctype.h> 60 #include <stdlib.h> 61 #include <stdio.h> 62 #include <string.h> 63 64 QT_BEGIN_NAMESPACE 65 66 class LU { 67 Q_DECLARE_TR_FUNCTIONS(LUpdate) 68 }; 42 69 43 70 class QScriptGrammar … … 174 201 } 175 202 }; 176 177 203 178 204 const char *const QScriptGrammar::spell [] = { … … 748 774 -1, -1}; 749 775 750 751 #define Q_SCRIPT_REGEXPLITERAL_RULE1 7752 753 #define Q_SCRIPT_REGEXPLITERAL_RULE2 8754 755 #include <translator.h>756 757 #include <QtCore/qdebug.h>758 #include <QtCore/qnumeric.h>759 #include <QtCore/qstring.h>760 #include <QtCore/qtextcodec.h>761 #include <QtCore/qvariant.h>762 763 #include <ctype.h>764 #include <stdlib.h>765 #include <stdio.h>766 #include <string.h>767 768 QT_BEGIN_NAMESPACE769 770 776 static void recordMessage( 771 777 Translator *tor, const QString &context, const QString &text, const QString &comment, 772 const QString &extracomment, bool plural, const QString &fileName, int lineNo) 778 const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra, 779 bool plural, const QString &fileName, int lineNo) 773 780 { 774 781 TranslatorMessage msg( … … 777 784 TranslatorMessage::Unfinished, plural); 778 785 msg.setExtraComment(extracomment.simplified()); 786 msg.setId(msgid); 787 msg.setExtras(extra); 779 788 tor->extend(msg); 780 789 } … … 784 793 { 785 794 795 class CommentProcessor 796 { 797 public: 798 virtual ~CommentProcessor() {} 799 virtual void processComment(const QChar *chars, int length) = 0; 800 }; 801 786 802 class Lexer 787 803 { 788 804 public: 789 Lexer( );805 Lexer(CommentProcessor *); 790 806 ~Lexer(); 791 807 792 void setCode(const QString &c, int lineno);808 void setCode(const QString &c, const QString &fileName, int lineno); 793 809 int lex(); 794 810 811 QString fileName() const { return yyfilename; } 795 812 int currentLineNo() const { return yylineno; } 796 813 int currentColumnNo() const { return yycolumn; } … … 872 889 873 890 private: 891 QString yyfilename; 874 892 int yylineno; 875 893 bool done; … … 925 943 void syncProhibitAutomaticSemicolon(); 926 944 945 void processComment(const QChar *, int); 946 927 947 const QChar *code; 928 948 uint length; … … 951 971 int parenthesesCount; 952 972 bool prohibitAutomaticSemicolon; 973 974 CommentProcessor *commentProcessor; 953 975 }; 954 976 … … 1027 1049 } // namespace QScript 1028 1050 1029 QScript::Lexer::Lexer( )1051 QScript::Lexer::Lexer(QScript::CommentProcessor *proc) 1030 1052 : 1031 1053 yylineno(0), … … 1038 1060 check_reserved(true), 1039 1061 parenthesesState(IgnoreParentheses), 1040 prohibitAutomaticSemicolon(false) 1062 prohibitAutomaticSemicolon(false), 1063 commentProcessor(proc) 1041 1064 { 1042 1065 // allocate space for read buffers … … 1053 1076 } 1054 1077 1055 void QScript::Lexer::setCode(const QString &c, int lineno)1078 void QScript::Lexer::setCode(const QString &c, const QString &fileName, int lineno) 1056 1079 { 1057 1080 errmsg = QString(); 1081 yyfilename = fileName; 1058 1082 yylineno = lineno; 1059 1083 yycolumn = 1; … … 1404 1428 recordStartPos(); 1405 1429 shift(1); 1430 Q_ASSERT(pos16 == 0); 1406 1431 state = InSingleLineComment; 1407 1432 } else if (current == '/' && next1 == '*') { 1408 1433 recordStartPos(); 1409 1434 shift(1); 1435 Q_ASSERT(pos16 == 0); 1410 1436 state = InMultiLineComment; 1411 1437 } else if (current == 0) { … … 1466 1492 setDone(Bad); 1467 1493 err = IllegalCharacter; 1468 errmsg = QLatin1String("Illegal character");1494 errmsg = LU::tr("Illegal character"); 1469 1495 } 1470 1496 } … … 1477 1503 setDone(Bad); 1478 1504 err = UnclosedStringLiteral; 1479 errmsg = QLatin1String("Unclosed string at end of line");1505 errmsg = LU::tr("Unclosed string at end of line"); 1480 1506 } else if (current == '\\') { 1481 1507 state = InEscapeSequence; … … 1503 1529 setDone(Bad); 1504 1530 err = IllegalEscapeSequence; 1505 errmsg = QLatin1String("Illegal escape squence");1531 errmsg = LU::tr("Illegal escape squence"); 1506 1532 } 1507 1533 } else if (current == 'x') … … 1542 1568 setDone(Bad); 1543 1569 err = IllegalUnicodeEscapeSequence; 1544 errmsg = QLatin1String("Illegal unicode escape sequence");1570 errmsg = LU::tr("Illegal unicode escape sequence"); 1545 1571 } 1546 1572 break; 1547 1573 case InSingleLineComment: 1548 1574 if (isLineTerminator()) { 1575 record16(current); // include newline 1576 processComment(buffer16, pos16); 1549 1577 shiftWindowsLineBreak(); 1550 1578 yylineno++; 1551 1579 yycolumn = 0; 1580 pos16 = 0; 1552 1581 terminator = true; 1553 1582 bol = true; … … 1559 1588 } else if (current == 0) { 1560 1589 setDone(Eof); 1590 } else { 1591 record16(current); 1561 1592 } 1562 1593 break; … … 1565 1596 setDone(Bad); 1566 1597 err = UnclosedComment; 1567 errmsg = QLatin1String("Unclosed comment at end of file");1598 errmsg = LU::tr("Unclosed comment at end of file"); 1568 1599 } else if (isLineTerminator()) { 1569 1600 shiftWindowsLineBreak(); 1570 1601 yylineno++; 1571 1602 } else if (current == '*' && next1 == '/') { 1603 processComment(buffer16, pos16); 1604 pos16 = 0; 1572 1605 state = Start; 1573 1606 shift(1); 1607 } else { 1608 record16(current); 1574 1609 } 1575 1610 break; … … 1649 1684 setDone(Bad); 1650 1685 err = IllegalExponentIndicator; 1651 errmsg = QLatin1String("Illegal syntax for exponential number");1686 errmsg = LU::tr("Illegal syntax for exponential number"); 1652 1687 } 1653 1688 break; … … 1675 1710 state = Bad; 1676 1711 err = IllegalIdentifier; 1677 errmsg = QLatin1String("Identifier cannot start with numeric literal");1712 errmsg = LU::tr("Identifier cannot start with numeric literal"); 1678 1713 } 1679 1714 … … 1994 2029 while (1) { 1995 2030 if (isLineTerminator() || current == 0) { 1996 errmsg = QLatin1String("Unterminated regular expression literal");2031 errmsg = LU::tr("Unterminated regular expression literal"); 1997 2032 return false; 1998 2033 } … … 2033 2068 } 2034 2069 2070 void QScript::Lexer::processComment(const QChar *chars, int length) 2071 { 2072 commentProcessor->processComment(chars, length); 2073 } 2074 2035 2075 2036 2076 class Translator; 2037 2077 2038 class QScriptParser: protected QScriptGrammar 2078 class QScriptParser: protected QScriptGrammar, public QScript::CommentProcessor 2039 2079 { 2040 2080 public: … … 2052 2092 ~QScriptParser(); 2053 2093 2054 bool parse(QScript::Lexer *lexer, 2055 const QString &fileName, 2056 Translator *translator); 2057 2094 void setLexer(QScript::Lexer *); 2095 2096 bool parse(Translator *translator); 2097 2098 QString fileName() const 2099 { return lexer->fileName(); } 2058 2100 inline QString errorMessage() const 2059 2101 { return error_message; } … … 2071 2113 inline Location &loc(int index) 2072 2114 { return location_stack [tos + index - 2]; } 2115 2116 std::ostream &yyMsg(int line = 0); 2117 2118 virtual void processComment(const QChar *, int); 2073 2119 2074 2120 protected: … … 2081 2127 int error_lineno; 2082 2128 int error_column; 2129 2130 private: 2131 QScript::Lexer *lexer; 2132 QString extracomment; 2133 QString msgid; 2134 QString sourcetext; 2135 TranslatorMessage::ExtraData extra; 2083 2136 }; 2084 2137 … … 2107 2160 sym_stack(0), 2108 2161 state_stack(0), 2109 location_stack(0) 2162 location_stack(0), 2163 lexer(0) 2110 2164 { 2111 2165 } … … 2129 2183 } 2130 2184 2131 bool QScriptParser::parse(QScript::Lexer *lexer, 2132 const QString &fileName, 2133 Translator *translator) 2134 { 2185 void QScriptParser::setLexer(QScript::Lexer *lex) 2186 { 2187 lexer = lex; 2188 } 2189 2190 bool QScriptParser::parse(Translator *translator) 2191 { 2192 Q_ASSERT(lexer != 0); 2135 2193 const int INITIAL_STATE = 0; 2136 2194 … … 2214 2272 QString name = sym(1).toString(); 2215 2273 if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) { 2274 if (!sourcetext.isEmpty()) 2275 yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name)); 2216 2276 QVariantList args = sym(2).toList(); 2217 2277 if (args.size() < 2) { 2218 qWarning("%s:%d: %s() requires at least two arguments", 2219 qPrintable(fileName), identLineNo, qPrintable(name)); 2278 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name)); 2220 2279 } else { 2221 2280 if ((args.at(0).type() != QVariant::String) 2222 2281 || (args.at(1).type() != QVariant::String)) { 2223 qWarning("%s:%d: %s(): both arguments must be literal strings", 2224 qPrintable(fileName), identLineNo, qPrintable(name)); 2282 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name)); 2225 2283 } else { 2226 2284 QString context = args.at(0).toString(); 2227 2285 QString text = args.at(1).toString(); 2228 2286 QString comment = args.value(2).toString(); 2229 QString extracomment;2230 2287 bool plural = (args.size() > 4); 2231 2288 recordMessage(translator, context, text, comment, extracomment, 2232 plural, fileName, identLineNo);2289 msgid, extra, plural, fileName(), identLineNo); 2233 2290 } 2234 2291 } 2292 sourcetext.clear(); 2293 extracomment.clear(); 2294 msgid.clear(); 2295 extra.clear(); 2235 2296 } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) { 2297 if (!sourcetext.isEmpty()) 2298 yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name)); 2236 2299 QVariantList args = sym(2).toList(); 2237 2300 if (args.size() < 1) { 2238 qWarning("%s:%d: %s() requires at least one argument", 2239 qPrintable(fileName), identLineNo, qPrintable(name)); 2301 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name)); 2240 2302 } else { 2241 2303 if (args.at(0).type() != QVariant::String) { 2242 qWarning("%s:%d: %s(): text to translate must be a literal string", 2243 qPrintable(fileName), identLineNo, qPrintable(name)); 2304 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name)); 2244 2305 } else { 2245 QString context = QFileInfo(fileName ).baseName();2306 QString context = QFileInfo(fileName()).baseName(); 2246 2307 QString text = args.at(0).toString(); 2247 2308 QString comment = args.value(1).toString(); 2248 QString extracomment;2249 2309 bool plural = (args.size() > 2); 2250 2310 recordMessage(translator, context, text, comment, extracomment, 2251 plural, fileName, identLineNo);2311 msgid, extra, plural, fileName(), identLineNo); 2252 2312 } 2253 2313 } 2314 sourcetext.clear(); 2315 extracomment.clear(); 2316 msgid.clear(); 2317 extra.clear(); 2318 } else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) { 2319 if (!msgid.isEmpty()) 2320 yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name)); 2321 QVariantList args = sym(2).toList(); 2322 if (args.size() < 1) { 2323 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name)); 2324 } else { 2325 if (args.at(0).type() != QVariant::String) { 2326 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name)); 2327 } else { 2328 msgid = args.at(0).toString(); 2329 bool plural = (args.size() > 1); 2330 recordMessage(translator, QString(), sourcetext, QString(), extracomment, 2331 msgid, extra, plural, fileName(), identLineNo); 2332 } 2333 } 2334 sourcetext.clear(); 2335 extracomment.clear(); 2336 msgid.clear(); 2337 extra.clear(); 2254 2338 } 2255 2339 } break; … … 2277 2361 sym(1) = QVariant(); 2278 2362 } break; 2363 2364 case 171: 2365 2366 case 172: 2367 2368 case 173: 2369 2370 case 174: 2371 2372 case 175: 2373 2374 case 176: 2375 2376 case 177: 2377 2378 case 178: 2379 2380 case 179: 2381 2382 case 180: 2383 2384 case 181: 2385 2386 case 182: 2387 2388 case 183: 2389 2390 case 184: 2391 2392 case 185: 2393 if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) { 2394 yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n")); 2395 sourcetext.clear(); 2396 extracomment.clear(); 2397 msgid.clear(); 2398 extra.clear(); 2399 } 2400 break; 2279 2401 2280 2402 } // switch … … 2332 2454 { 2333 2455 if (first) 2334 error_message += QLatin1String ("Expected "); 2456 //: Beginning of the string that contains 2457 //: comma-separated list of expected tokens 2458 error_message += LU::tr("Expected "); 2335 2459 else 2336 2460 error_message += QLatin1String (", "); … … 2356 2480 } 2357 2481 2482 std::ostream &QScriptParser::yyMsg(int line) 2483 { 2484 return std::cerr << qPrintable(fileName()) << ':' << (line ? line : lexer->startLineNo()) << ": "; 2485 } 2486 2487 void QScriptParser::processComment(const QChar *chars, int length) 2488 { 2489 if (!length) 2490 return; 2491 // Try to match the logic of the C++ parser. 2492 if (*chars == QLatin1Char(':') && chars[1].isSpace()) { 2493 extracomment += QString(chars+2, length-2); 2494 } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) { 2495 msgid = QString(chars+2, length-2).simplified(); 2496 } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) { 2497 QString text = QString(chars+2, length-2).trimmed(); 2498 int k = text.indexOf(QLatin1Char(' ')); 2499 if (k > -1) 2500 extra.insert(text.left(k), text.mid(k + 1).trimmed()); 2501 } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) { 2502 sourcetext.reserve(sourcetext.length() + length-2); 2503 ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length(); 2504 int p = 2, c; 2505 forever { 2506 if (p >= length) 2507 break; 2508 c = chars[p++].unicode(); 2509 if (isspace(c)) 2510 continue; 2511 if (c != '"') { 2512 yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n")); 2513 break; 2514 } 2515 forever { 2516 if (p >= length) { 2517 whoops: 2518 yyMsg() << qPrintable(LU::tr("Unterminated meta string\n")); 2519 break; 2520 } 2521 c = chars[p++].unicode(); 2522 if (c == '"') 2523 break; 2524 if (c == '\\') { 2525 if (p >= length) 2526 goto whoops; 2527 c = chars[p++].unicode(); 2528 if (c == '\n') 2529 goto whoops; 2530 *ptr++ = '\\'; 2531 } 2532 *ptr++ = c; 2533 } 2534 } 2535 sourcetext.resize(ptr - (ushort *)sourcetext.data()); 2536 } 2537 } 2538 2358 2539 2359 2540 bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd) … … 2361 2542 QFile file(filename); 2362 2543 if (!file.open(QIODevice::ReadOnly)) { 2363 cd.appendError(QString::fromLatin1("Cannot open %1: %2") 2364 .arg(filename, file.errorString())); 2544 cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); 2365 2545 return false; 2366 2546 } … … 2375 2555 2376 2556 QString code = ts.readAll(); 2377 QScript::Lexer lexer;2378 lexer.setCode(code, /*lineNumber=*/1);2379 2557 QScriptParser parser; 2380 if (!parser.parse(&lexer, filename, &translator)) { 2381 qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(), 2382 qPrintable(parser.errorMessage())); 2558 QScript::Lexer lexer(&parser); 2559 lexer.setCode(code, filename, /*lineNumber=*/1); 2560 parser.setLexer(&lexer); 2561 if (!parser.parse(&translator)) { 2562 std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": " 2563 << qPrintable(parser.errorMessage()) << std::endl; 2383 2564 return false; 2384 2565 } -
trunk/tools/linguist/lupdate/qscript.g
r651 r846 1 1 ---------------------------------------------------------------------------- 2 2 -- 3 -- Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 -- Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 -- All rights reserved. 5 5 -- Contact: Nokia Corporation (qt-info@nokia.com) … … 85 85 #include <translator.h> 86 86 87 #include <QtCore/QCoreApplication> 87 88 #include <QtCore/qdebug.h> 88 89 #include <QtCore/qnumeric.h> … … 91 92 #include <QtCore/qvariant.h> 92 93 94 #include <iostream> 95 93 96 #include <ctype.h> 94 97 #include <stdlib.h> … … 98 101 QT_BEGIN_NAMESPACE 99 102 103 class LU { 104 Q_DECLARE_TR_FUNCTIONS(LUpdate) 105 }; 106 100 107 static void recordMessage( 101 108 Translator *tor, const QString &context, const QString &text, const QString &comment, 102 const QString &extracomment, bool plural, const QString &fileName, int lineNo) 109 const QString &extracomment, const QString &msgid, const TranslatorMessage::ExtraData &extra, 110 bool plural, const QString &fileName, int lineNo) 103 111 { 104 112 TranslatorMessage msg( … … 107 115 TranslatorMessage::Unfinished, plural); 108 116 msg.setExtraComment(extracomment.simplified()); 109 tor->replace(msg); 117 msg.setId(msgid); 118 msg.setExtras(extra); 119 tor->extend(msg); 110 120 } 111 121 … … 114 124 { 115 125 126 class CommentProcessor 127 { 128 public: 129 virtual ~CommentProcessor() {} 130 virtual void processComment(const QChar *chars, int length) = 0; 131 }; 132 116 133 class Lexer 117 134 { 118 135 public: 119 Lexer( );136 Lexer(CommentProcessor *); 120 137 ~Lexer(); 121 138 122 void setCode(const QString &c, int lineno);139 void setCode(const QString &c, const QString &fileName, int lineno); 123 140 int lex(); 124 141 142 QString fileName() const { return yyfilename; } 125 143 int currentLineNo() const { return yylineno; } 126 144 int currentColumnNo() const { return yycolumn; } … … 202 220 203 221 private: 222 QString yyfilename; 204 223 int yylineno; 205 224 bool done; … … 255 274 void syncProhibitAutomaticSemicolon(); 256 275 276 void processComment(const QChar *, int); 277 257 278 const QChar *code; 258 279 uint length; … … 281 302 int parenthesesCount; 282 303 bool prohibitAutomaticSemicolon; 304 305 CommentProcessor *commentProcessor; 283 306 }; 284 307 … … 357 380 } // namespace QScript 358 381 359 QScript::Lexer::Lexer( )382 QScript::Lexer::Lexer(QScript::CommentProcessor *proc) 360 383 : 361 384 yylineno(0), … … 368 391 check_reserved(true), 369 392 parenthesesState(IgnoreParentheses), 370 prohibitAutomaticSemicolon(false) 393 prohibitAutomaticSemicolon(false), 394 commentProcessor(proc) 371 395 { 372 396 // allocate space for read buffers … … 383 407 } 384 408 385 void QScript::Lexer::setCode(const QString &c, int lineno)409 void QScript::Lexer::setCode(const QString &c, const QString &fileName, int lineno) 386 410 { 387 411 errmsg = QString(); 412 yyfilename = fileName; 388 413 yylineno = lineno; 389 414 yycolumn = 1; … … 734 759 recordStartPos(); 735 760 shift(1); 761 Q_ASSERT(pos16 == 0); 736 762 state = InSingleLineComment; 737 763 } else if (current == '/' && next1 == '*') { 738 764 recordStartPos(); 739 765 shift(1); 766 Q_ASSERT(pos16 == 0); 740 767 state = InMultiLineComment; 741 768 } else if (current == 0) { … … 796 823 setDone(Bad); 797 824 err = IllegalCharacter; 798 errmsg = QLatin1String("Illegal character");825 errmsg = LU::tr("Illegal character"); 799 826 } 800 827 } … … 807 834 setDone(Bad); 808 835 err = UnclosedStringLiteral; 809 errmsg = QLatin1String("Unclosed string at end of line");836 errmsg = LU::tr("Unclosed string at end of line"); 810 837 } else if (current == '\\') { 811 838 state = InEscapeSequence; … … 833 860 setDone(Bad); 834 861 err = IllegalEscapeSequence; 835 errmsg = QLatin1String("Illegal escape squence");862 errmsg = LU::tr("Illegal escape squence"); 836 863 } 837 864 } else if (current == 'x') … … 872 899 setDone(Bad); 873 900 err = IllegalUnicodeEscapeSequence; 874 errmsg = QLatin1String("Illegal unicode escape sequence");901 errmsg = LU::tr("Illegal unicode escape sequence"); 875 902 } 876 903 break; 877 904 case InSingleLineComment: 878 905 if (isLineTerminator()) { 906 record16(current); // include newline 907 processComment(buffer16, pos16); 879 908 shiftWindowsLineBreak(); 880 909 yylineno++; 881 910 yycolumn = 0; 911 pos16 = 0; 882 912 terminator = true; 883 913 bol = true; … … 889 919 } else if (current == 0) { 890 920 setDone(Eof); 921 } else { 922 record16(current); 891 923 } 892 924 break; … … 895 927 setDone(Bad); 896 928 err = UnclosedComment; 897 errmsg = QLatin1String("Unclosed comment at end of file");929 errmsg = LU::tr("Unclosed comment at end of file"); 898 930 } else if (isLineTerminator()) { 899 931 shiftWindowsLineBreak(); 900 932 yylineno++; 901 933 } else if (current == '*' && next1 == '/') { 934 processComment(buffer16, pos16); 935 pos16 = 0; 902 936 state = Start; 903 937 shift(1); 938 } else { 939 record16(current); 904 940 } 905 941 break; … … 979 1015 setDone(Bad); 980 1016 err = IllegalExponentIndicator; 981 errmsg = QLatin1String("Illegal syntax for exponential number");1017 errmsg = LU::tr("Illegal syntax for exponential number"); 982 1018 } 983 1019 break; … … 1005 1041 state = Bad; 1006 1042 err = IllegalIdentifier; 1007 errmsg = QLatin1String("Identifier cannot start with numeric literal");1043 errmsg = LU::tr("Identifier cannot start with numeric literal"); 1008 1044 } 1009 1045 … … 1324 1360 while (1) { 1325 1361 if (isLineTerminator() || current == 0) { 1326 errmsg = QLatin1String("Unterminated regular expression literal");1362 errmsg = LU::tr("Unterminated regular expression literal"); 1327 1363 return false; 1328 1364 } … … 1363 1399 } 1364 1400 1401 void QScript::Lexer::processComment(const QChar *chars, int length) 1402 { 1403 commentProcessor->processComment(chars, length); 1404 } 1405 1365 1406 1366 1407 class Translator; 1367 1408 1368 class QScriptParser: protected $table 1409 class QScriptParser: protected $table, public QScript::CommentProcessor 1369 1410 { 1370 1411 public: … … 1382 1423 ~QScriptParser(); 1383 1424 1384 bool parse(QScript::Lexer *lexer, 1385 const QString &fileName, 1386 Translator *translator); 1387 1425 void setLexer(QScript::Lexer *); 1426 1427 bool parse(Translator *translator); 1428 1429 QString fileName() const 1430 { return lexer->fileName(); } 1388 1431 inline QString errorMessage() const 1389 1432 { return error_message; } … … 1401 1444 inline Location &loc(int index) 1402 1445 { return location_stack [tos + index - 2]; } 1446 1447 std::ostream &yyMsg(int line = 0); 1448 1449 virtual void processComment(const QChar *, int); 1403 1450 1404 1451 protected: … … 1411 1458 int error_lineno; 1412 1459 int error_column; 1460 1461 private: 1462 QScript::Lexer *lexer; 1463 QString extracomment; 1464 QString msgid; 1465 QString sourcetext; 1466 TranslatorMessage::ExtraData extra; 1413 1467 }; 1414 1468 … … 1437 1491 sym_stack(0), 1438 1492 state_stack(0), 1439 location_stack(0) 1493 location_stack(0), 1494 lexer(0) 1440 1495 { 1441 1496 } … … 1459 1514 } 1460 1515 1461 bool QScriptParser::parse(QScript::Lexer *lexer, 1462 const QString &fileName, 1463 Translator *translator) 1464 { 1516 void QScriptParser::setLexer(QScript::Lexer *lex) 1517 { 1518 lexer = lex; 1519 } 1520 1521 bool QScriptParser::parse(Translator *translator) 1522 { 1523 Q_ASSERT(lexer != 0); 1465 1524 const int INITIAL_STATE = 0; 1466 1525 … … 1629 1688 QString name = sym(1).toString(); 1630 1689 if ((name == QLatin1String("qsTranslate")) || (name == QLatin1String("QT_TRANSLATE_NOOP"))) { 1690 if (!sourcetext.isEmpty()) 1691 yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name)); 1631 1692 QVariantList args = sym(2).toList(); 1632 1693 if (args.size() < 2) { 1633 qWarning("%s:%d: %s() requires at least two arguments", 1634 qPrintable(fileName), identLineNo, qPrintable(name)); 1694 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least two arguments.\n").arg(name)); 1635 1695 } else { 1636 1696 if ((args.at(0).type() != QVariant::String) 1637 1697 || (args.at(1).type() != QVariant::String)) { 1638 qWarning("%s:%d: %s(): both arguments must be literal strings", 1639 qPrintable(fileName), identLineNo, qPrintable(name)); 1698 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): both arguments must be literal strings.\n").arg(name)); 1640 1699 } else { 1641 1700 QString context = args.at(0).toString(); 1642 1701 QString text = args.at(1).toString(); 1643 1702 QString comment = args.value(2).toString(); 1644 QString extracomment;1645 1703 bool plural = (args.size() > 4); 1646 1704 recordMessage(translator, context, text, comment, extracomment, 1647 plural, fileName, identLineNo); 1648 } 1649 } 1705 msgid, extra, plural, fileName(), identLineNo); 1706 } 1707 } 1708 sourcetext.clear(); 1709 extracomment.clear(); 1710 msgid.clear(); 1711 extra.clear(); 1650 1712 } else if ((name == QLatin1String("qsTr")) || (name == QLatin1String("QT_TR_NOOP"))) { 1713 if (!sourcetext.isEmpty()) 1714 yyMsg(identLineNo) << qPrintable(LU::tr("//% cannot be used with %1(). Ignoring\n").arg(name)); 1651 1715 QVariantList args = sym(2).toList(); 1652 1716 if (args.size() < 1) { 1653 qWarning("%s:%d: %s() requires at least one argument", 1654 qPrintable(fileName), identLineNo, qPrintable(name)); 1717 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name)); 1655 1718 } else { 1656 1719 if (args.at(0).type() != QVariant::String) { 1657 qWarning("%s:%d: %s(): text to translate must be a literal string", 1658 qPrintable(fileName), identLineNo, qPrintable(name)); 1720 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): text to translate must be a literal string.\n").arg(name)); 1659 1721 } else { 1660 QString context = QFileInfo(fileName ).baseName();1722 QString context = QFileInfo(fileName()).baseName(); 1661 1723 QString text = args.at(0).toString(); 1662 1724 QString comment = args.value(1).toString(); 1663 QString extracomment;1664 1725 bool plural = (args.size() > 2); 1665 1726 recordMessage(translator, context, text, comment, extracomment, 1666 plural, fileName, identLineNo); 1667 } 1668 } 1727 msgid, extra, plural, fileName(), identLineNo); 1728 } 1729 } 1730 sourcetext.clear(); 1731 extracomment.clear(); 1732 msgid.clear(); 1733 extra.clear(); 1734 } else if ((name == QLatin1String("qsTrId")) || (name == QLatin1String("QT_TRID_NOOP"))) { 1735 if (!msgid.isEmpty()) 1736 yyMsg(identLineNo) << qPrintable(LU::tr("//= cannot be used with %1(). Ignoring\n").arg(name)); 1737 QVariantList args = sym(2).toList(); 1738 if (args.size() < 1) { 1739 yyMsg(identLineNo) << qPrintable(LU::tr("%1() requires at least one argument.\n").arg(name)); 1740 } else { 1741 if (args.at(0).type() != QVariant::String) { 1742 yyMsg(identLineNo) << qPrintable(LU::tr("%1(): identifier must be a literal string.\n").arg(name)); 1743 } else { 1744 msgid = args.at(0).toString(); 1745 bool plural = (args.size() > 1); 1746 recordMessage(translator, QString(), sourcetext, QString(), extracomment, 1747 msgid, extra, plural, fileName(), identLineNo); 1748 } 1749 } 1750 sourcetext.clear(); 1751 extracomment.clear(); 1752 msgid.clear(); 1753 extra.clear(); 1669 1754 } 1670 1755 } break; … … 1812 1897 1813 1898 Statement: Block ; 1899 /. 1900 case $rule_number: 1901 ./ 1814 1902 Statement: VariableStatement ; 1903 /. 1904 case $rule_number: 1905 ./ 1815 1906 Statement: EmptyStatement ; 1907 /. 1908 case $rule_number: 1909 ./ 1816 1910 Statement: ExpressionStatement ; 1911 /. 1912 case $rule_number: 1913 ./ 1817 1914 Statement: IfStatement ; 1915 /. 1916 case $rule_number: 1917 ./ 1818 1918 Statement: IterationStatement ; 1919 /. 1920 case $rule_number: 1921 ./ 1819 1922 Statement: ContinueStatement ; 1923 /. 1924 case $rule_number: 1925 ./ 1820 1926 Statement: BreakStatement ; 1927 /. 1928 case $rule_number: 1929 ./ 1821 1930 Statement: ReturnStatement ; 1931 /. 1932 case $rule_number: 1933 ./ 1822 1934 Statement: WithStatement ; 1935 /. 1936 case $rule_number: 1937 ./ 1823 1938 Statement: LabelledStatement ; 1939 /. 1940 case $rule_number: 1941 ./ 1824 1942 Statement: SwitchStatement ; 1943 /. 1944 case $rule_number: 1945 ./ 1825 1946 Statement: ThrowStatement ; 1947 /. 1948 case $rule_number: 1949 ./ 1826 1950 Statement: TryStatement ; 1951 /. 1952 case $rule_number: 1953 ./ 1827 1954 Statement: DebuggerStatement ; 1955 /. 1956 case $rule_number: 1957 if (!sourcetext.isEmpty() || !extracomment.isEmpty() || !msgid.isEmpty() || !extra.isEmpty()) { 1958 yyMsg() << qPrintable(LU::tr("Discarding unconsumed meta data\n")); 1959 sourcetext.clear(); 1960 extracomment.clear(); 1961 msgid.clear(); 1962 extra.clear(); 1963 } 1964 break; 1965 ./ 1828 1966 1829 1967 Block: T_LBRACE StatementListOpt T_RBRACE ; … … 1964 2102 if (first) 1965 2103 error_message += QLatin1String ("Expected "); 2104 //: Beginning of the string that contains 2105 //: comma-separated list of expected tokens 2106 error_message += LU::tr("Expected "); 1966 2107 else 1967 2108 error_message += QLatin1String (", "); … … 1987 2128 } 1988 2129 2130 std::ostream &QScriptParser::yyMsg(int line) 2131 { 2132 return std::cerr << qPrintable(fileName()) << ':' << (line ? line : lexer->startLineNo()) << ": "; 2133 } 2134 2135 void QScriptParser::processComment(const QChar *chars, int length) 2136 { 2137 if (!length) 2138 return; 2139 // Try to match the logic of the C++ parser. 2140 if (*chars == QLatin1Char(':') && chars[1].isSpace()) { 2141 extracomment += QString(chars+2, length-2); 2142 } else if (*chars == QLatin1Char('=') && chars[1].isSpace()) { 2143 msgid = QString(chars+2, length-2).simplified(); 2144 } else if (*chars == QLatin1Char('~') && chars[1].isSpace()) { 2145 QString text = QString(chars+2, length-2).trimmed(); 2146 int k = text.indexOf(QLatin1Char(' ')); 2147 if (k > -1) 2148 extra.insert(text.left(k), text.mid(k + 1).trimmed()); 2149 } else if (*chars == QLatin1Char('%') && chars[1].isSpace()) { 2150 sourcetext.reserve(sourcetext.length() + length-2); 2151 ushort *ptr = (ushort *)sourcetext.data() + sourcetext.length(); 2152 int p = 2, c; 2153 forever { 2154 if (p >= length) 2155 break; 2156 c = chars[p++].unicode(); 2157 if (isspace(c)) 2158 continue; 2159 if (c != '"') { 2160 yyMsg() << qPrintable(LU::tr("Unexpected character in meta string\n")); 2161 break; 2162 } 2163 forever { 2164 if (p >= length) { 2165 whoops: 2166 yyMsg() << qPrintable(LU::tr("Unterminated meta string\n")); 2167 break; 2168 } 2169 c = chars[p++].unicode(); 2170 if (c == '"') 2171 break; 2172 if (c == '\\') { 2173 if (p >= length) 2174 goto whoops; 2175 c = chars[p++].unicode(); 2176 if (c == '\n') 2177 goto whoops; 2178 *ptr++ = '\\'; 2179 } 2180 *ptr++ = c; 2181 } 2182 } 2183 sourcetext.resize(ptr - (ushort *)sourcetext.data()); 2184 } 2185 } 2186 1989 2187 1990 2188 bool loadQScript(Translator &translator, const QString &filename, ConversionData &cd) … … 1992 2190 QFile file(filename); 1993 2191 if (!file.open(QIODevice::ReadOnly)) { 1994 cd.appendError(QString::fromLatin1("Cannot open %1: %2") 1995 .arg(filename, file.errorString())); 2192 cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); 1996 2193 return false; 1997 2194 } … … 2006 2203 2007 2204 QString code = ts.readAll(); 2008 QScript::Lexer lexer;2009 lexer.setCode(code, /*lineNumber=*/1);2010 2205 QScriptParser parser; 2011 if (!parser.parse(&lexer, filename, &translator)) { 2012 qWarning("%s:%d: %s", qPrintable(filename), parser.errorLineNumber(), 2013 qPrintable(parser.errorMessage())); 2206 QScript::Lexer lexer(&parser); 2207 lexer.setCode(code, filename, /*lineNumber=*/1); 2208 parser.setLexer(&lexer); 2209 if (!parser.parse(&translator)) { 2210 std::cerr << qPrintable(filename) << ':' << parser.errorLineNumber() << ": " 2211 << qPrintable(parser.errorMessage()) << std::endl; 2014 2212 return false; 2015 2213 } -
trunk/tools/linguist/lupdate/ui.cpp
r651 r846 1 1 /**************************************************************************** 2 2 ** 3 ** Copyright (C) 201 0Nokia Corporation and/or its subsidiary(-ies).3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 4 ** All rights reserved. 5 5 ** Contact: Nokia Corporation (qt-info@nokia.com) … … 44 44 #include <translator.h> 45 45 46 #include <QtCore/QCoreApplication> 46 47 #include <QtCore/QDebug> 47 48 #include <QtCore/QFile> … … 55 56 56 57 QT_BEGIN_NAMESPACE 58 59 class LU { 60 Q_DECLARE_TR_FUNCTIONS(LUpdate) 61 }; 57 62 58 63 class UiReader : public QXmlDefaultHandler … … 153 158 bool UiReader::fatalError(const QXmlParseException &exception) 154 159 { 155 QString msg; 156 msg.sprintf("XML error: Parse error at line %d, column %d (%s).", 157 exception.lineNumber(), exception.columnNumber(), 158 exception.message().toLatin1().data()); 159 m_cd.appendError(msg); 160 QString msg = LU::tr("XML error: Parse error at line %1, column %2 (%3).") 161 .arg(exception.lineNumber()).arg(exception.columnNumber()) 162 .arg(exception.message()); 163 m_cd.appendError(msg); 160 164 return false; 161 165 } … … 182 186 QFile file(filename); 183 187 if (!file.open(QIODevice::ReadOnly)) { 184 cd.appendError(QString::fromLatin1("Cannot open %1: %2") 185 .arg(filename, file.errorString())); 188 cd.appendError(LU::tr("Cannot open %1: %2").arg(filename, file.errorString())); 186 189 return false; 187 190 } … … 197 200 bool result = reader.parse(in); 198 201 if (!result) 199 cd.appendError( QLatin1String("Parse error in UI file"));202 cd.appendError(LU::tr("Parse error in UI file")); 200 203 reader.setContentHandler(0); 201 204 reader.setErrorHandler(0);
Note:
See TracChangeset
for help on using the changeset viewer.