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 KDE_DEPRECATED 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 KDE_DEPRECATED 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 FirstFullWeek = 1, 00813 FirstPartialWeek = 2, 00814 SimpleWeek = 3 00815 }; 00816 00817 //KDE5 move to KDateTime namespace 00823 enum DateTimeFormatStandard { 00824 KdeFormat, 00825 PosixFormat, 00826 UnicodeFormat 00827 }; 00828 00829 //KDE5 move to KDateTime namespace 00835 enum DateTimeParseMode { 00836 LiberalParsing 00839 //ModerateParsing, /**< Parse Date/Time with modeate tolerance. 00840 // The date components in the format must all 00841 // occur in the input and in the same order, 00842 // but the spacing and the componants themselves 00843 // may vary from the strict format. */ 00844 //StrictParsing /**< Parse Date/Time strictly to the format. */ 00845 }; 00846 00847 //KDE5 move to KDateTime namespace 00859 enum DateTimeComponent { 00860 Year = 0x1, 00861 YearName = 0x2, 00862 Month = 0x4, 00863 MonthName = 0x8, 00864 Day = 0x10, 00865 DayName = 0x20, 00866 JulianDay = 0x40, 00867 EraName = 0x80, 00868 EraYear = 0x100, 00869 YearInEra = 0x200, 00870 DayOfYear = 0x400, 00871 DayOfYearName = 0x800, 00872 DayOfWeek = 0x1000, 00873 DayOfWeekName = 0x2000, 00874 Week = 0x4000, 00875 WeekYear = 0x8000, 00876 MonthsInYear = 0x10000, 00877 WeeksInYear = 0x20000, 00878 DaysInYear = 0x40000, 00879 DaysInMonth = 0x80000, 00880 DaysInWeek = 0x100000, 00881 Hour = 0x200000, 00882 Minute = 0x400000, 00883 Second = 0x800000, 00884 Millisecond = 0x1000000, 00885 DayPeriod = 0x2000000, 00886 DayPeriodHour = 0x4000000, 00887 Timezone = 0x8000000, 00888 TimezoneName = 0x10000000, 00889 UnixTime = 0x20000000 00890 }; 00891 Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent) 00892 00893 //KDE5 move to KDateTime namespace 00902 enum DateTimeComponentFormat { 00903 DefaultComponentFormat = -1, 00904 ShortNumber = 0, 00905 LongNumber, 00906 //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */ 00907 NarrowName = 3, 00908 ShortName, 00909 LongName 00910 }; 00911 00912 //KDE5 move to KDateTime namespace 00916 enum DateFormat { 00917 ShortDate, 00918 LongDate, 00919 FancyShortDate, 00922 FancyLongDate, 00925 IsoDate, 00926 IsoWeekDate, 00927 IsoOrdinalDate 00928 }; 00929 00930 //KDE5 move to KDateTime namespace 00940 QString formatDate(const QDate &date, DateFormat format = LongDate) const; 00941 00942 //KDE5 move to KDateTime namespace 00954 QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, 00955 bool includeSecs = false) const; 00956 00957 //KDE5 move to KDateTime namespace 00961 enum DateTimeFormatOption { 00962 TimeZone = 0x01, 00963 Seconds = 0x02 00964 }; 00965 Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption) 00966 00967 //KDE5 move to KDateTime namespace 00978 QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, 00979 DateTimeFormatOptions options = 0) const; 00980 00987 bool dateMonthNamePossessive() const; 00988 01003 QString formatTime(const QTime &pTime, bool includeSecs = false, bool isDuration = false) const; 01004 01005 //KDE5 move to KDateTime namespace 01011 enum TimeFormatOption { 01012 TimeDefault = 0x0, 01013 01014 TimeWithoutSeconds = 0x1, 01015 TimeWithoutAmPm = 0x2, 01016 01017 01018 01019 TimeDuration = 0x6, 01020 01021 01022 01023 01024 TimeFoldHours = 0xE 01025 01026 01027 01028 01029 }; 01030 Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption) 01031 01032 //KDE5 move to KDateTime namespace 01043 QString formatLocaleTime(const QTime &pTime, 01044 TimeFormatOptions options = KLocale::TimeDefault) const; 01045 01055 DigitSet dateTimeDigitSet() const; 01056 01062 bool use12Clock() const; 01063 01073 QString dayPeriodText(const QTime &time, DateTimeComponentFormat format = DefaultComponentFormat) const; 01074 01080 int weekStartDay() const; 01081 01088 int workingWeekStartDay() const; 01089 01096 int workingWeekEndDay() const; 01097 01104 int weekDayOfPray() const; 01105 01111 const KCalendarSystem * calendar() const; 01112 01113 //KDE5 remove 01123 KDE_DEPRECATED QString calendarType() const; 01124 01134 KLocale::CalendarSystem calendarSystem() const; 01135 01136 //KDE5 remove 01146 KDE_DEPRECATED void setCalendar(const QString & calendarType); 01147 01157 void setCalendarSystem(KLocale::CalendarSystem calendarSystem); 01158 01168 void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem); 01169 01170 //KDE5 remove in favour of const version 01180 KLocale::WeekNumberSystem weekNumberSystem(); 01181 01191 KLocale::WeekNumberSystem weekNumberSystem() const; 01192 01202 double readMoney(const QString &numStr, bool * ok = 0) const; 01203 01213 double readNumber(const QString &numStr, bool * ok = 0) const; 01214 01215 //KDE5 move to KDateTime namespace 01229 QDate readDate(const QString &str, bool* ok = 0) const; 01230 01231 //KDE5 move to KDateTime namespace 01237 QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; 01238 01239 //KDE5 move to KDateTime namespace 01243 enum ReadDateFlags { 01244 NormalFormat = 1, 01246 ShortFormat = 2, 01248 IsoFormat = 4, 01250 IsoWeekFormat = 8, 01252 IsoOrdinalFormat = 16 01254 }; 01255 01256 //KDE5 move to KDateTime namespace 01270 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 01271 01284 QTime readTime(const QString &str, bool* ok = 0) const; 01285 01291 enum ReadTimeFlags { 01292 WithSeconds = 0, 01293 WithoutSeconds = 1 01294 }; // (maybe use this enum as a bitfield, if adding independent features?) 01295 01311 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 01312 01319 enum TimeProcessingOption { 01320 ProcessStrict = 0x1, 01321 01322 01323 ProcessNonStrict = 0x2 01324 01325 01326 }; 01327 Q_DECLARE_FLAGS(TimeProcessingOptions, TimeProcessingOption) 01328 01329 01347 QTime readLocaleTime(const QString &str, bool *ok = 0, 01348 TimeFormatOptions options = KLocale::TimeDefault, 01349 TimeProcessingOptions processing = ProcessNonStrict) const; 01350 01363 QString language() const; 01364 01383 QString country() const; 01384 01403 QString countryDivisionCode() const; 01404 01416 QStringList languageList() const; 01417 01431 QStringList currencyCodeList() const; 01432 01441 const QByteArray encoding() const; 01442 01451 int encodingMib() const; 01452 01461 QTextCodec * codecForEncoding() const; 01462 01471 int fileEncodingMib() const; 01472 01495 void setDateFormat(const QString & format); 01496 01519 void setDateFormatShort(const QString & format); 01520 01526 void setDateMonthNamePossessive(bool possessive); 01527 01547 void setTimeFormat(const QString & format); 01548 01557 void setDateTimeDigitSet(DigitSet digitSet); 01558 01564 void setWeekStartDay(int day); 01565 01572 void setWorkingWeekStartDay(int day); 01573 01580 void setWorkingWeekEndDay(int day); 01581 01588 void setWeekDayOfPray(int day); 01589 01596 QString dateFormat() const; 01597 01604 QString dateFormatShort() const; 01605 01612 QString timeFormat() const; 01613 01619 void setDecimalSymbol(const QString & symbol); 01620 01626 void setThousandsSeparator(const QString & separator); 01627 01634 void setPositiveSign(const QString & sign); 01635 01641 void setNegativeSign(const QString & sign); 01642 01651 void setDigitSet(DigitSet digitSet); 01652 01658 void setPositiveMonetarySignPosition(SignPosition signpos); 01659 01665 void setNegativeMonetarySignPosition(SignPosition signpos); 01666 01674 void setPositivePrefixCurrencySymbol(bool prefix); 01675 01683 void setNegativePrefixCurrencySymbol(bool prefix); 01684 01692 KDE_DEPRECATED void setFracDigits(int digits); 01693 01701 void setDecimalPlaces(int digits); 01702 01710 void setMonetaryDecimalPlaces(int digits); 01711 01717 void setMonetaryThousandsSeparator(const QString & separator); 01718 01725 void setMonetaryDecimalSymbol(const QString & symbol); 01726 01734 void setCurrencyCode(const QString &newCurrencyCode); 01735 01744 void setCurrencySymbol(const QString & symbol); 01745 01754 void setMonetaryDigitSet(DigitSet digitSet); 01755 01761 int pageSize() const; 01762 01768 void setPageSize(int paperFormat); 01769 01774 enum MeasureSystem { 01775 Metric, 01776 Imperial 01777 }; 01778 01784 MeasureSystem measureSystem() const; 01785 01791 void setMeasureSystem(MeasureSystem value); 01792 01803 void insertCatalog(const QString& catalog); 01804 01810 void removeCatalog(const QString &catalog); 01811 01816 void setActiveCatalog(const QString &catalog); 01817 01823 QString translateQt(const char *context, const char *sourceText, const char *comment) const; 01824 01836 QStringList allLanguagesList() const; 01837 01850 QStringList installedLanguages() const; 01851 01868 QString languageCodeToName(const QString &language) const; 01869 01880 QStringList allCountriesList() const; 01881 01896 QString countryCodeToName(const QString &country) const; 01897 01908 static void splitLocale(const QString &locale, QString &language, QString &country, 01909 QString &modifier, QString &charset); 01910 01919 static void setMainCatalog(const char *catalog); 01920 01937 static QString langLookup(const QString &fname, const char *rtype = "html"); 01938 01944 static QString defaultLanguage(); 01945 01956 static QString defaultCountry(); 01957 01965 static QString defaultCurrencyCode(); 01966 01972 bool useTranscript() const; 01973 01979 bool isApplicationTranslatedInto(const QString & language); 01980 01986 void copyCatalogsTo(KLocale *locale); 01987 02006 bool setCountry(const QString & country, KConfig *config); 02007 02023 bool setCountryDivisionCode(const QString & countryDivision); 02024 02041 bool setLanguage(const QString &language, KConfig *config); 02042 02052 bool setLanguage(const QStringList &languages); 02053 02076 QString localizedFilePath(const QString &filePath) const; 02077 02094 QString removeAcceleratorMarker(const QString &label) const; 02095 02114 QString convertDigits(const QString &str, DigitSet digitSet, 02115 bool ignoreContext = false) const; 02116 02117 private: 02118 friend class KLocalePrivate; 02119 friend class KLocaleTest; 02120 friend class KDateTimeFormatter; 02121 KLocalePrivate * const d; 02122 }; 02123 02124 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeFormatOptions) 02125 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeComponents) 02126 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeFormatOptions) 02127 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeProcessingOptions) 02128 02129 #endif
KDE 4.7 API Reference