KDECore
klocale.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 1997 Stephan Kulow <coolo@kde.org> 00003 Copyright (C) 1999-2003 Hans Petter Bieker <bieker@kde.org> 00004 Copyright (c) 2002 Lukas Tinkl <lukas@kde.org> 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Library General Public 00008 License as published by the Free Software Foundation; either 00009 version 2 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Library General Public License for more details. 00015 00016 You should have received a copy of the GNU Library General Public License 00017 along with this library; see the file COPYING.LIB. If not, write to 00018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00019 Boston, MA 02110-1301, USA. 00020 */ 00021 #ifndef KLOCALE_H 00022 #define KLOCALE_H 00023 00024 #include <kdecore_export.h> 00025 #include <klocalizedstring.h> 00026 #include <ksharedconfig.h> 00027 00028 #include <QtCore/QString> 00029 #include <QtCore/QList> 00030 00031 class QStringList; 00032 class QTextCodec; 00033 class QDate; 00034 class QTime; 00035 class QDateTime; 00036 00037 class KDateTime; 00038 class KCalendarSystem; 00039 class KCurrencyCode; 00040 class KDayPeriod; 00041 00042 class KLocalePrivate; 00043 00069 class KDECORE_EXPORT KLocale 00070 { 00071 public: 00095 explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = KSharedConfig::Ptr()); 00096 00114 KLocale(const QString& catalog, const QString &language, const QString &country = QString(), 00115 KConfig *config = 0); 00116 00120 KLocale(const KLocale & rhs); 00121 00125 KLocale& operator= (const KLocale & rhs); 00126 00130 virtual ~KLocale(); 00131 00153 void translateRawFrom(const char* catname, const char* msg, QString *lang, QString *trans) const; 00154 00160 void translateRaw(const char* msg, QString *lang, QString *trans) const; 00161 00185 void translateRawFrom(const char *catname, const char *ctxt, const char *msg, QString *lang, QString *trans) const; 00186 00192 void translateRaw(const char *ctxt, const char *msg, QString *lang, QString *trans) const; 00193 00219 void translateRawFrom(const char *catname, const char *singular, const char *plural, unsigned long n, 00220 QString *lang, QString *trans) const; 00221 00227 void translateRaw(const char *singular, const char *plural, unsigned long n, QString *lang, 00228 QString *trans) const; 00229 00257 void translateRawFrom(const char *catname, const char *ctxt, const char *singular, const char *plural, 00258 unsigned long n, QString *lang, QString *trans) const; 00259 00265 void translateRaw(const char *ctxt, const char *singular, const char *plural, unsigned long n, 00266 QString *lang, QString *trans) const; 00267 00275 bool setEncoding(int mibEnum); 00276 00281 enum SignPosition { 00285 ParensAround = 0, 00289 BeforeQuantityMoney = 1, 00293 AfterQuantityMoney = 2, 00297 BeforeMoney = 3, 00301 AfterMoney = 4 00302 }; 00303 00309 enum DigitSet { 00310 ArabicDigits, 00312 ArabicIndicDigits, 00313 EasternArabicIndicDigits, 00314 DevenagariDigits, 00315 BengaliDigits, 00316 GujaratiDigits, 00317 GurmukhiDigits, 00318 KannadaDigits, 00319 KhmerDigits, 00320 MalayalamDigits, 00321 OriyaDigits, 00322 TamilDigits, 00323 TeluguDigits, 00324 ThaiDigits 00325 // The following Decimal Digit Sets are defined in Unicode but the associated 00326 // languages are not yet translated in KDE, so are not yet enabled. 00327 // The script names are taken from the Unicode standard, the associated 00328 // languages from Wikipedia. 00329 // BalineseDigits, /**< ᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙ (Balinese) */ 00330 // ChamDigits, /**< ꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙ (Cham) */ 00331 // JavaneseDigits, /**< ꧐꧑꧒꧓꧔꧕꧖꧗꧘꧙ (Javanese) */ 00332 // KayahLiDigits, /**< ꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉ (Kayah) */ 00333 // LaoDigits, /**< ໐໑໒໓໔໕໖໗໘໙ (Lao) */ 00334 // LepchaDigits, /**< ᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉ (Lepcha) */ 00335 // LimbuDigits, /**< ᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏ (Limbu) */ 00336 // MeeteiMayekDigits, /**< ꯰꯱꯲꯳꯴꯵꯶꯷꯸꯹ (Meitei) */ 00337 // MongolianDigits, /**< ᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙ (Mongolian) */ 00338 // MyanmarDigits, /**< ၀၁၂၃၄၅၆၇၈၉ (Myanmar/Burmese ) */ 00339 // MyanmarShanDigits, /**< ႐႑႒႓႔႕႖႗႘႙ (Shan) */ 00340 // NewTaiLueDigits, /**< ᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙ (Tai Lü) */ 00341 // NKoDigits, /**< ߀߁߂߃߄߅߆߇߈߉ (Mande and N'Ko) */ 00342 // OlChikiDigits, /**< ᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙ (Santali) */ 00343 // OsmanyaDigits, /**< ҠҡҢңҤҥҦҧҨҩ (Somali) */ 00344 // SaurashtraDigits, /**< ꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙ (Saurashtra) */ 00345 // SundaneseDigits, /**< ᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹ (Sundanese) */ 00346 // TaiThamDigits, /**< ᪐᪑᪒᪓᪔᪕᪖᪗᪘᪙ (Tai Lü) */ 00347 // TibetanDigits, /**< ༠༡༢༣༤༥༦༧༨༩ (Tibetan) */ 00348 // VaiDigits, /**< ꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩ (Vai) */ 00349 }; 00350 00363 QString digitSetToName(DigitSet digitSet, bool withDigits = false) const; 00364 00374 QList<DigitSet> allDigitSetsList() const; 00375 00382 QString decimalSymbol() const; 00383 00391 QString thousandsSeparator() const; 00392 00402 DigitSet digitSet() const; 00403 00411 QString currencyCode() const; 00412 00420 KCurrencyCode *currency() const; 00421 00428 QString currencySymbol() const; 00429 00437 QString monetaryDecimalSymbol() const; 00438 00446 QString monetaryThousandsSeparator() const; 00447 00454 QString positiveSign() const; 00455 00462 QString negativeSign() const; 00463 00471 int fracDigits() const; 00472 00480 int decimalPlaces() const; 00481 00489 int monetaryDecimalPlaces() const; 00490 00497 bool positivePrefixCurrencySymbol() const; 00498 00505 bool negativePrefixCurrencySymbol() const; 00506 00514 SignPosition positiveMonetarySignPosition() const; 00515 00523 SignPosition negativeMonetarySignPosition() const; 00524 00534 DigitSet monetaryDigitSet() const; 00535 00551 QString formatMoney(double num, const QString ¤cy = QString(), int precision = -1) const; 00552 00570 QString formatNumber(double num, int precision = -1) const; 00571 00586 QString formatNumber(const QString &numStr, bool round = true, int precision = -1) const; 00587 00598 QString formatLong(long num) const; 00599 00621 enum BinarySizeUnits { 00623 DefaultBinaryUnits = -1, 00624 00625 // The first real unit must be 0 for the current implementation! 00626 UnitByte, 00627 UnitKiloByte, 00628 UnitMegaByte, 00629 UnitGigaByte, 00630 UnitTeraByte, 00631 UnitPetaByte, 00632 UnitExaByte, 00633 UnitZettaByte, 00634 UnitYottaByte, 00635 UnitLastUnit = UnitYottaByte 00636 }; 00637 00656 enum BinaryUnitDialect { 00657 DefaultBinaryDialect = -1, 00658 IECBinaryDialect, 00659 JEDECBinaryDialect, 00660 MetricBinaryDialect, 00661 LastBinaryDialect = MetricBinaryDialect 00662 }; 00663 00677 QString formatByteSize(double size) const; 00678 00703 QString formatByteSize(double size, int precision, 00704 BinaryUnitDialect dialect = KLocale::DefaultBinaryDialect, 00705 BinarySizeUnits specificUnit = KLocale::DefaultBinaryUnits) const; 00706 00714 BinaryUnitDialect binaryUnitDialect() const; 00715 00724 void setBinaryUnitDialect(BinaryUnitDialect newDialect); 00725 00735 QString formatDuration(unsigned long mSec) const; 00736 00752 QString prettyFormatDuration(unsigned long mSec) const; 00753 00763 bool nounDeclension() const; 00764 00765 //KDE5 move to KDateTime namespace 00774 enum CalendarSystem { 00775 QDateCalendar = 1, 00776 //BahaiCalendar = 2, /**< Baha'i Calendar */ 00777 //BuddhistLunarCalendar = 3, /**< Buddhist Lunar Calendar*/ 00778 //ChineseCalendar = 4, /**< Chinese Calendar */ 00779 CopticCalendar = 5, 00780 EthiopianCalendar = 6, 00781 //EthiopianAmeteAlemCalendar = 7, /**< Ethiopian Amete Alem version, aka Ethiopic Amete Alem */ 00782 GregorianCalendar = 8, 00783 HebrewCalendar = 9, 00784 //HinduCalendar = 10, /**< Hindu Lunar Calendar */ 00785 //IslamicLunarCalendar = 11, /**< Islamic Lunar Calendar */ 00786 IslamicCivilCalendar = 12, 00787 //IslamicUmAlQuraCalendar = 13, /**< Islamic Lunar Calendar, Um Al Qura varient used in Saudi Arabia */ 00788 IndianNationalCalendar = 14, 00789 //Iso8601Calendar = 15, /**< ISO 8601 Standard Calendar */ 00790 JalaliCalendar = 16, 00791 //JalaliBirashkCalendar = 17, /**< Jalali Calendar, Birashk Algorythm variant */ 00792 //Jalali33YearCalendar = 18, /**< Jalali Calendar, 33 Year cycle variant */ 00793 JapaneseCalendar= 19, 00794 //JucheCalendar = 20, /**< Juche Calendar, used in North Korea */ 00795 JulianCalendar = 21, 00796 MinguoCalendar= 22, 00797 ThaiCalendar = 23 00798 }; 00799 00800 //KDE5 move to KDateTime namespace 00809 enum WeekNumberSystem { 00810 DefaultWeekNumber = -1, 00811 IsoWeekNumber = 0 00812 //UsaWeekNumber = 1 /**< USA Week Number */ 00813 }; 00814 00815 //KDE5 move to KDateTime namespace 00821 enum DateTimeFormatStandard { 00822 KdeFormat, 00823 PosixFormat, 00824 UnicodeFormat 00825 }; 00826 00827 //KDE5 move to KDateTime namespace 00833 enum DateTimeParseMode { 00834 LiberalParsing 00837 //ModerateParsing, /**< Parse Date/Time with modeate tolerance. 00838 // The date components in the format must all 00839 // occur in the input and in the same order, 00840 // but the spacing and the componants themselves 00841 // may vary from the strict format. */ 00842 //StrictParsing /**< Parse Date/Time strictly to the format. */ 00843 }; 00844 00845 //KDE5 move to KDateTime namespace 00857 enum DateTimeComponent { 00858 Year = 0x1, 00859 YearName = 0x2, 00860 Month = 0x4, 00861 MonthName = 0x8, 00862 Day = 0x10, 00863 DayName = 0x20, 00864 JulianDay = 0x40, 00865 EraName = 0x80, 00866 EraYear = 0x100, 00867 YearInEra = 0x200, 00868 DayOfYear = 0x400, 00869 DayOfYearName = 0x800, 00870 DayOfWeek = 0x1000, 00871 DayOfWeekName = 0x2000, 00872 Week = 0x4000, 00873 WeekYear = 0x8000, 00874 MonthsInYear = 0x10000, 00875 WeeksInYear = 0x20000, 00876 DaysInYear = 0x40000, 00877 DaysInMonth = 0x80000, 00878 DaysInWeek = 0x100000, 00879 Hour = 0x200000, 00880 Minute = 0x400000, 00881 Second = 0x800000, 00882 Millisecond = 0x1000000, 00883 DayPeriod = 0x2000000, 00884 DayPeriodHour = 0x4000000, 00885 Timezone = 0x8000000, 00886 TimezoneName = 0x10000000, 00887 UnixTime = 0x20000000 00888 }; 00889 Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent) 00890 00891 //KDE5 move to KDateTime namespace 00900 enum DateTimeComponentFormat { 00901 DefaultComponentFormat = -1, 00902 ShortNumber = 0, 00903 LongNumber, 00904 //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */ 00905 NarrowName = 3, 00906 ShortName, 00907 LongName 00908 }; 00909 00910 //KDE5 move to KDateTime namespace 00914 enum DateFormat { 00915 ShortDate, 00916 LongDate, 00917 FancyShortDate, 00920 FancyLongDate, 00923 IsoDate, 00924 IsoWeekDate, 00925 IsoOrdinalDate 00926 }; 00927 00928 //KDE5 move to KDateTime namespace 00938 QString formatDate(const QDate &date, DateFormat format = LongDate) const; 00939 00940 //KDE5 move to KDateTime namespace 00952 QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, 00953 bool includeSecs = false) const; 00954 00955 //KDE5 move to KDateTime namespace 00959 enum DateTimeFormatOption { 00960 TimeZone = 0x01, 00961 Seconds = 0x02 00962 }; 00963 Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption) 00964 00965 //KDE5 move to KDateTime namespace 00976 QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, 00977 DateTimeFormatOptions options = 0) const; 00978 00985 bool dateMonthNamePossessive() const; 00986 01001 QString formatTime(const QTime &pTime, bool includeSecs = false, bool isDuration = false) const; 01002 01003 //KDE5 move to KDateTime namespace 01009 enum TimeFormatOption { 01010 TimeDefault = 0x0, 01011 01012 TimeWithoutSeconds = 0x1, 01013 TimeWithoutAmPm = 0x2, 01014 01015 01016 01017 TimeDuration = 0x6, 01018 01019 01020 01021 01022 TimeFoldHours = 0xE 01023 01024 01025 01026 01027 }; 01028 Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption) 01029 01030 //KDE5 move to KDateTime namespace 01041 QString formatLocaleTime(const QTime &pTime, 01042 TimeFormatOptions options = KLocale::TimeDefault) const; 01043 01053 DigitSet dateTimeDigitSet() const; 01054 01060 bool use12Clock() const; 01061 01070 QString dayPeriodText(const QTime &time, DateTimeComponentFormat format = DefaultComponentFormat) const; 01071 01077 int weekStartDay() const; 01078 01085 int workingWeekStartDay() const; 01086 01093 int workingWeekEndDay() const; 01094 01101 int weekDayOfPray() const; 01102 01108 const KCalendarSystem * calendar() const; 01109 01110 //KDE5 remove 01120 QString calendarType() const; 01121 01131 KLocale::CalendarSystem calendarSystem() const; 01132 01133 //KDE5 remove 01143 void setCalendar(const QString & calendarType); 01144 01154 void setCalendarSystem(KLocale::CalendarSystem calendarSystem); 01155 01167 void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem); 01168 01180 KLocale::WeekNumberSystem weekNumberSystem(); 01181 01191 double readMoney(const QString &numStr, bool * ok = 0) const; 01192 01202 double readNumber(const QString &numStr, bool * ok = 0) const; 01203 01204 //KDE5 move to KDateTime namespace 01218 QDate readDate(const QString &str, bool* ok = 0) const; 01219 01220 //KDE5 move to KDateTime namespace 01226 QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; 01227 01228 //KDE5 move to KDateTime namespace 01232 enum ReadDateFlags { 01233 NormalFormat = 1, 01235 ShortFormat = 2, 01237 IsoFormat = 4, 01239 IsoWeekFormat = 8, 01241 IsoOrdinalFormat = 16 01243 }; 01244 01245 //KDE5 move to KDateTime namespace 01259 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 01260 01273 QTime readTime(const QString &str, bool* ok = 0) const; 01274 01280 enum ReadTimeFlags { 01281 WithSeconds = 0, 01282 WithoutSeconds = 1 01283 }; // (maybe use this enum as a bitfield, if adding independent features?) 01284 01300 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 01301 01308 enum TimeProcessingOption { 01309 ProcessStrict = 0x1, 01310 01311 01312 ProcessNonStrict = 0x2 01313 01314 01315 }; 01316 Q_DECLARE_FLAGS(TimeProcessingOptions, TimeProcessingOption) 01317 01318 01336 QTime readLocaleTime(const QString &str, bool *ok = 0, 01337 TimeFormatOptions options = KLocale::TimeDefault, 01338 TimeProcessingOptions processing = ProcessNonStrict) const; 01339 01352 QString language() const; 01353 01372 QString country() const; 01373 01392 QString countryDivisionCode() const; 01393 01405 QStringList languageList() const; 01406 01420 QStringList currencyCodeList() const; 01421 01430 const QByteArray encoding() const; 01431 01440 int encodingMib() const; 01441 01450 QTextCodec * codecForEncoding() const; 01451 01460 int fileEncodingMib() const; 01461 01484 void setDateFormat(const QString & format); 01485 01508 void setDateFormatShort(const QString & format); 01509 01515 void setDateMonthNamePossessive(bool possessive); 01516 01536 void setTimeFormat(const QString & format); 01537 01546 void setDateTimeDigitSet(DigitSet digitSet); 01547 01553 void setWeekStartDay(int day); 01554 01561 void setWorkingWeekStartDay(int day); 01562 01569 void setWorkingWeekEndDay(int day); 01570 01577 void setWeekDayOfPray(int day); 01578 01585 QString dateFormat() const; 01586 01593 QString dateFormatShort() const; 01594 01601 QString timeFormat() const; 01602 01608 void setDecimalSymbol(const QString & symbol); 01609 01615 void setThousandsSeparator(const QString & separator); 01616 01623 void setPositiveSign(const QString & sign); 01624 01630 void setNegativeSign(const QString & sign); 01631 01640 void setDigitSet(DigitSet digitSet); 01641 01647 void setPositiveMonetarySignPosition(SignPosition signpos); 01648 01654 void setNegativeMonetarySignPosition(SignPosition signpos); 01655 01663 void setPositivePrefixCurrencySymbol(bool prefix); 01664 01672 void setNegativePrefixCurrencySymbol(bool prefix); 01673 01681 void setFracDigits(int digits); 01682 01690 void setDecimalPlaces(int digits); 01691 01699 void setMonetaryDecimalPlaces(int digits); 01700 01706 void setMonetaryThousandsSeparator(const QString & separator); 01707 01714 void setMonetaryDecimalSymbol(const QString & symbol); 01715 01723 void setCurrencyCode(const QString &newCurrencyCode); 01724 01733 void setCurrencySymbol(const QString & symbol); 01734 01743 void setMonetaryDigitSet(DigitSet digitSet); 01744 01750 int pageSize() const; 01751 01757 void setPageSize(int paperFormat); 01758 01763 enum MeasureSystem { 01764 Metric, 01765 Imperial 01766 }; 01767 01773 MeasureSystem measureSystem() const; 01774 01780 void setMeasureSystem(MeasureSystem value); 01781 01792 void insertCatalog(const QString& catalog); 01793 01799 void removeCatalog(const QString &catalog); 01800 01805 void setActiveCatalog(const QString &catalog); 01806 01812 QString translateQt(const char *context, const char *sourceText, const char *comment) const; 01813 01825 QStringList allLanguagesList() const; 01826 01839 QStringList installedLanguages() const; 01840 01857 QString languageCodeToName(const QString &language) const; 01858 01869 QStringList allCountriesList() const; 01870 01885 QString countryCodeToName(const QString &country) const; 01886 01897 static void splitLocale(const QString &locale, QString &language, QString &country, 01898 QString &modifier, QString &charset); 01899 01908 static void setMainCatalog(const char *catalog); 01909 01926 static QString langLookup(const QString &fname, const char *rtype = "html"); 01927 01933 static QString defaultLanguage(); 01934 01945 static QString defaultCountry(); 01946 01954 static QString defaultCurrencyCode(); 01955 01961 bool useTranscript() const; 01962 01968 bool isApplicationTranslatedInto(const QString & language); 01969 01975 void copyCatalogsTo(KLocale *locale); 01976 01995 bool setCountry(const QString & country, KConfig *config); 01996 02012 bool setCountryDivisionCode(const QString & countryDivision); 02013 02030 bool setLanguage(const QString &language, KConfig *config); 02031 02041 bool setLanguage(const QStringList &languages); 02042 02065 QString localizedFilePath(const QString &filePath) const; 02066 02083 QString removeAcceleratorMarker(const QString &label) const; 02084 02103 QString convertDigits(const QString &str, DigitSet digitSet, 02104 bool ignoreContext = false) const; 02105 02106 private: 02107 friend class KLocalePrivate; 02108 friend class KLocaleTest; 02109 friend class KDateTimeFormatter; 02110 KLocalePrivate * const d; 02111 }; 02112 02113 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeFormatOptions) 02114 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeComponents) 02115 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeFormatOptions) 02116 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeProcessingOptions) 02117 02118 #endif
KDE 4.6 API Reference