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 00704 QString formatByteSize(double size, int precision, 00705 BinaryUnitDialect dialect = KLocale::DefaultBinaryDialect, 00706 BinarySizeUnits specificUnit = KLocale::DefaultBinaryUnits) const; 00707 00720 BinaryUnitDialect binaryUnitDialect() const; 00721 00730 void setBinaryUnitDialect(BinaryUnitDialect newDialect); 00731 00741 QString formatDuration(unsigned long mSec) const; 00742 00758 QString prettyFormatDuration(unsigned long mSec) const; 00759 00769 KDE_DEPRECATED bool nounDeclension() const; 00770 00771 //KDE5 move to KDateTime namespace 00780 enum CalendarSystem { 00781 QDateCalendar = 1, 00782 //BahaiCalendar = 2, /**< Baha'i Calendar */ 00783 //BuddhistLunarCalendar = 3, /**< Buddhist Lunar Calendar*/ 00784 //ChineseCalendar = 4, /**< Chinese Calendar */ 00785 CopticCalendar = 5, 00786 EthiopianCalendar = 6, 00787 //EthiopianAmeteAlemCalendar = 7, /**< Ethiopian Amete Alem version, aka Ethiopic Amete Alem */ 00788 GregorianCalendar = 8, 00789 HebrewCalendar = 9, 00790 //HinduCalendar = 10, /**< Hindu Lunar Calendar */ 00791 //IslamicLunarCalendar = 11, /**< Islamic Lunar Calendar */ 00792 IslamicCivilCalendar = 12, 00793 //IslamicUmAlQuraCalendar = 13, /**< Islamic Lunar Calendar, Um Al Qura varient used in Saudi Arabia */ 00794 IndianNationalCalendar = 14, 00795 //Iso8601Calendar = 15, /**< ISO 8601 Standard Calendar */ 00796 JalaliCalendar = 16, 00797 //JalaliBirashkCalendar = 17, /**< Jalali Calendar, Birashk Algorythm variant */ 00798 //Jalali33YearCalendar = 18, /**< Jalali Calendar, 33 Year cycle variant */ 00799 JapaneseCalendar= 19, 00800 //JucheCalendar = 20, /**< Juche Calendar, used in North Korea */ 00801 JulianCalendar = 21, 00802 MinguoCalendar= 22, 00803 ThaiCalendar = 23 00804 }; 00805 00806 //KDE5 move to KDateTime namespace 00815 enum WeekNumberSystem { 00816 DefaultWeekNumber = -1, 00817 IsoWeekNumber = 0, 00818 FirstFullWeek = 1, 00819 FirstPartialWeek = 2, 00820 SimpleWeek = 3 00821 }; 00822 00823 //KDE5 move to KDateTime namespace 00829 enum DateTimeFormatStandard { 00830 KdeFormat, 00831 PosixFormat, 00832 UnicodeFormat 00833 }; 00834 00835 //KDE5 move to KDateTime namespace 00841 enum DateTimeParseMode { 00842 LiberalParsing 00845 //ModerateParsing, /**< Parse Date/Time with modeate tolerance. 00846 // The date components in the format must all 00847 // occur in the input and in the same order, 00848 // but the spacing and the componants themselves 00849 // may vary from the strict format. */ 00850 //StrictParsing /**< Parse Date/Time strictly to the format. */ 00851 }; 00852 00853 //KDE5 move to KDateTime namespace 00865 enum DateTimeComponent { 00866 Year = 0x1, 00867 YearName = 0x2, 00868 Month = 0x4, 00869 MonthName = 0x8, 00870 Day = 0x10, 00871 DayName = 0x20, 00872 JulianDay = 0x40, 00873 EraName = 0x80, 00874 EraYear = 0x100, 00875 YearInEra = 0x200, 00876 DayOfYear = 0x400, 00877 DayOfYearName = 0x800, 00878 DayOfWeek = 0x1000, 00879 DayOfWeekName = 0x2000, 00880 Week = 0x4000, 00881 WeekYear = 0x8000, 00882 MonthsInYear = 0x10000, 00883 WeeksInYear = 0x20000, 00884 DaysInYear = 0x40000, 00885 DaysInMonth = 0x80000, 00886 DaysInWeek = 0x100000, 00887 Hour = 0x200000, 00888 Minute = 0x400000, 00889 Second = 0x800000, 00890 Millisecond = 0x1000000, 00891 DayPeriod = 0x2000000, 00892 DayPeriodHour = 0x4000000, 00893 Timezone = 0x8000000, 00894 TimezoneName = 0x10000000, 00895 UnixTime = 0x20000000 00896 }; 00897 Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent) 00898 00899 //KDE5 move to KDateTime namespace 00908 enum DateTimeComponentFormat { 00909 DefaultComponentFormat = -1, 00910 ShortNumber = 0, 00911 LongNumber, 00912 //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */ 00913 NarrowName = 3, 00914 ShortName, 00915 LongName 00916 }; 00917 00918 //KDE5 move to KDateTime namespace 00922 enum DateFormat { 00923 ShortDate, 00924 LongDate, 00925 FancyShortDate, 00928 FancyLongDate, 00931 IsoDate, 00932 IsoWeekDate, 00933 IsoOrdinalDate 00934 }; 00935 00936 //KDE5 move to KDateTime namespace 00946 QString formatDate(const QDate &date, DateFormat format = LongDate) const; 00947 00948 //KDE5 move to KDateTime namespace 00960 QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate, 00961 bool includeSecs = false) const; 00962 00963 //KDE5 move to KDateTime namespace 00967 enum DateTimeFormatOption { 00968 TimeZone = 0x01, 00969 Seconds = 0x02 00970 }; 00971 Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption) 00972 00973 //KDE5 move to KDateTime namespace 00984 QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate, 00985 DateTimeFormatOptions options = 0) const; 00986 00993 bool dateMonthNamePossessive() const; 00994 01009 QString formatTime(const QTime &pTime, bool includeSecs = false, bool isDuration = false) const; 01010 01011 //KDE5 move to KDateTime namespace 01017 enum TimeFormatOption { 01018 TimeDefault = 0x0, 01019 01020 TimeWithoutSeconds = 0x1, 01021 TimeWithoutAmPm = 0x2, 01022 01023 01024 01025 TimeDuration = 0x6, 01026 01027 01028 01029 01030 TimeFoldHours = 0xE 01031 01032 01033 01034 01035 }; 01036 Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption) 01037 01038 //KDE5 move to KDateTime namespace 01049 QString formatLocaleTime(const QTime &pTime, 01050 TimeFormatOptions options = KLocale::TimeDefault) const; 01051 01061 DigitSet dateTimeDigitSet() const; 01062 01068 bool use12Clock() const; 01069 01079 QString dayPeriodText(const QTime &time, DateTimeComponentFormat format = DefaultComponentFormat) const; 01080 01086 int weekStartDay() const; 01087 01094 int workingWeekStartDay() const; 01095 01102 int workingWeekEndDay() const; 01103 01110 int weekDayOfPray() const; 01111 01117 const KCalendarSystem * calendar() const; 01118 01119 //KDE5 remove 01129 KDE_DEPRECATED QString calendarType() const; 01130 01140 KLocale::CalendarSystem calendarSystem() const; 01141 01142 //KDE5 remove 01152 KDE_DEPRECATED void setCalendar(const QString & calendarType); 01153 01163 void setCalendarSystem(KLocale::CalendarSystem calendarSystem); 01164 01174 void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem); 01175 01176 //KDE5 remove in favour of const version 01186 KLocale::WeekNumberSystem weekNumberSystem(); 01187 01197 KLocale::WeekNumberSystem weekNumberSystem() const; 01198 01208 double readMoney(const QString &numStr, bool * ok = 0) const; 01209 01219 double readNumber(const QString &numStr, bool * ok = 0) const; 01220 01221 //KDE5 move to KDateTime namespace 01235 QDate readDate(const QString &str, bool* ok = 0) const; 01236 01237 //KDE5 move to KDateTime namespace 01243 QDate readDate(const QString &intstr, const QString &fmt, bool* ok = 0) const; 01244 01245 //KDE5 move to KDateTime namespace 01249 enum ReadDateFlags { 01250 NormalFormat = 1, 01252 ShortFormat = 2, 01254 IsoFormat = 4, 01256 IsoWeekFormat = 8, 01258 IsoOrdinalFormat = 16 01260 }; 01261 01262 //KDE5 move to KDateTime namespace 01276 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const; 01277 01290 QTime readTime(const QString &str, bool* ok = 0) const; 01291 01297 enum ReadTimeFlags { 01298 WithSeconds = 0, 01299 WithoutSeconds = 1 01300 }; // (maybe use this enum as a bitfield, if adding independent features?) 01301 01317 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const; 01318 01325 enum TimeProcessingOption { 01326 ProcessStrict = 0x1, 01327 01328 01329 ProcessNonStrict = 0x2 01330 01331 01332 }; 01333 Q_DECLARE_FLAGS(TimeProcessingOptions, TimeProcessingOption) 01334 01335 01353 QTime readLocaleTime(const QString &str, bool *ok = 0, 01354 TimeFormatOptions options = KLocale::TimeDefault, 01355 TimeProcessingOptions processing = ProcessNonStrict) const; 01356 01369 QString language() const; 01370 01389 QString country() const; 01390 01409 QString countryDivisionCode() const; 01410 01422 QStringList languageList() const; 01423 01437 QStringList currencyCodeList() const; 01438 01447 const QByteArray encoding() const; 01448 01457 int encodingMib() const; 01458 01467 QTextCodec * codecForEncoding() const; 01468 01477 int fileEncodingMib() const; 01478 01501 void setDateFormat(const QString & format); 01502 01525 void setDateFormatShort(const QString & format); 01526 01532 void setDateMonthNamePossessive(bool possessive); 01533 01553 void setTimeFormat(const QString & format); 01554 01563 void setDateTimeDigitSet(DigitSet digitSet); 01564 01570 void setWeekStartDay(int day); 01571 01578 void setWorkingWeekStartDay(int day); 01579 01586 void setWorkingWeekEndDay(int day); 01587 01594 void setWeekDayOfPray(int day); 01595 01602 QString dateFormat() const; 01603 01610 QString dateFormatShort() const; 01611 01618 QString timeFormat() const; 01619 01625 void setDecimalSymbol(const QString & symbol); 01626 01632 void setThousandsSeparator(const QString & separator); 01633 01640 void setPositiveSign(const QString & sign); 01641 01647 void setNegativeSign(const QString & sign); 01648 01657 void setDigitSet(DigitSet digitSet); 01658 01664 void setPositiveMonetarySignPosition(SignPosition signpos); 01665 01671 void setNegativeMonetarySignPosition(SignPosition signpos); 01672 01680 void setPositivePrefixCurrencySymbol(bool prefix); 01681 01689 void setNegativePrefixCurrencySymbol(bool prefix); 01690 01698 KDE_DEPRECATED void setFracDigits(int digits); 01699 01707 void setDecimalPlaces(int digits); 01708 01716 void setMonetaryDecimalPlaces(int digits); 01717 01723 void setMonetaryThousandsSeparator(const QString & separator); 01724 01731 void setMonetaryDecimalSymbol(const QString & symbol); 01732 01740 void setCurrencyCode(const QString &newCurrencyCode); 01741 01750 void setCurrencySymbol(const QString & symbol); 01751 01760 void setMonetaryDigitSet(DigitSet digitSet); 01761 01767 int pageSize() const; 01768 01774 void setPageSize(int paperFormat); 01775 01780 enum MeasureSystem { 01781 Metric, 01782 Imperial 01783 }; 01784 01790 MeasureSystem measureSystem() const; 01791 01797 void setMeasureSystem(MeasureSystem value); 01798 01809 void insertCatalog(const QString& catalog); 01810 01816 void removeCatalog(const QString &catalog); 01817 01822 void setActiveCatalog(const QString &catalog); 01823 01829 QString translateQt(const char *context, const char *sourceText, const char *comment) const; 01830 01842 QStringList allLanguagesList() const; 01843 01856 QStringList installedLanguages() const; 01857 01874 QString languageCodeToName(const QString &language) const; 01875 01886 QStringList allCountriesList() const; 01887 01902 QString countryCodeToName(const QString &country) const; 01903 01914 static void splitLocale(const QString &locale, QString &language, QString &country, 01915 QString &modifier, QString &charset); 01916 01925 static void setMainCatalog(const char *catalog); 01926 01943 static QString langLookup(const QString &fname, const char *rtype = "html"); 01944 01950 static QString defaultLanguage(); 01951 01962 static QString defaultCountry(); 01963 01971 static QString defaultCurrencyCode(); 01972 01978 bool useTranscript() const; 01979 01985 bool isApplicationTranslatedInto(const QString & language); 01986 01992 void copyCatalogsTo(KLocale *locale); 01993 02012 bool setCountry(const QString & country, KConfig *config); 02013 02029 bool setCountryDivisionCode(const QString & countryDivision); 02030 02047 bool setLanguage(const QString &language, KConfig *config); 02048 02058 bool setLanguage(const QStringList &languages); 02059 02082 QString localizedFilePath(const QString &filePath) const; 02083 02100 QString removeAcceleratorMarker(const QString &label) const; 02101 02120 QString convertDigits(const QString &str, DigitSet digitSet, 02121 bool ignoreContext = false) const; 02122 02129 void reparseConfiguration(); 02130 02131 private: 02132 friend class KLocalePrivate; 02133 friend class KLocaleTest; 02134 friend class KDateTimeFormatter; 02135 KLocalePrivate * const d; 02136 }; 02137 02138 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeFormatOptions) 02139 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeComponents) 02140 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeFormatOptions) 02141 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeProcessingOptions) 02142 02143 #endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:31 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Thu May 10 2012 20:49:31 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.