KDELibs4Support

klocale.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 1997 Stephan Kulow <[email protected]>
3  Copyright (C) 1999-2003 Hans Petter Bieker <[email protected]>
4  Copyright (c) 2002 Lukas Tinkl <[email protected]>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 #ifndef KLOCALE_H
22 #define KLOCALE_H
23 
24 #include <kdelibs4support_export.h>
25 #include <ksharedconfig.h>
26 
27 // Include for providing source code compatibility
28 #include <klocalizedstring.h>
29 
30 #include <QString>
31 #include <QList>
32 
33 class QStringList;
34 class QTextCodec;
35 class QDate;
36 class QTime;
37 class QDateTime;
38 
39 class KDateTime;
40 class KCalendarSystem;
41 class KCurrencyCode;
42 class KDayPeriod;
43 
44 class KLocalePrivate;
45 
75 class KDELIBS4SUPPORT_EXPORT KLocale
76 {
77 public:
98  KDELIBS4SUPPORT_DEPRECATED explicit KLocale(KSharedConfig::Ptr config = KSharedConfig::Ptr());
99 
117  KLocale(const QString &language, const QString &country = QString(),
118  KConfig *config = nullptr);
119 
123  KLocale(const KLocale &rhs);
124 
128  KLocale &operator= (const KLocale &rhs);
129 
133  virtual ~KLocale();
134 
142  bool setEncoding(int mibEnum);
143 
152  ParensAround = 0,
156  BeforeQuantityMoney = 1,
160  AfterQuantityMoney = 2,
164  BeforeMoney = 3,
168  AfterMoney = 4
169  };
170 
176  enum DigitSet {
177  ArabicDigits,
191  ThaiDigits
192  // The following Decimal Digit Sets are defined in Unicode but the associated
193  // languages are not yet translated in KDE, so are not yet enabled.
194  // The script names are taken from the Unicode standard, the associated
195  // languages from Wikipedia.
196  // BalineseDigits, /**< ᭐᭑᭒᭓᭔᭕᭖᭗᭘᭙ (Balinese) */
197  // ChamDigits, /**< ꩐꩑꩒꩓꩔꩕꩖꩗꩘꩙ (Cham) */
198  // JavaneseDigits, /**< ꧐꧑꧒꧓꧔꧕꧖꧗꧘꧙ (Javanese) */
199  // KayahLiDigits, /**< ꤀꤁꤂꤃꤄꤅꤆꤇꤈꤉ (Kayah) */
200  // LaoDigits, /**< ໐໑໒໓໔໕໖໗໘໙ (Lao) */
201  // LepchaDigits, /**< ᱀᱁᱂᱃᱄᱅᱆᱇᱈᱉ (Lepcha) */
202  // LimbuDigits, /**< ᥆᥇᥈᥉᥊᥋᥌᥍᥎᥏ (Limbu) */
203  // MeeteiMayekDigits, /**< ꯰꯱꯲꯳꯴꯵꯶꯷꯸꯹ (Meitei) */
204  // MongolianDigits, /**< ᠐᠑᠒᠓᠔᠕᠖᠗᠘᠙ (Mongolian) */
205  // MyanmarDigits, /**< ၀၁၂၃၄၅၆၇၈၉ (Myanmar/Burmese ) */
206  // MyanmarShanDigits, /**< ႐႑႒႓႔႕႖႗႘႙ (Shan) */
207  // NewTaiLueDigits, /**< ᧐᧑᧒᧓᧔᧕᧖᧗᧘᧙ (Tai Lü) */
208  // NKoDigits, /**< ߀߁߂߃߄߅߆߇߈߉ (Mande and N'Ko) */
209  // OlChikiDigits, /**< ᱐᱑᱒᱓᱔᱕᱖᱗᱘᱙ (Santali) */
210  // OsmanyaDigits, /**< ҠҡҢңҤҥҦҧҨҩ (Somali) */
211  // SaurashtraDigits, /**< ꣐꣑꣒꣓꣔꣕꣖꣗꣘꣙ (Saurashtra) */
212  // SundaneseDigits, /**< ᮰᮱᮲᮳᮴᮵᮶᮷᮸᮹ (Sundanese) */
213  // TaiThamDigits, /**< ᪐᪑᪒᪓᪔᪕᪖᪗᪘᪙ (Tai Lü) */
214  // TibetanDigits, /**< ༠༡༢༣༤༥༦༧༨༩ (Tibetan) */
215  // VaiDigits, /**< ꘠꘡꘢꘣꘤꘥꘦꘧꘨꘩ (Vai) */
216  };
217 
230  QString digitSetToName(DigitSet digitSet, bool withDigits = false) const;
231 
241  QList<DigitSet> allDigitSetsList() const;
242 
249  QString decimalSymbol() const;
250 
258  QString thousandsSeparator() const;
259 
269  DigitSet digitSet() const;
270 
278  QString currencyCode() const;
279 
287  KCurrencyCode *currency() const;
288 
295  QString currencySymbol() const;
296 
304  QString monetaryDecimalSymbol() const;
305 
313  QString monetaryThousandsSeparator() const;
314 
321  QString positiveSign() const;
322 
329  QString negativeSign() const;
330 
338  KDELIBS4SUPPORT_DEPRECATED int fracDigits() const;
339 
347  int decimalPlaces() const;
348 
356  int monetaryDecimalPlaces() const;
357 
364  bool positivePrefixCurrencySymbol() const;
365 
372  bool negativePrefixCurrencySymbol() const;
373 
381  SignPosition positiveMonetarySignPosition() const;
382 
390  SignPosition negativeMonetarySignPosition() const;
391 
401  DigitSet monetaryDigitSet() const;
402 
418  QString formatMoney(double num, const QString &currency = QString(), int precision = -1) const;
419 
437  QString formatNumber(double num, int precision = -1) const;
438 
453  QString formatNumber(const QString &numStr, bool round = true, int precision = -1) const;
454 
465  QString formatLong(long num) const;
466 
490  DefaultBinaryUnits = -1,
491 
492  // The first real unit must be 0 for the current implementation!
502  UnitLastUnit = UnitYottaByte
503  };
504 
524  DefaultBinaryDialect = -1,
528  LastBinaryDialect = MetricBinaryDialect
529  };
530 
544  QString formatByteSize(double size) const;
545 
571  QString formatByteSize(double size, int precision,
573  BinarySizeUnits specificUnit = KLocale::DefaultBinaryUnits) const;
574 
587  BinaryUnitDialect binaryUnitDialect() const;
588 
597  void setBinaryUnitDialect(BinaryUnitDialect newDialect);
598 
608  QString formatDuration(unsigned long mSec) const;
609 
625  QString prettyFormatDuration(unsigned long mSec) const;
626 
636  KDELIBS4SUPPORT_DEPRECATED bool nounDeclension() const;
637 
647  GregorianCalendar = 1,
648  //BahaiCalendar = 2, /**< Baha'i Calendar */
649  //BuddhistLunarCalendar = 3, /**< Buddhist Lunar Calendar*/
650  //ChineseCalendar = 4, /**< Chinese Calendar */
651  CopticCalendar = 5,
652  EthiopianCalendar = 6,
653  //EthiopianAmeteAlemCalendar = 7, /**< Ethiopian Amete Alem version, aka Ethiopic Amete Alem */
654  HebrewCalendar = 9,
655  //HinduCalendar = 10, /**< Hindu Lunar Calendar */
656  //IslamicLunarCalendar = 11, /**< Islamic Lunar Calendar */
657  IslamicCivilCalendar = 12,
658  //IslamicUmAlQuraCalendar = 13, /**< Islamic Lunar Calendar, Um Al Qura varient used in Saudi Arabia */
659  IndianNationalCalendar = 14,
660  //Iso8601Calendar = 15, /**< ISO 8601 Standard Calendar */
661  JalaliCalendar = 16,
662  //JalaliBirashkCalendar = 17, /**< Jalali Calendar, Birashk Algorythm variant */
663  //Jalali33YearCalendar = 18, /**< Jalali Calendar, 33 Year cycle variant */
664  JapaneseCalendar = 19,
665  //JucheCalendar = 20, /**< Juche Calendar, used in North Korea */
666  JulianCalendar = 21,
667  MinguoCalendar = 22,
668  ThaiCalendar = 23,
670  QDateCalendar = GregorianCalendar
671  };
672 
682  DefaultWeekNumber = -1,
683  IsoWeekNumber = 0,
684  FirstFullWeek = 1,
685  FirstPartialWeek = 2,
686  SimpleWeek = 3
687  };
688 
697  UnicodeFormat
698  };
699 
706  LiberalParsing
709  //ModerateParsing, /**< Parse Date/Time with modeate tolerance.
710  // The date components in the format must all
711  // occur in the input and in the same order,
712  // but the spacing and the componants themselves
713  // may vary from the strict format. */
714  //StrictParsing /**< Parse Date/Time strictly to the format. */
715  };
716 
729  Year = 0x1,
730  YearName = 0x2,
731  Month = 0x4,
732  MonthName = 0x8,
733  Day = 0x10,
734  DayName = 0x20,
735  JulianDay = 0x40,
736  EraName = 0x80,
737  EraYear = 0x100,
738  YearInEra = 0x200,
739  DayOfYear = 0x400,
740  DayOfYearName = 0x800,
741  DayOfWeek = 0x1000,
742  DayOfWeekName = 0x2000,
743  Week = 0x4000,
744  WeekYear = 0x8000,
745  MonthsInYear = 0x10000,
746  WeeksInYear = 0x20000,
747  DaysInYear = 0x40000,
748  DaysInMonth = 0x80000,
749  DaysInWeek = 0x100000,
750  Hour = 0x200000,
751  Minute = 0x400000,
752  Second = 0x800000,
753  Millisecond = 0x1000000,
754  DayPeriod = 0x2000000,
755  DayPeriodHour = 0x4000000,
756  Timezone = 0x8000000,
757  TimezoneName = 0x10000000,
758  UnixTime = 0x20000000
759  };
760  Q_DECLARE_FLAGS(DateTimeComponents, DateTimeComponent)
761 
762 
771  DefaultComponentFormat = -1,
772  ShortNumber = 0,
774  //OrdinalNumber /**< Ordinal number format, e.g. "2nd" for the 2nd */
775  NarrowName = 3,
777  LongName
778  };
779 
783  enum DateFormat {
786  FancyShortDate,
789  FancyLongDate,
794  IsoOrdinalDate
795  };
796 
806  QString formatDate(const QDate &date, DateFormat format = LongDate) const;
807 
819  QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate,
820  bool includeSecs = false) const;
821 
826  TimeZone = 0x01,
827  Seconds = 0x02
828  };
830 
831 
841  QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate,
842  DateTimeFormatOptions options = {}) const;
843 
850  bool dateMonthNamePossessive() const;
851 
866  QString formatTime(const QTime &pTime, bool includeSecs = false, bool isDuration = false) const;
867 
874  TimeDefault = 0x0,
875  TimeWithoutSeconds = 0x1,
877  TimeWithoutAmPm = 0x2,
878  TimeDuration = 0x6,
882  TimeFoldHours = 0xE
887  };
892  Q_DECLARE_FLAGS(TimeFormatOptions, TimeFormatOption)
893 
894 
904  QString formatLocaleTime(const QTime &pTime,
905  TimeFormatOptions options = KLocale::TimeDefault) const;
906 
916  DigitSet dateTimeDigitSet() const;
917 
933  bool use12Clock() const;
934 
944  QString dayPeriodText(const QTime &time, DateTimeComponentFormat format = DefaultComponentFormat) const;
945 
951  int weekStartDay() const;
952 
959  int workingWeekStartDay() const;
960 
967  int workingWeekEndDay() const;
968 
975  int weekDayOfPray() const;
976 
982  const KCalendarSystem *calendar() const;
983 
993  KDELIBS4SUPPORT_DEPRECATED QString calendarType() const;
994 
1004  KLocale::CalendarSystem calendarSystem() const;
1005 
1015  KDELIBS4SUPPORT_DEPRECATED void setCalendar(const QString &calendarType);
1016 
1026  void setCalendarSystem(KLocale::CalendarSystem calendarSystem);
1027 
1037  void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem);
1038 
1048  KLocale::WeekNumberSystem weekNumberSystem();
1049 
1059  KLocale::WeekNumberSystem weekNumberSystem() const;
1060 
1070  double readMoney(const QString &numStr, bool *ok = nullptr) const;
1071 
1081  double readNumber(const QString &numStr, bool *ok = nullptr) const;
1082 
1096  QDate readDate(const QString &str, bool *ok = nullptr) const;
1097 
1103  QDate readDate(const QString &intstr, const QString &fmt, bool *ok = nullptr) const;
1104 
1109  NormalFormat = 1,
1111  ShortFormat = 2,
1113  IsoFormat = 4,
1115  IsoWeekFormat = 8,
1117  IsoOrdinalFormat = 16
1119  };
1120 
1134  QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = nullptr) const;
1135 
1148  QTime readTime(const QString &str, bool *ok = nullptr) const;
1149 
1156  WithSeconds = 0,
1157  WithoutSeconds = 1
1158  }; // (maybe use this enum as a bitfield, if adding independent features?)
1159 
1175  QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = nullptr) const;
1176 
1184  ProcessStrict = 0x1,
1185  ProcessNonStrict = 0x2
1188  };
1192 
1193 
1211  QTime readLocaleTime(const QString &str, bool *ok = nullptr,
1212  TimeFormatOptions options = KLocale::TimeDefault,
1213  TimeProcessingOptions processing = ProcessNonStrict) const;
1214 
1225  QString language() const;
1226 
1245  QString country() const;
1246 
1265  QString countryDivisionCode() const;
1266 
1278  QStringList languageList() const;
1279 
1293  QStringList currencyCodeList() const;
1294 
1303  const QByteArray encoding() const;
1304 
1313  int encodingMib() const;
1314 
1323  QTextCodec *codecForEncoding() const;
1324 
1333  int fileEncodingMib() const;
1334 
1357  void setDateFormat(const QString &format);
1358 
1381  void setDateFormatShort(const QString &format);
1382 
1388  void setDateMonthNamePossessive(bool possessive);
1389 
1409  void setTimeFormat(const QString &format);
1410 
1419  void setDateTimeDigitSet(DigitSet digitSet);
1420 
1426  void setWeekStartDay(int day);
1427 
1434  void setWorkingWeekStartDay(int day);
1435 
1442  void setWorkingWeekEndDay(int day);
1443 
1450  void setWeekDayOfPray(int day);
1451 
1458  QString dateFormat() const;
1459 
1466  QString dateFormatShort() const;
1467 
1474  QString timeFormat() const;
1475 
1481  void setDecimalSymbol(const QString &symbol);
1482 
1488  void setThousandsSeparator(const QString &separator);
1489 
1496  void setPositiveSign(const QString &sign);
1497 
1503  void setNegativeSign(const QString &sign);
1504 
1513  void setDigitSet(DigitSet digitSet);
1514 
1520  void setPositiveMonetarySignPosition(SignPosition signpos);
1521 
1527  void setNegativeMonetarySignPosition(SignPosition signpos);
1528 
1536  void setPositivePrefixCurrencySymbol(bool prefix);
1537 
1545  void setNegativePrefixCurrencySymbol(bool prefix);
1546 
1554  KDELIBS4SUPPORT_DEPRECATED void setFracDigits(int digits);
1555 
1563  void setDecimalPlaces(int digits);
1564 
1572  void setMonetaryDecimalPlaces(int digits);
1573 
1579  void setMonetaryThousandsSeparator(const QString &separator);
1580 
1587  void setMonetaryDecimalSymbol(const QString &symbol);
1588 
1596  void setCurrencyCode(const QString &newCurrencyCode);
1597 
1606  void setCurrencySymbol(const QString &symbol);
1607 
1616  void setMonetaryDigitSet(DigitSet digitSet);
1617 
1623  int pageSize() const;
1624 
1630  void setPageSize(int paperFormat);
1631 
1638  Imperial
1639  };
1640 
1646  MeasureSystem measureSystem() const;
1647 
1653  void setMeasureSystem(MeasureSystem value);
1654 
1666  QStringList allLanguagesList() const;
1667 
1680  QStringList installedLanguages() const;
1681 
1698  QString languageCodeToName(const QString &language) const;
1699 
1710  QStringList allCountriesList() const;
1711 
1726  QString countryCodeToName(const QString &country) const;
1727 
1738  static void splitLocale(const QString &locale, QString &language, QString &country,
1739  QString &modifier, QString &charset);
1740 
1753  static KLocale *global();
1754 
1760  static QString defaultLanguage();
1761 
1772  static QString defaultCountry();
1773 
1781  static QString defaultCurrencyCode();
1782 
1801  bool setCountry(const QString &country, KConfig *config);
1802 
1818  bool setCountryDivisionCode(const QString &countryDivision);
1819 
1836  bool setLanguage(const QString &language, KConfig *config);
1837 
1847  bool setLanguage(const QStringList &languages);
1848 
1867  QString convertDigits(const QString &str, DigitSet digitSet,
1868  bool ignoreContext = false) const;
1869 
1876  void reparseConfiguration();
1877 
1878 private:
1879  friend class KLocalePrivate;
1880  friend class KLocaleTest;
1881  friend class KDateTimeFormatter;
1882  KLocalePrivate *const d;
1883 };
1884 
1885 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeFormatOptions)
1886 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeComponents)
1887 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeFormatOptions)
1888 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::TimeProcessingOptions)
1889 
1890 #endif
MiB/MB/MB 2^20/10^06 bytes.
Definition: klocale.h:495
POSIX Standard.
Definition: klocale.h:696
MeasureSystem
The Metric system will give you information in mm, while the Imperial system will give you informatio...
Definition: klocale.h:1636
௦௧௨௩௪௫௬௭௮ (Tamil)
Definition: klocale.h:189
Locale Short date format, e.g.
Definition: klocale.h:784
PiB/PB/PB 2^50/10^15 bytes.
Definition: klocale.h:498
DateFormat
Format for date string.
Definition: klocale.h:783
੦੧੨੩੪੫੬੭੮੯ (Punjabi)
Definition: klocale.h:184
KDE Default, KiB, MiB, etc. 2^(10*n)
Definition: klocale.h:525
ISO-8601 Week Date format YYYY-Www-D, e.g.
Definition: klocale.h:793
BinarySizeUnits
These binary units are used in KDE by the formatByteSize() functions.
Definition: klocale.h:488
൦൧൨൩൪൫൬൭൮൯ (Malayalam)
Definition: klocale.h:187
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE...
DateTimeComponentFormat
Definition: klocale.h:770
DateTimeFormatOption
Options for formatting date-time values.
Definition: klocale.h:825
KDE 3.5 default, KB, MB, etc. 2^(10*n)
Definition: klocale.h:526
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
Definition: klocale.h:490
TiB/TB/TB 2^40/10^12 bytes.
Definition: klocale.h:497
ReadTimeFlags
Flags for the old version of readTime()
Definition: klocale.h:1155
CalendarSystem
Definition: klocale.h:646
Number padded to a required width, e.g.
Definition: klocale.h:773
YiB/YB/YB 2^80/10^24 bytes.
Definition: klocale.h:501
WeekNumberSystem
Definition: klocale.h:681
SI Units, kB, MB, etc. 10^(3*n)
Definition: klocale.h:527
୦୧୨୩୪୫୬୭୮୯ (Oriya)
Definition: klocale.h:188
ReadDateFlags
Flags for readDate()
Definition: klocale.h:1108
GiB/GB/GB 2^30/10^09 bytes.
Definition: klocale.h:496
TimeProcessingOption
Additional processing options for readLocaleTime().
Definition: klocale.h:1183
DateTimeComponent
Definition: klocale.h:728
౦౧౨౩౪౫౬౭౯ (Telugu)
Definition: klocale.h:190
KDE Standard.
Definition: klocale.h:695
০১২৩৪৫৬৭৮৯ (Bengali and Assamese)
Definition: klocale.h:182
A class representing a date and time with an associated time zone.
Definition: kdatetime.h:148
KiB/KB/kB 1024/1000 bytes.
Definition: klocale.h:494
Used if no specific preference.
Definition: klocale.h:524
Short text format, e.g.
Definition: klocale.h:776
ZiB/ZB/ZB 2^70/10^21 bytes.
Definition: klocale.h:500
KLocale provides support for language and country specific stuff.
Definition: klocale.h:75
DateTimeFormatStandard
Definition: klocale.h:694
SignPosition
Various positions for where to place the positive or negative sign when they are related to a monetar...
Definition: klocale.h:148
B 1 byte.
Definition: klocale.h:493
۰۱۲۳۴۵۶۷۸۹ (Persian and Urdu)
Definition: klocale.h:180
TimeFormatOption
Definition: klocale.h:873
೦೧೨೩೪೫೬೭೮೯ (Kannada)
Definition: klocale.h:185
ISO-8601 Date format YYYY-MM-DD, e.g.
Definition: klocale.h:792
Locale Long date format, e.g.
Definition: klocale.h:785
EiB/EB/EB 2^60/10^18 bytes.
Definition: klocale.h:499
BinaryUnitDialect
This enum chooses what dialect is used for binary units.
Definition: klocale.h:523
DigitSet
Definition: klocale.h:176
Metric system (used e.g. in Europe)
Definition: klocale.h:1637
០១២៣៤៥៦៧៨៩ (Khmer)
Definition: klocale.h:186
૦૧૨૩૪૫૬૭૮૯ (Gujarati)
Definition: klocale.h:183
٠١٢٣٤٥٦٧٨٩ (eastern Arabic dialects)
Definition: klocale.h:179
०१२३४५६७८९ (Hindi)
Definition: klocale.h:181
DateTimeParseMode
Definition: klocale.h:705
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Thu Dec 3 2020 22:59:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.