KDECore
klocalizedstring.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2006 Chusslove Illich <caslav.ilic@gmx.net> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 #ifndef KLOCALIZEDSTRING_H 00020 #define KLOCALIZEDSTRING_H 00021 00022 #include <kdecore_export.h> 00023 00024 00025 #include <QtCore/QChar> 00026 #include <QtCore/QLatin1Char> 00027 #include <QtCore/QStringList> 00028 00029 class KLocale; 00030 struct KCatalogName; 00031 class KLocalizedStringPrivate; 00032 00037 #ifndef I18N_NOOP 00038 00051 #define I18N_NOOP(x) x 00052 #endif 00053 00054 #ifndef I18N_NOOP2 00055 00072 #define I18N_NOOP2(comment,x) x 00073 #endif 00074 00075 #ifndef I18N_NOOP2_NOSTRIP 00076 00102 #define I18N_NOOP2_NOSTRIP(ctxt, text) ctxt, text 00103 #endif 00104 00299 class KDECORE_EXPORT KLocalizedString 00300 { 00301 00302 friend KLocalizedString KDECORE_EXPORT ki18n (const char* msg); 00303 friend KLocalizedString KDECORE_EXPORT ki18nc (const char *ctxt, const char *msg); 00304 friend KLocalizedString KDECORE_EXPORT ki18np (const char *singular, const char *plural); 00305 friend KLocalizedString KDECORE_EXPORT ki18ncp (const char *ctxt, 00306 const char *singular, const char *plural); 00307 00308 public: 00316 explicit KLocalizedString (); 00317 00321 KLocalizedString (const KLocalizedString &rhs); 00322 00326 KLocalizedString& operator= (const KLocalizedString &rhs); 00327 00331 ~KLocalizedString (); 00332 00342 QString toString () const; 00343 00352 QString toString (const QString &catalogName) const; 00353 00365 QString toString (const KLocale *locale) const; 00366 00376 QString toString (const KLocale *locale, const QString &catalogName) const; 00377 00387 bool isEmpty() const; 00388 00401 KLocalizedString subs (int a, int fieldWidth = 0, int base = 10, 00402 const QChar &fillChar = QLatin1Char(' ')) const; 00403 00416 KLocalizedString subs (uint a, int fieldWidth = 0, int base = 10, 00417 const QChar &fillChar = QLatin1Char(' ')) const; 00418 00431 KLocalizedString subs (long a, int fieldWidth = 0, int base = 10, 00432 const QChar &fillChar = QLatin1Char(' ')) const; 00433 00446 KLocalizedString subs (ulong a, int fieldWidth = 0, int base = 10, 00447 const QChar &fillChar = QLatin1Char(' ')) const; 00448 00461 KLocalizedString subs (qlonglong a, int fieldWidth = 0, int base = 10, 00462 const QChar &fillChar = QLatin1Char(' ')) const; 00463 00476 KLocalizedString subs (qulonglong a, int fieldWidth = 0, int base = 10, 00477 const QChar &fillChar = QLatin1Char(' ')) const; 00478 00491 KLocalizedString subs (double a, int fieldWidth = 0, 00492 char format = 'g', int precision = -1, 00493 const QChar &fillChar = QLatin1Char(' ')) const; 00494 00505 KLocalizedString subs (QChar a, int fieldWidth = 0, 00506 const QChar &fillChar = QLatin1Char(' ')) const; 00507 00518 KLocalizedString subs (const QString &a, int fieldWidth = 0, 00519 const QChar &fillChar = QLatin1Char(' ')) const; 00520 00528 KLocalizedString inContext (const QString &key, 00529 const QString &text) const; 00530 00534 static void notifyCatalogsUpdated (const QStringList &languages, 00535 const QList<KCatalogName> &catalogs); 00536 00537 private: 00538 KLocalizedString (const char *ctxt, 00539 const char *msg, const char *plural); 00540 00541 KLocalizedStringPrivate * const d; 00542 }; 00543 00553 extern KLocalizedString KDECORE_EXPORT ki18n (const char* msg); 00554 00567 extern KLocalizedString KDECORE_EXPORT ki18nc (const char *ctxt, const char *msg); 00568 00579 extern KLocalizedString KDECORE_EXPORT ki18np (const char *singular, const char *plural); 00580 00595 extern KLocalizedString KDECORE_EXPORT ki18ncp (const char *ctxt, const char *singular, const char *plural); 00596 00602 inline QString tr2i18n (const char *message, const char *comment = 0) { 00603 if (comment && comment[0] && message && message[0]) { 00604 return ki18nc(comment, message).toString(); 00605 } 00606 else if (message && message[0]) { 00607 return ki18n(message).toString(); 00608 } 00609 else { 00610 return QString(); 00611 } 00612 } 00613 00614 #ifndef NDEBUG 00615 #define I18N_ERR_MSG String_literal_as_second_argument_to_i18n___Perhaps_you_need_i18nc_or_i18np 00616 template <typename T, int s> class I18nTypeCheck {public: static void I18N_ERR_MSG () {}}; 00617 template <int s> class I18nTypeCheck<char[s], s> {}; 00618 #define STATIC_ASSERT_NOT_LITERAL_STRING(T) I18nTypeCheck<T, sizeof(T)>::I18N_ERR_MSG (); 00619 #else 00620 #define STATIC_ASSERT_NOT_LITERAL_STRING(T) 00621 #endif 00622 00623 // >>>>> Basic calls 00624 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00630 inline QString i18n (const char *text) 00631 { 00632 return ki18n(text).toString(); 00633 } 00634 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00641 template <typename A1> 00642 inline QString i18n (const char *text, const A1 &a1) 00643 { 00644 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00645 return ki18n(text).subs(a1).toString(); 00646 } 00647 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00655 template <typename A1, typename A2> 00656 inline QString i18n (const char *text, const A1 &a1, const A2 &a2) 00657 { 00658 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00659 return ki18n(text).subs(a1).subs(a2).toString(); 00660 } 00661 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00670 template <typename A1, typename A2, typename A3> 00671 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3) 00672 { 00673 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00674 return ki18n(text).subs(a1).subs(a2).subs(a3).toString(); 00675 } 00676 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00686 template <typename A1, typename A2, typename A3, typename A4> 00687 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) 00688 { 00689 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00690 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).toString(); 00691 } 00692 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00703 template <typename A1, typename A2, typename A3, typename A4, typename A5> 00704 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) 00705 { 00706 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00707 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).toString(); 00708 } 00709 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00721 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 00722 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) 00723 { 00724 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00725 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).toString(); 00726 } 00727 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00740 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> 00741 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) 00742 { 00743 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00744 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).toString(); 00745 } 00746 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00760 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> 00761 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) 00762 { 00763 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00764 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).toString(); 00765 } 00766 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00781 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> 00782 inline QString i18n (const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) 00783 { 00784 STATIC_ASSERT_NOT_LITERAL_STRING(A1) 00785 return ki18n(text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).subs(a9).toString(); 00786 } 00787 // <<<<<<< End of basic calls 00788 00789 // >>>>> Context calls 00790 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00797 inline QString i18nc (const char *ctxt, const char *text) 00798 { 00799 return ki18nc(ctxt, text).toString(); 00800 } 00801 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00809 template <typename A1> 00810 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1) 00811 { 00812 return ki18nc(ctxt, text).subs(a1).toString(); 00813 } 00814 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00823 template <typename A1, typename A2> 00824 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2) 00825 { 00826 return ki18nc(ctxt, text).subs(a1).subs(a2).toString(); 00827 } 00828 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00838 template <typename A1, typename A2, typename A3> 00839 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3) 00840 { 00841 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).toString(); 00842 } 00843 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00854 template <typename A1, typename A2, typename A3, typename A4> 00855 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) 00856 { 00857 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).toString(); 00858 } 00859 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00871 template <typename A1, typename A2, typename A3, typename A4, typename A5> 00872 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) 00873 { 00874 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).toString(); 00875 } 00876 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00889 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 00890 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) 00891 { 00892 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).toString(); 00893 } 00894 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00908 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> 00909 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) 00910 { 00911 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).toString(); 00912 } 00913 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00928 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> 00929 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) 00930 { 00931 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).toString(); 00932 } 00933 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00949 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> 00950 inline QString i18nc (const char *ctxt, const char *text, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) 00951 { 00952 return ki18nc(ctxt, text).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).subs(a9).toString(); 00953 } 00954 // <<<<< End of context calls 00955 00956 // >>>>> Plural calls 00957 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00965 template <typename A1> 00966 inline QString i18np (const char *sing, const char *plur, const A1 &a1) 00967 { 00968 return ki18np(sing, plur).subs(a1).toString(); 00969 } 00970 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00979 template <typename A1, typename A2> 00980 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2) 00981 { 00982 return ki18np(sing, plur).subs(a1).subs(a2).toString(); 00983 } 00984 // Autogenerated; contact KLocalizedString maintainer for batch changes. 00994 template <typename A1, typename A2, typename A3> 00995 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3) 00996 { 00997 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).toString(); 00998 } 00999 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01010 template <typename A1, typename A2, typename A3, typename A4> 01011 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) 01012 { 01013 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).toString(); 01014 } 01015 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01027 template <typename A1, typename A2, typename A3, typename A4, typename A5> 01028 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) 01029 { 01030 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).toString(); 01031 } 01032 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01045 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 01046 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) 01047 { 01048 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).toString(); 01049 } 01050 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01064 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> 01065 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) 01066 { 01067 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).toString(); 01068 } 01069 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01084 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> 01085 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) 01086 { 01087 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).toString(); 01088 } 01089 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01105 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> 01106 inline QString i18np (const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) 01107 { 01108 return ki18np(sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).subs(a9).toString(); 01109 } 01110 // <<<<< End of plural calls 01111 01112 // >>>>> Context-plural calls 01113 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01122 template <typename A1> 01123 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1) 01124 { 01125 return ki18ncp(ctxt, sing, plur).subs(a1).toString(); 01126 } 01127 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01137 template <typename A1, typename A2> 01138 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2) 01139 { 01140 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).toString(); 01141 } 01142 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01153 template <typename A1, typename A2, typename A3> 01154 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3) 01155 { 01156 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).toString(); 01157 } 01158 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01170 template <typename A1, typename A2, typename A3, typename A4> 01171 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4) 01172 { 01173 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).toString(); 01174 } 01175 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01188 template <typename A1, typename A2, typename A3, typename A4, typename A5> 01189 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5) 01190 { 01191 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).toString(); 01192 } 01193 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01207 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> 01208 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6) 01209 { 01210 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).toString(); 01211 } 01212 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01227 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> 01228 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7) 01229 { 01230 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).toString(); 01231 } 01232 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01248 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> 01249 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8) 01250 { 01251 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).toString(); 01252 } 01253 // Autogenerated; contact KLocalizedString maintainer for batch changes. 01270 template <typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> 01271 inline QString i18ncp (const char *ctxt, const char *sing, const char *plur, const A1 &a1, const A2 &a2, const A3 &a3, const A4 &a4, const A5 &a5, const A6 &a6, const A7 &a7, const A8 &a8, const A9 &a9) 01272 { 01273 return ki18ncp(ctxt, sing, plur).subs(a1).subs(a2).subs(a3).subs(a4).subs(a5).subs(a6).subs(a7).subs(a8).subs(a9).toString(); 01274 } 01275 // <<<<< End of context-plural calls 01276 01277 #endif
KDE 4.6 API Reference