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 00048 #define I18N_NOOP(x) x 00049 #endif 00050 00051 #ifndef I18N_NOOP2 00052 00058 #define I18N_NOOP2(comment,x) x 00059 #endif 00060 00073 QString i18n(const char *text); 00074 00082 QString i18n(const char *comment, const char *text); 00083 00090 QString i18n(const char *singular, const char *plural, unsigned long n); 00091 00098 inline QString tr2i18n(const char* message, const char* =0) { 00099 return i18n(message); 00100 } 00101 00114 class KLocale 00115 { 00116 friend class KGlobal; // for initInstance() 00117 public: 00134 KLocale( const QString& catalog, KConfig *config = 0 ); 00135 00139 KLocale( const KLocale & rhs ); 00140 00144 KLocale& operator= ( const KLocale & rhs ); 00145 00149 ~KLocale(); 00150 00169 QString translate( const char *index ) const; 00170 00196 QString translate( const char *comment, const char *fallback) const; 00197 00208 QString translate( const char *singular, const char *plural, 00209 unsigned long n) const; 00210 00218 bool setEncoding(int mibEnum); 00219 00229 bool setLanguage(const QString & language); 00230 00240 bool setLanguage(const QStringList & languages); 00241 00251 bool setCountry(const QString & country); 00252 00257 enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, 00258 AfterQuantityMoney = 2, 00259 BeforeMoney = 3, AfterMoney = 4 }; 00260 00267 QString decimalSymbol() const; 00268 00276 QString thousandsSeparator() const; 00277 00284 QString currencySymbol() const; 00285 00293 QString monetaryDecimalSymbol() const; 00294 00302 QString monetaryThousandsSeparator() const; 00303 00310 QString positiveSign() const; 00311 00318 QString negativeSign() const; 00319 00326 int fracDigits() const; 00327 00334 bool positivePrefixCurrencySymbol() const; 00335 00342 bool negativePrefixCurrencySymbol() const; 00343 00351 SignPosition positiveMonetarySignPosition() const; 00352 00360 SignPosition negativeMonetarySignPosition() const; 00361 00376 QString formatMoney(double num, 00377 const QString & currency = QString::null, 00378 int digits = -1) const; 00379 00392 QString formatNumber(double num, int precision = -1) const; 00393 00405 QString formatLong(long num) const; 00406 00415 bool nounDeclension() const; 00416 00426 QString formatDate(const QDate &pDate, bool shortFormat = false) const; 00427 00435 bool dateMonthNamePossessive() const; 00436 00449 QString formatTime(const QTime &pTime, bool includeSecs, bool isDuration /*=false*/) const; 00450 00461 QString formatTime(const QTime &pTime, bool includeSecs = false) const; // BIC: merge with above 00462 00468 bool use12Clock() const; 00469 00479 bool weekStartsMonday() const KDE_DEPRECATED; //### remove for KDE 4.0 00480 00487 int weekStartDay() const; 00488 00509 QString monthName(int i, bool shortName = false) const KDE_DEPRECATED; 00510 00534 QString monthNamePossessive(int i, bool shortName = false) const KDE_DEPRECATED; 00535 00546 QString weekDayName(int i, bool shortName = false) const KDE_DEPRECATED; 00547 00554 const KCalendarSystem * calendar() const; 00555 00563 QString calendarType() const; 00564 00573 void setCalendar(const QString & calendarType); 00574 00585 QString formatDateTime(const QDateTime &pDateTime, 00586 bool shortFormat = true, 00587 bool includeSecs = false) const; 00588 00598 double readMoney(const QString &numStr, bool * ok = 0) const; 00599 00609 double readNumber(const QString &numStr, bool * ok = 0) const; 00610 00621 QDate readDate(const QString &str, bool* ok = 0) const; 00622 00627 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const; 00628 00629 enum ReadDateFlags { 00630 NormalFormat = 1, 00631 ShortFormat = 2 00632 }; 00633 00647 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 00648 00661 QTime readTime(const QString &str, bool* ok = 0) const; 00662 00663 enum ReadTimeFlags { 00664 WithSeconds = 0, // default (no flag set) 00665 WithoutSeconds = 1 00666 }; // (maybe use this enum as a bitfield, if adding independent features?) 00681 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 00682 00690 QString language() const; 00691 00698 QString country() const; 00699 00713 QStringList languagesTwoAlpha() const; 00714 00723 QStringList languageList() const; 00724 00733 const char * encoding() const; 00734 00743 int encodingMib() const; 00752 QTextCodec * codecForEncoding() const; 00753 00762 int fileEncodingMib() const; 00763 00785 void setDateFormat(const QString & format); 00807 void setDateFormatShort(const QString & format); 00814 void setDateMonthNamePossessive(bool possessive); 00833 void setTimeFormat(const QString & format); 00834 00844 void setWeekStartsMonday(bool start) KDE_DEPRECATED; //### remove for KDE 4.0 00845 00852 void setWeekStartDay(int day); 00859 QString dateFormat() const; 00866 QString dateFormatShort() const; 00873 QString timeFormat() const; 00874 00880 void setDecimalSymbol(const QString & symbol); 00886 void setThousandsSeparator(const QString & separator); 00893 void setPositiveSign(const QString & sign); 00899 void setNegativeSign(const QString & sign); 00905 void setPositiveMonetarySignPosition(SignPosition signpos); 00911 void setNegativeMonetarySignPosition(SignPosition signpos); 00919 void setPositivePrefixCurrencySymbol(bool prefix); 00927 void setNegativePrefixCurrencySymbol(bool prefix); 00933 void setFracDigits(int digits); 00939 void setMonetaryThousandsSeparator(const QString & separator); 00946 void setMonetaryDecimalSymbol(const QString & symbol); 00952 void setCurrencySymbol(const QString & symbol); 00953 00959 int pageSize() const; 00960 00966 void setPageSize(int paperFormat); 00967 00972 enum MeasureSystem { Metric, Imperial }; 00973 00979 MeasureSystem measureSystem() const; 00980 00986 void setMeasureSystem(MeasureSystem value); 00987 00998 void insertCatalogue(const QString& catalog); 00999 01005 void removeCatalogue(const QString &catalog); 01006 01011 void setActiveCatalogue(const QString &catalog); 01012 01019 QString translateQt(const char *context, 01020 const char *sourceText, 01021 const char *message) const; 01022 01028 QStringList allLanguagesTwoAlpha() const; 01029 01036 QString twoAlphaToLanguageName(const QString &code) const; 01037 01043 QStringList allCountriesTwoAlpha() const; 01044 01051 QString twoAlphaToCountryName(const QString &code) const; 01052 01062 static void splitLocale(const QString & str, 01063 QString & language, 01064 QString & country, 01065 QString & charset); 01066 01075 static void setMainCatalogue(const char *catalog); 01076 01083 static QString langLookup(const QString &fname, const char *rtype = "html"); 01084 01090 static QString defaultLanguage(); 01091 01097 static QString defaultCountry(); 01098 01099 01103 static QString _initLanguage(KConfigBase *config); 01104 01105 #ifdef KDE_NO_COMPAT 01106 private: 01107 #endif 01112 QString formatMoney(const QString &numStr) const KDE_DEPRECATED; 01113 01118 QString formatNumber(const QString &numStr) const KDE_DEPRECATED; 01119 01126 QString languages() const KDE_DEPRECATED; 01127 01132 bool setCharset(const QString & charset) KDE_DEPRECATED; 01133 01138 QString charset() const KDE_DEPRECATED; 01139 01140 protected: 01145 static void initInstance(); 01146 01147 private: 01154 void initFormat(KConfig *config); 01155 01162 void initMainCatalogues(const QString & catalog); 01163 01172 void initLanguageList(KConfig * config, bool useEnv); 01173 01179 void initEncoding(KConfig * config); 01180 01185 void initFileNameEncoding(KConfig *config); 01186 01190 static QCString encodeFileNameUTF8( const QString & fileName ); 01191 01195 static QString decodeFileNameUTF8( const QCString & localFileName ); 01196 01201 void initCatalogue( KCatalogue & catalog ); 01202 01206 void doFormatInit() const; 01207 01211 void initFormat(); 01212 01216 QString translate_priv(const char *index, 01217 const char *text, 01218 const char ** original = 0, 01219 int* pluralType = 0) const; 01220 01224 bool useDefaultLanguage() const; 01225 01229 bool isLanguageInstalled(const QString & language) const; 01230 01235 void updateCatalogues( ); 01236 01240 void initPluralTypes( ); 01246 int pluralType( const QString & language ); 01247 01254 int pluralType( const KCatalogue& catalog ); 01261 // const KCatalogue * catalog( const QString & language, const QString & name ); 01262 01263 01268 static QString catalogueFileName(const QString & language, 01269 const KCatalogue & catalog); 01270 01276 bool isApplicationTranslatedInto( const QString & language); 01277 01278 private: 01279 // Numbers and money 01280 QString m_decimalSymbol; 01281 QString m_thousandsSeparator; 01282 QString m_currencySymbol; 01283 QString m_monetaryDecimalSymbol; 01284 QString m_monetaryThousandsSeparator; 01285 QString m_positiveSign; 01286 QString m_negativeSign; 01287 int m_fracDigits; 01288 SignPosition m_positiveMonetarySignPosition; 01289 SignPosition m_negativeMonetarySignPosition; 01290 01291 // Date and time 01292 QString m_timeFormat; 01293 QString m_dateFormat; 01294 QString m_dateFormatShort; 01295 01296 QString m_language; 01297 QString m_country; 01298 01299 bool m_weekStartsMonday; //### remove for KDE 4.0 01300 bool m_positivePrefixCurrencySymbol; 01301 bool m_negativePrefixCurrencySymbol; 01302 01303 KLocalePrivate *d; 01304 }; 01305 01306 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:40:08 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003