kdecore Library API Documentation

klocale.h

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., 59 Temple Place - Suite 330, 00020 Boston, MA 02111-1307, USA. 00021 */ 00022 #ifndef _KLOCALE_H 00023 #define _KLOCALE_H 00024 00025 #include <qstring.h> 00026 #include "kdemacros.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 00041 #ifndef I18N_NOOP 00042 00047 #define I18N_NOOP(x) x 00048 #endif 00049 00062 QString i18n(const char *text); 00063 00071 QString i18n(const char *comment, const char *text); 00072 00079 QString i18n(const char *singular, const char *plural, unsigned long n); 00080 00087 inline QString tr2i18n(const char* message, const char* =0) { 00088 return i18n(message); 00089 } 00090 00103 class KLocale 00104 { 00105 friend class KGlobal; // for initInstance() 00106 public: 00123 KLocale( const QString& catalog, KConfig *config = 0 ); 00124 00128 KLocale( const KLocale & rhs ); 00129 00133 KLocale& operator= ( const KLocale & rhs ); 00134 00138 ~KLocale(); 00139 00158 QString translate( const char *index ) const; 00159 00185 QString translate( const char *comment, const char *fallback) const; 00186 00197 QString translate( const char *singular, const char *plural, 00198 unsigned long n) const; 00199 00207 bool setEncoding(int mibEnum); 00208 00218 bool setLanguage(const QString & language); 00219 00229 bool setLanguage(const QStringList & languages); 00230 00240 bool setCountry(const QString & country); 00241 00246 enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, 00247 AfterQuantityMoney = 2, 00248 BeforeMoney = 3, AfterMoney = 4 }; 00249 00256 QString decimalSymbol() const; 00257 00265 QString thousandsSeparator() const; 00266 00273 QString currencySymbol() const; 00274 00282 QString monetaryDecimalSymbol() const; 00283 00291 QString monetaryThousandsSeparator() const; 00292 00299 QString positiveSign() const; 00300 00307 QString negativeSign() const; 00308 00315 int fracDigits() const; 00316 00323 bool positivePrefixCurrencySymbol() const; 00324 00331 bool negativePrefixCurrencySymbol() const; 00332 00340 SignPosition positiveMonetarySignPosition() const; 00341 00349 SignPosition negativeMonetarySignPosition() const; 00350 00365 QString formatMoney(double num, 00366 const QString & currency = QString::null, 00367 int digits = -1) const; 00368 00381 QString formatNumber(double num, int precision = -1) const; 00382 00394 QString formatLong(long num) const; 00395 00404 bool nounDeclension() const; 00405 00415 QString formatDate(const QDate &pDate, bool shortFormat = false) const; 00416 00424 bool dateMonthNamePossessive() const; 00425 00436 QString formatTime(const QTime &pTime, bool includeSecs = false) const; 00437 00443 bool use12Clock() const; 00444 00454 bool weekStartsMonday() const KDE_DEPRECATED; //### remove for KDE 4.0 00455 00462 int weekStartDay() const; 00463 00474 QString monthName(int i, bool shortName = false) const KDE_DEPRECATED; 00475 00489 QString monthNamePossessive(int i, bool shortName = false) const KDE_DEPRECATED; 00490 00501 QString weekDayName(int i, bool shortName = false) const KDE_DEPRECATED; 00502 00509 const KCalendarSystem * calendar() const; 00510 00518 QString calendarType() const; 00519 00528 void setCalendar(const QString & calendarType); 00529 00540 QString formatDateTime(const QDateTime &pDateTime, 00541 bool shortFormat = true, 00542 bool includeSecs = false) const; 00543 00553 double readMoney(const QString &numStr, bool * ok = 0) const; 00554 00564 double readNumber(const QString &numStr, bool * ok = 0) const; 00565 00576 QDate readDate(const QString &str, bool* ok = 0) const; 00577 00582 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; 00583 00584 enum ReadDateFlags { 00585 NormalFormat = 1, 00586 ShortFormat = 2 00587 }; 00588 00602 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 00603 00615 QTime readTime(const QString &str, bool* ok = 0) const; 00616 00617 enum ReadTimeFlags { 00618 WithSeconds = 0, // default (no flag set) 00619 WithoutSeconds = 1 00620 }; // (maybe use this enum as a bitfield, if adding independent features?) 00635 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 00636 00644 QString language() const; 00645 00652 QString country() const; 00653 00667 QStringList languagesTwoAlpha() const; 00668 00677 QStringList languageList() const; 00678 00687 const char * encoding() const; 00688 00697 int encodingMib() const; 00706 QTextCodec * codecForEncoding() const; 00707 00716 int fileEncodingMib() const; 00717 00738 void setDateFormat(const QString & format); 00759 void setDateFormatShort(const QString & format); 00766 void setDateMonthNamePossessive(bool possessive); 00785 void setTimeFormat(const QString & format); 00786 00796 void setWeekStartsMonday(bool start) KDE_DEPRECATED; //### remove for KDE 4.0 00797 00804 void setWeekStartDay(int day); 00811 QString dateFormat() const; 00818 QString dateFormatShort() const; 00825 QString timeFormat() const; 00826 00832 void setDecimalSymbol(const QString & symbol); 00838 void setThousandsSeparator(const QString & separator); 00845 void setPositiveSign(const QString & sign); 00851 void setNegativeSign(const QString & sign); 00857 void setPositiveMonetarySignPosition(SignPosition signpos); 00863 void setNegativeMonetarySignPosition(SignPosition signpos); 00871 void setPositivePrefixCurrencySymbol(bool prefix); 00879 void setNegativePrefixCurrencySymbol(bool prefix); 00885 void setFracDigits(int digits); 00891 void setMonetaryThousandsSeparator(const QString & separator); 00898 void setMonetaryDecimalSymbol(const QString & symbol); 00904 void setCurrencySymbol(const QString & symbol); 00905 00911 int pageSize() const; 00912 00918 void setPageSize(int paperFormat); 00919 00924 enum MeasureSystem { Metric, Imperial }; 00925 00931 MeasureSystem measureSystem() const; 00932 00938 void setMeasureSystem(MeasureSystem value); 00939 00950 void insertCatalogue(const QString& catalog); 00951 00957 void removeCatalogue(const QString &catalog); 00958 00963 void setActiveCatalogue(const QString &catalog); 00964 00971 QString translateQt(const char *context, 00972 const char *sourceText, 00973 const char *message) const; 00974 00980 QStringList allLanguagesTwoAlpha() const; 00981 00988 QString twoAlphaToLanguageName(const QString &code) const; 00989 00995 QStringList allCountriesTwoAlpha() const; 00996 01003 QString twoAlphaToCountryName(const QString &code) const; 01004 01014 static void splitLocale(const QString & str, 01015 QString & language, 01016 QString & country, 01017 QString & charset); 01018 01027 static void setMainCatalogue(const char *catalog); 01028 01035 static QString langLookup(const QString &fname, const char *rtype = "html"); 01036 01042 static QString defaultLanguage(); 01043 01049 static QString defaultCountry(); 01050 01051 01055 static QString _initLanguage(KConfigBase *config); 01056 01057 #ifdef KDE_NO_COMPAT 01058 private: 01059 #endif 01064 QString formatMoney(const QString &numStr) const KDE_DEPRECATED; 01065 01070 QString formatNumber(const QString &numStr) const KDE_DEPRECATED; 01071 01078 QString languages() const KDE_DEPRECATED; 01079 01084 bool setCharset(const QString & charset) KDE_DEPRECATED; 01085 01090 QString charset() const KDE_DEPRECATED; 01091 01092 protected: 01097 static void initInstance(); 01098 01099 private: 01106 void initFormat(KConfig *config); 01107 01114 void initMainCatalogues(const QString & catalog); 01115 01124 void initLanguageList(KConfig * config, bool useEnv); 01125 01131 void initEncoding(KConfig * config); 01132 01137 void initFileNameEncoding(KConfig *config); 01138 01142 static QCString encodeFileNameUTF8( const QString & fileName ); 01143 01147 static QString decodeFileNameUTF8( const QCString & localFileName ); 01148 01153 void initCatalogue( KCatalogue & catalog ); 01154 01158 void doFormatInit() const; 01159 01163 void initFormat(); 01164 01168 QString translate_priv(const char *index, 01169 const char *text, 01170 const char ** original = 0, 01171 int* pluralType = 0) const; 01172 01176 bool useDefaultLanguage() const; 01177 01181 bool isLanguageInstalled(const QString & language) const; 01182 01187 void updateCatalogues( ); 01188 01192 void initPluralTypes( ); 01198 int pluralType( const QString & language ); 01199 01206 int pluralType( const KCatalogue& catalog ); 01213 // const KCatalogue * catalog( const QString & language, const QString & name ); 01214 01215 01220 static QString catalogueFileName(const QString & language, 01221 const KCatalogue & catalog); 01222 01228 bool isApplicationTranslatedInto( const QString & language); 01229 01230 01231 private: 01232 // Numbers and money 01233 QString m_decimalSymbol; 01234 QString m_thousandsSeparator; 01235 QString m_currencySymbol; 01236 QString m_monetaryDecimalSymbol; 01237 QString m_monetaryThousandsSeparator; 01238 QString m_positiveSign; 01239 QString m_negativeSign; 01240 int m_fracDigits; 01241 SignPosition m_positiveMonetarySignPosition; 01242 SignPosition m_negativeMonetarySignPosition; 01243 01244 // Date and time 01245 QString m_timeFormat; 01246 QString m_dateFormat; 01247 QString m_dateFormatShort; 01248 01249 QString m_language; 01250 QString m_country; 01251 01252 bool m_weekStartsMonday; //### remove for KDE 4.0 01253 bool m_positivePrefixCurrencySymbol; 01254 bool m_negativePrefixCurrencySymbol; 01255 01256 KLocalePrivate *d; 01257 }; 01258 01259 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.2.3.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 8 11:14:01 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003