klocale.h
Go to the documentation of this file.
00001 // -*- c-basic-offset: 2 -*- 00002 /* This file is part of the KDE libraries 00003 Copyright (C) 1997 Stephan Kulow <coolo@kde.org> 00004 Copyright (C) 1999-2003 Hans Petter Bieker <bieker@kde.org> 00005 Copyright (c) 2002 Lukas Tinkl <lukas@kde.org> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #ifndef _KLOCALE_H 00023 #define _KLOCALE_H 00024 00025 #include <qstring.h> 00026 #include <kdelibs_export.h> 00027 00028 class QStringList; 00029 class QTextCodec; 00030 class QDate; 00031 class QTime; 00032 class QDateTime; 00033 00034 class KGlobal; 00035 class KConfig; 00036 class KConfigBase; 00037 class KLocalePrivate; 00038 class KCatalogue; 00039 class KCalendarSystem; 00040 00045 #ifndef I18N_NOOP 00046 00052 #define I18N_NOOP(x) x 00053 #endif 00054 00055 #ifndef I18N_NOOP2 00056 00063 #define I18N_NOOP2(comment,x) x 00064 #endif 00065 00078 KDECORE_EXPORT QString i18n(const char *text); 00079 00087 KDECORE_EXPORT QString i18n(const char *comment, const char *text); 00088 00100 KDECORE_EXPORT QString i18n(const char *singular, const char *plural, unsigned long n); 00101 00108 inline QString tr2i18n(const char* message, const char* =0) { 00109 return i18n(message); 00110 } 00111 00124 class KDECORE_EXPORT KLocale 00125 { 00126 friend class KGlobal; // for initInstance() 00127 public: 00144 KLocale( const QString& catalog, KConfig *config = 0 ); 00145 00149 KLocale( const KLocale & rhs ); 00150 00154 KLocale& operator= ( const KLocale & rhs ); 00155 00159 ~KLocale(); 00160 00179 QString translate( const char *index ) const; 00180 00206 QString translate( const char *comment, const char *fallback) const; 00207 00218 QString translate( const char *singular, const char *plural, 00219 unsigned long n) const; 00220 00228 bool setEncoding(int mibEnum); 00229 00239 bool setLanguage(const QString & language); 00240 00250 bool setLanguage(const QStringList & languages); 00251 00261 bool setCountry(const QString & country); 00262 00267 enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, 00268 AfterQuantityMoney = 2, 00269 BeforeMoney = 3, AfterMoney = 4 }; 00270 00277 QString decimalSymbol() const; 00278 00286 QString thousandsSeparator() const; 00287 00294 QString currencySymbol() const; 00295 00303 QString monetaryDecimalSymbol() const; 00304 00312 QString monetaryThousandsSeparator() const; 00313 00320 QString positiveSign() const; 00321 00328 QString negativeSign() const; 00329 00336 int fracDigits() const; 00337 00344 bool positivePrefixCurrencySymbol() const; 00345 00352 bool negativePrefixCurrencySymbol() const; 00353 00361 SignPosition positiveMonetarySignPosition() const; 00362 00370 SignPosition negativeMonetarySignPosition() const; 00371 00386 QString formatMoney(double num, 00387 const QString & currency = QString::null, 00388 int digits = -1) const; 00389 00405 QString formatNumber(double num, int precision = -1) const; 00406 00414 QString formatNumber(const QString &numStr) const KDE_DEPRECATED; 00415 00429 QString formatNumber(const QString &numStr, bool round, int precision) const; 00430 00442 QString formatLong(long num) const; 00443 00452 bool nounDeclension() const; 00453 00463 QString formatDate(const QDate &pDate, bool shortFormat = false) const; 00464 00472 bool dateMonthNamePossessive() const; 00473 00486 QString formatTime(const QTime &pTime, bool includeSecs, bool isDuration /*=false*/) const; 00487 00498 QString formatTime(const QTime &pTime, bool includeSecs = false) const; // BIC: merge with above 00499 00505 bool use12Clock() const; 00506 00516 bool weekStartsMonday() const KDE_DEPRECATED; //### remove for KDE 4.0 00517 00524 int weekStartDay() const; 00525 00546 QString monthName(int i, bool shortName = false) const KDE_DEPRECATED; 00547 00571 QString monthNamePossessive(int i, bool shortName = false) const KDE_DEPRECATED; 00572 00583 QString weekDayName(int i, bool shortName = false) const KDE_DEPRECATED; 00584 00591 const KCalendarSystem * calendar() const; 00592 00600 QString calendarType() const; 00601 00610 void setCalendar(const QString & calendarType); 00611 00622 QString formatDateTime(const QDateTime &pDateTime, 00623 bool shortFormat = true, 00624 bool includeSecs = false) const; 00625 00635 double readMoney(const QString &numStr, bool * ok = 0) const; 00636 00646 double readNumber(const QString &numStr, bool * ok = 0) const; 00647 00658 QDate readDate(const QString &str, bool* ok = 0) const; 00659 00664 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; 00665 00666 enum ReadDateFlags { 00667 NormalFormat = 1, 00668 ShortFormat = 2 00669 }; 00670 00684 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 00685 00698 QTime readTime(const QString &str, bool* ok = 0) const; 00699 00700 enum ReadTimeFlags { 00701 WithSeconds = 0, // default (no flag set) 00702 WithoutSeconds = 1 00703 }; // (maybe use this enum as a bitfield, if adding independent features?) 00718 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 00719 00727 QString language() const; 00728 00735 QString country() const; 00736 00750 QStringList languagesTwoAlpha() const; 00751 00760 QStringList languageList() const; 00761 00770 const char * encoding() const; 00771 00780 int encodingMib() const; 00789 QTextCodec * codecForEncoding() const; 00790 00799 int fileEncodingMib() const; 00800 00823 void setDateFormat(const QString & format); 00846 void setDateFormatShort(const QString & format); 00853 void setDateMonthNamePossessive(bool possessive); 00873 void setTimeFormat(const QString & format); 00874 00884 void setWeekStartsMonday(bool start) KDE_DEPRECATED; //### remove for KDE 4.0 00885 00892 void setWeekStartDay(int day); 00899 QString dateFormat() const; 00906 QString dateFormatShort() const; 00913 QString timeFormat() const; 00914 00920 void setDecimalSymbol(const QString & symbol); 00926 void setThousandsSeparator(const QString & separator); 00933 void setPositiveSign(const QString & sign); 00939 void setNegativeSign(const QString & sign); 00945 void setPositiveMonetarySignPosition(SignPosition signpos); 00951 void setNegativeMonetarySignPosition(SignPosition signpos); 00959 void setPositivePrefixCurrencySymbol(bool prefix); 00967 void setNegativePrefixCurrencySymbol(bool prefix); 00973 void setFracDigits(int digits); 00979 void setMonetaryThousandsSeparator(const QString & separator); 00986 void setMonetaryDecimalSymbol(const QString & symbol); 00992 void setCurrencySymbol(const QString & symbol); 00993 00999 int pageSize() const; 01000 01006 void setPageSize(int paperFormat); 01007 01012 enum MeasureSystem { Metric, Imperial }; 01013 01019 MeasureSystem measureSystem() const; 01020 01026 void setMeasureSystem(MeasureSystem value); 01027 01038 void insertCatalogue(const QString& catalog); 01039 01045 void removeCatalogue(const QString &catalog); 01046 01051 void setActiveCatalogue(const QString &catalog); 01052 01059 QString translateQt(const char *context, 01060 const char *sourceText, 01061 const char *message) const; 01062 01068 QStringList allLanguagesTwoAlpha() const; 01069 01076 QString twoAlphaToLanguageName(const QString &code) const; 01077 01083 QStringList allCountriesTwoAlpha() const; 01084 01091 QString twoAlphaToCountryName(const QString &code) const; 01092 01102 static void splitLocale(const QString & str, 01103 QString & language, 01104 QString & country, 01105 QString & charset); 01106 01115 static void setMainCatalogue(const char *catalog); 01116 01123 static QString langLookup(const QString &fname, const char *rtype = "html"); 01124 01130 static QString defaultLanguage(); 01131 01137 static QString defaultCountry(); 01138 01139 01143 static QString _initLanguage(KConfigBase *config); 01144 01145 #ifdef KDE_NO_COMPAT 01146 private: 01147 #endif 01148 01152 QString formatMoney(const QString &numStr) const KDE_DEPRECATED; 01153 01160 QString languages() const KDE_DEPRECATED; 01161 01166 bool setCharset(const QString & charset) KDE_DEPRECATED; 01167 01172 QString charset() const KDE_DEPRECATED; 01173 01174 protected: 01179 static void initInstance(); 01180 01181 private: 01188 void initFormat(KConfig *config); 01189 01196 void initMainCatalogues(const QString & catalog); 01197 01206 void initLanguageList(KConfig * config, bool useEnv); 01207 01213 void initEncoding(KConfig * config); 01214 01219 void initFileNameEncoding(KConfig *config); 01220 01224 static QCString encodeFileNameUTF8( const QString & fileName ); 01225 01229 static QString decodeFileNameUTF8( const QCString & localFileName ); 01230 01235 void initCatalogue( KCatalogue & catalog ); 01236 01240 void doFormatInit() const; 01241 01245 void initFormat(); 01246 01250 QString translate_priv(const char *index, 01251 const char *text, 01252 const char ** original = 0, 01253 int* pluralType = 0) const; 01254 01258 bool useDefaultLanguage() const; 01259 01263 bool isLanguageInstalled(const QString & language) const; 01264 01269 void updateCatalogues( ); 01270 01274 void initPluralTypes( ); 01280 int pluralType( const QString & language ); 01281 01288 int pluralType( const KCatalogue& catalog ); 01295 // const KCatalogue * catalog( const QString & language, const QString & name ); 01296 01297 01302 static QString catalogueFileName(const QString & language, 01303 const KCatalogue & catalog); 01304 public: 01310 bool isApplicationTranslatedInto( const QString & language); 01311 01312 private: 01313 // Numbers and money 01314 QString m_decimalSymbol; 01315 QString m_thousandsSeparator; 01316 QString m_currencySymbol; 01317 QString m_monetaryDecimalSymbol; 01318 QString m_monetaryThousandsSeparator; 01319 QString m_positiveSign; 01320 QString m_negativeSign; 01321 int m_fracDigits; 01322 SignPosition m_positiveMonetarySignPosition; 01323 SignPosition m_negativeMonetarySignPosition; 01324 01325 // Date and time 01326 QString m_timeFormat; 01327 QString m_dateFormat; 01328 QString m_dateFormatShort; 01329 01330 QString m_language; 01331 QString m_country; 01332 01333 bool m_weekStartsMonday; //### remove for KDE 4.0 01334 bool m_positivePrefixCurrencySymbol; 01335 bool m_negativePrefixCurrencySymbol; 01336 01337 KLocalePrivate *d; 01338 }; 01339 01340 #endif