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 <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 
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 KDECORE_EXPORT QString i18n(const char *text);
00074 
00082 KDECORE_EXPORT QString i18n(const char *comment, const char *text);
00083 
00095 KDECORE_EXPORT QString i18n(const char *singular, const char *plural, unsigned long n);
00096 
00103 inline QString tr2i18n(const char* message, const char* =0) {
00104   return i18n(message);
00105 }
00106 
00119 class KDECORE_EXPORT KLocale
00120 {
00121   friend class KGlobal; // for initInstance()
00122 public:
00139   KLocale( const QString& catalog, KConfig *config = 0 );
00140 
00144   KLocale( const KLocale & rhs );
00145 
00149   KLocale& operator= ( const KLocale & rhs );
00150 
00154   ~KLocale();
00155 
00174   QString translate( const char *index ) const;
00175 
00201   QString translate( const char *comment, const char *fallback) const;
00202 
00213   QString translate( const char *singular, const char *plural,
00214              unsigned long n) const;
00215 
00223   bool setEncoding(int mibEnum);
00224 
00234   bool setLanguage(const QString & language);
00235 
00245   bool setLanguage(const QStringList & languages);
00246  
00256   bool setCountry(const QString & country);
00257 
00262   enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1,
00263               AfterQuantityMoney = 2,
00264               BeforeMoney = 3, AfterMoney = 4 };
00265 
00272   QString decimalSymbol() const;
00273 
00281   QString thousandsSeparator() const;
00282 
00289   QString currencySymbol() const;
00290 
00298   QString monetaryDecimalSymbol() const;
00299 
00307   QString monetaryThousandsSeparator() const;
00308 
00315   QString positiveSign() const;
00316 
00323   QString negativeSign() const;
00324 
00331   int fracDigits() const;
00332 
00339   bool positivePrefixCurrencySymbol() const;
00340 
00347   bool negativePrefixCurrencySymbol() const;
00348 
00356   SignPosition positiveMonetarySignPosition() const;
00357 
00365   SignPosition negativeMonetarySignPosition() const;
00366 
00381   QString formatMoney(double num,
00382               const QString & currency = QString::null,
00383               int digits = -1) const;
00384 
00397   QString formatNumber(double num, int precision = -1) const;
00398 
00410   QString formatLong(long num) const;
00411 
00420    bool nounDeclension() const;
00421 
00431   QString formatDate(const QDate &pDate, bool shortFormat = false) const;
00432 
00440   bool dateMonthNamePossessive() const;
00441 
00454   QString formatTime(const QTime &pTime, bool includeSecs, bool isDuration /*=false*/) const;
00455 
00466   QString formatTime(const QTime &pTime, bool includeSecs = false) const; // BIC: merge with above
00467 
00473   bool use12Clock() const;
00474 
00484   bool weekStartsMonday() const KDE_DEPRECATED; //### remove for KDE 4.0
00485 
00492   int weekStartDay() const;
00493 
00514   QString monthName(int i, bool shortName = false) const KDE_DEPRECATED;
00515 
00539   QString monthNamePossessive(int i, bool shortName = false) const KDE_DEPRECATED;
00540 
00551   QString weekDayName(int i, bool shortName = false) const KDE_DEPRECATED;
00552 
00559   const KCalendarSystem * calendar() const;
00560 
00568   QString calendarType() const;
00569 
00578   void setCalendar(const QString & calendarType);
00579 
00590   QString formatDateTime(const QDateTime &pDateTime,
00591              bool shortFormat = true,
00592              bool includeSecs = false) const;
00593 
00603   double readMoney(const QString &numStr, bool * ok = 0) const;
00604 
00614   double readNumber(const QString &numStr, bool * ok = 0) const;
00615 
00626   QDate readDate(const QString &str, bool* ok = 0) const;
00627 
00632   QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
00633 
00634   enum ReadDateFlags {
00635       NormalFormat = 1,
00636       ShortFormat = 2
00637   };
00638 
00652   QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const;
00653 
00666   QTime readTime(const QString &str, bool* ok = 0) const;
00667 
00668   enum ReadTimeFlags {
00669       WithSeconds = 0, // default (no flag set)
00670       WithoutSeconds = 1
00671   }; // (maybe use this enum as a bitfield, if adding independent features?)
00686   QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const;
00687 
00695   QString language() const;
00696 
00703   QString country() const;
00704 
00718   QStringList languagesTwoAlpha() const;
00719 
00728   QStringList languageList() const;
00729 
00738   const char * encoding() const;
00739 
00748   int encodingMib() const;
00757   QTextCodec * codecForEncoding() const;
00758 
00767   int fileEncodingMib() const;
00768 
00790   void setDateFormat(const QString & format);
00812   void setDateFormatShort(const QString & format);
00819   void setDateMonthNamePossessive(bool possessive);
00838   void setTimeFormat(const QString & format);
00839 
00849   void setWeekStartsMonday(bool start) KDE_DEPRECATED; //### remove for KDE 4.0
00850 
00857   void setWeekStartDay(int day);
00864   QString dateFormat() const;
00871   QString dateFormatShort() const;
00878   QString timeFormat() const;
00879 
00885   void setDecimalSymbol(const QString & symbol);
00891   void setThousandsSeparator(const QString & separator);
00898   void setPositiveSign(const QString & sign);
00904   void setNegativeSign(const QString & sign);
00910   void setPositiveMonetarySignPosition(SignPosition signpos);
00916   void setNegativeMonetarySignPosition(SignPosition signpos);
00924   void setPositivePrefixCurrencySymbol(bool prefix);
00932   void setNegativePrefixCurrencySymbol(bool prefix);
00938   void setFracDigits(int digits);
00944   void setMonetaryThousandsSeparator(const QString & separator);
00951   void setMonetaryDecimalSymbol(const QString & symbol);
00957   void setCurrencySymbol(const QString & symbol);
00958 
00964   int pageSize() const;
00965 
00971   void setPageSize(int paperFormat);
00972 
00977   enum MeasureSystem { Metric, Imperial };
00978 
00984   MeasureSystem measureSystem() const;
00985 
00991   void setMeasureSystem(MeasureSystem value);
00992   
01003   void insertCatalogue(const QString& catalog);
01004 
01010   void removeCatalogue(const QString &catalog);
01011 
01016   void setActiveCatalogue(const QString &catalog);
01017 
01024   QString translateQt(const char *context,
01025               const char *sourceText,
01026               const char *message) const;
01027 
01033   QStringList allLanguagesTwoAlpha() const;
01034 
01041   QString twoAlphaToLanguageName(const QString &code) const;
01042 
01048   QStringList allCountriesTwoAlpha() const;
01049 
01056   QString twoAlphaToCountryName(const QString &code) const;
01057 
01067   static void splitLocale(const QString & str,
01068               QString & language,
01069               QString & country,
01070               QString & charset);
01071 
01080   static void setMainCatalogue(const char *catalog);
01081 
01088   static QString langLookup(const QString &fname, const char *rtype = "html");
01089 
01095   static QString defaultLanguage();
01096 
01102   static QString defaultCountry();
01103 
01104 
01108   static QString _initLanguage(KConfigBase *config);
01109 
01110 #ifdef KDE_NO_COMPAT
01111 private:
01112 #endif
01113 
01117   QString formatMoney(const QString &numStr) const KDE_DEPRECATED;
01118 
01123   QString formatNumber(const QString &numStr) const KDE_DEPRECATED;
01124 
01131   QString languages() const KDE_DEPRECATED;
01132 
01137   bool setCharset(const QString & charset) KDE_DEPRECATED;
01138 
01143   QString charset() const KDE_DEPRECATED;
01144 
01145 protected:
01150   static void initInstance();
01151 
01152 private:
01159   void initFormat(KConfig *config);
01160   
01167   void initMainCatalogues(const QString & catalog);
01168   
01177   void initLanguageList(KConfig * config, bool useEnv);
01178 
01184   void initEncoding(KConfig * config);
01185 
01190   void initFileNameEncoding(KConfig *config);
01191 
01195   static QCString encodeFileNameUTF8( const QString & fileName );
01196 
01200   static QString decodeFileNameUTF8( const QCString & localFileName );
01201 
01206   void initCatalogue( KCatalogue & catalog );
01207 
01211   void doFormatInit() const;
01212 
01216   void initFormat();
01217 
01221   QString translate_priv(const char *index,
01222              const char *text,
01223              const char ** original = 0,
01224              int* pluralType = 0) const;
01225 
01229   bool useDefaultLanguage() const;
01230 
01234   bool isLanguageInstalled(const QString & language) const;
01235   
01240   void updateCatalogues( );
01241   
01245   void initPluralTypes( );
01251   int pluralType( const QString & language );
01252   
01259   int pluralType( const KCatalogue& catalog );
01266   // const KCatalogue * catalog( const QString & language, const QString & name );
01267   
01268 
01273   static QString catalogueFileName(const QString & language,
01274                    const KCatalogue & catalog);
01275 
01281    bool isApplicationTranslatedInto( const QString & language);
01282    
01283 private:
01284   // Numbers and money
01285   QString m_decimalSymbol;
01286   QString m_thousandsSeparator;
01287   QString m_currencySymbol;
01288   QString m_monetaryDecimalSymbol;
01289   QString m_monetaryThousandsSeparator;
01290   QString m_positiveSign;
01291   QString m_negativeSign;
01292   int m_fracDigits;
01293   SignPosition m_positiveMonetarySignPosition;
01294   SignPosition m_negativeMonetarySignPosition;
01295 
01296   // Date and time
01297   QString m_timeFormat;
01298   QString m_dateFormat;
01299   QString m_dateFormatShort;
01300 
01301   QString m_language;
01302   QString m_country;
01303 
01304   bool m_weekStartsMonday; //### remove for KDE 4.0
01305   bool m_positivePrefixCurrencySymbol;
01306   bool m_negativePrefixCurrencySymbol;
01307 
01308   KLocalePrivate *d;
01309 };
01310 
01311 #endif
KDE Logo
This file is part of the documentation for kdecore Library Version 3.4.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Apr 22 16:00:20 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003