• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.10.5 API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • kdecore
  • localization
klocale_kde.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (c) 1997,2001 Stephan Kulow <coolo@kde.org>
3  Copyright (c) 1999 Preston Brown <pbrown@kde.org>
4  Copyright (c) 1999-2002 Hans Petter Bieker <bieker@kde.org>
5  Copyright (c) 2002 Lukas Tinkl <lukas@kde.org>
6  Copyright (C) 2007 Bernhard Loos <nhuh.put@web.de>
7  Copyright (C) 2009, 2010 John Layt <john@layt.net>
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Library General Public
11  License as published by the Free Software Foundation; either
12  version 2 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Library General Public License for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with this library; see the file COPYING.LIB. If not, write to
21  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  Boston, MA 02110-1301, USA.
23 */
24 
25 #include "klocale_p.h"
26 
27 #include "config-localization.h"
28 
29 #include <math.h>
30 
31 #ifdef HAVE_SYS_TIME_H
32 #include <sys/time.h>
33 #endif
34 #ifdef HAVE_TIME_H
35 #include <time.h>
36 #endif
37 #if HAVE_LANGINFO_H
38 #include <langinfo.h>
39 #endif
40 
41 #include <QtCore/QTextCodec>
42 #include <QtCore/QFile>
43 #include <QtGui/QPrinter>
44 #include <QtCore/QFileInfo>
45 #include <QtCore/QRegExp>
46 #include <QtCore/QLocale>
47 #include <QtCore/QHash>
48 #include <QtCore/QMutexLocker>
49 #include <QtCore/QStringList>
50 
51 #include "kcatalog_p.h"
52 #include "kglobal.h"
53 #include "kstandarddirs.h"
54 #include "kconfig.h"
55 #include "kcomponentdata.h"
56 #include "kdebug.h"
57 #include "kdatetime.h"
58 #include "kcalendarsystem.h"
59 #include "kcurrencycode.h"
60 #include "klocalizedstring.h"
61 #include "kconfiggroup.h"
62 #include "kcatalogname_p.h"
63 #include "common_helpers_p.h"
64 #include "kdayperiod_p.h"
65 
66 class KLocaleStaticData
67 {
68 public:
69 
70  KLocaleStaticData();
71 
72  QString maincatalog;
73 
74  // FIXME: Temporary until full language-sensitivity implemented.
75  QHash<KLocale::DigitSet, QStringList> languagesUsingDigitSet;
76 };
77 
78 KLocaleStaticData::KLocaleStaticData()
79 {
80  // Languages using non-Western Arabic digit sets.
81  // FIXME: Temporary until full language-sensitivity implemented.
82  languagesUsingDigitSet.insert(KLocale::ArabicIndicDigits, QStringList() << QString::fromLatin1("ar") << QString::fromLatin1("ps"));
83  languagesUsingDigitSet.insert(KLocale::BengaliDigits, QStringList() << QString::fromLatin1("bn") << QString::fromLatin1("as") );
84  languagesUsingDigitSet.insert(KLocale::DevenagariDigits, QStringList() << QString::fromLatin1("hi") << QString::fromLatin1("ne"));
85  languagesUsingDigitSet.insert(KLocale::EasternArabicIndicDigits, QStringList() << QString::fromLatin1("fa") << QString::fromLatin1("ur"));
86  languagesUsingDigitSet.insert(KLocale::GujaratiDigits, QStringList() << QString::fromLatin1("gu") );
87  languagesUsingDigitSet.insert(KLocale::GurmukhiDigits, QStringList() << QString::fromLatin1("pa") );
88  languagesUsingDigitSet.insert(KLocale::KannadaDigits, QStringList() << QString::fromLatin1("kn") );
89  languagesUsingDigitSet.insert(KLocale::KhmerDigits, QStringList() << QString::fromLatin1("km") );
90  languagesUsingDigitSet.insert(KLocale::MalayalamDigits, QStringList() << QString::fromLatin1("ml") );
91  languagesUsingDigitSet.insert(KLocale::OriyaDigits, QStringList() << QString::fromLatin1("or") );
92  languagesUsingDigitSet.insert(KLocale::TamilDigits, QStringList() << QString::fromLatin1("ta") );
93  languagesUsingDigitSet.insert(KLocale::TeluguDigits, QStringList() << QString::fromLatin1("te") );
94  languagesUsingDigitSet.insert(KLocale::ThaiDigits, QStringList() << QString::fromLatin1("th"));
95 }
96 
97 K_GLOBAL_STATIC(KLocaleStaticData, staticData)
98 
99 
100 QDebug operator<<(QDebug debug, const KCatalogName &cn)
101 {
102  return debug << cn.name << cn.loadCount;
103 }
104 
105 KLocalePrivate::KLocalePrivate(KLocale *q_ptr)
106  : q(q_ptr),
107  m_config(KSharedConfig::Ptr()),
108  m_country(QString()),
109  m_language(QString()),
110  m_languages(0),
111  m_catalogName(QString()),
112  m_calendar(0),
113  m_currency(0),
114  m_codecForEncoding(0)
115 {
116 }
117 
118 KLocalePrivate::KLocalePrivate(const KLocalePrivate &rhs)
119 {
120  copy(rhs);
121 }
122 
123 KLocalePrivate &KLocalePrivate::operator=(const KLocalePrivate &rhs)
124 {
125  copy(rhs);
126  return *this;
127 }
128 
129 KConfig *KLocalePrivate::config()
130 {
131  if (m_config != KSharedConfig::Ptr()) {
132  return m_config.data();
133  } else {
134  return KGlobal::config().data();
135  }
136 }
137 
138 void KLocalePrivate::copy(const KLocalePrivate &rhs)
139 {
140  // Parent KLocale
141  q = 0;
142 
143  // Config
144  m_config = rhs.m_config;
145 
146  // Country settings
147  m_country = rhs.m_country;
148  m_countryDivisionCode = rhs.m_countryDivisionCode;
149 
150  // Language settings
151  m_language = rhs.m_language;
152  m_languages = 0;
153  m_languageList = rhs.m_languageList;
154  m_languageSensitiveDigits = rhs.m_languageSensitiveDigits;
155  m_nounDeclension = rhs.m_nounDeclension;
156 
157  // Catalog settings
158  m_catalogName = rhs.m_catalogName;
159  m_catalogNames = rhs.m_catalogNames;
160  m_catalogs = rhs.m_catalogs;
161  m_numberOfSysCatalogs = rhs.m_numberOfSysCatalogs;
162  m_useTranscript = rhs.m_useTranscript;
163 
164  // Calendar settings
165  m_calendarSystem = rhs.m_calendarSystem;
166  m_calendar = 0;
167  m_weekStartDay = rhs.m_weekStartDay;
168  m_workingWeekStartDay = rhs.m_workingWeekStartDay;
169  m_workingWeekEndDay = rhs.m_workingWeekEndDay;
170  m_weekDayOfPray = rhs.m_weekDayOfPray;
171 
172  // Date/Time settings
173  m_dateFormat = rhs.m_dateFormat;
174  m_dateFormatShort = rhs.m_dateFormatShort;
175  m_timeFormat = rhs.m_timeFormat;
176  m_dateTimeDigitSet = rhs.m_dateTimeDigitSet;
177  m_dateMonthNamePossessive = rhs.m_dateMonthNamePossessive;
178  m_dayPeriods = rhs.m_dayPeriods;
179  m_weekNumberSystem = rhs.m_weekNumberSystem;
180 
181  // Number settings
182  m_decimalPlaces = rhs.m_decimalPlaces;
183  m_decimalSymbol = rhs.m_decimalSymbol;
184  m_thousandsSeparator = rhs.m_thousandsSeparator;
185  m_numericDigitGrouping = rhs.m_numericDigitGrouping;
186  m_positiveSign = rhs.m_positiveSign;
187  m_negativeSign = rhs.m_negativeSign;
188  m_digitSet = rhs.m_digitSet;
189 
190  // Currency settings
191  m_currencyCode = rhs.m_currencyCode;
192  m_currency = 0;
193  m_currencyCodeList = rhs.m_currencyCodeList;
194 
195  // Money settings
196  m_currencySymbol = rhs.m_currencySymbol;
197  m_monetaryDecimalSymbol = rhs.m_monetaryDecimalSymbol;
198  m_monetaryThousandsSeparator = rhs.m_monetaryThousandsSeparator;
199  m_monetaryDigitGrouping = rhs.m_monetaryDigitGrouping;
200  m_monetaryDecimalPlaces = rhs.m_monetaryDecimalPlaces;
201  m_positiveMonetarySignPosition = rhs.m_positiveMonetarySignPosition;
202  m_negativeMonetarySignPosition = rhs.m_negativeMonetarySignPosition;
203  m_positivePrefixCurrencySymbol = rhs.m_positivePrefixCurrencySymbol;
204  m_negativePrefixCurrencySymbol = rhs.m_negativePrefixCurrencySymbol;
205  m_monetaryDigitSet = rhs.m_monetaryDigitSet;
206 
207  // Units settings
208  m_binaryUnitDialect = rhs.m_binaryUnitDialect;
209  m_byteSizeFmt = rhs.m_byteSizeFmt;
210  m_pageSize = rhs.m_pageSize;
211  m_measureSystem = rhs.m_measureSystem;
212 
213  // Encoding settings
214  m_encoding = rhs.m_encoding;
215  m_codecForEncoding = rhs.m_codecForEncoding;
216  m_utf8FileEncoding = rhs.m_utf8FileEncoding;
217 }
218 
219 KLocalePrivate::~KLocalePrivate()
220 {
221  delete m_currency;
222  delete m_calendar;
223  delete m_languages;
224 }
225 
226 // init only called from platform specific constructor, so set everything up
227 // Will be given a persistantConfig or a tempConfig or neither, but never both
228 void KLocalePrivate::init(const QString& catalogName, const QString &language, const QString &country,
229  KSharedConfig::Ptr persistantConfig, KConfig *tempConfig)
230 {
231  m_catalogName = catalogName;
232 
233  // Only keep the persistant config if it is not the global
234  if (persistantConfig != KSharedConfig::Ptr() && persistantConfig != KGlobal::config()) {
235  m_config = persistantConfig;
236  }
237 
238  KConfigGroup cg;
239  bool useEnvironmentVariables;
240 
241  // We can't read the formats from the config until we know what locale to read in, but we need
242  // to read the config to find out the locale. The Country and Language settings should never
243  // be localized in the config, so we can read a temp copy of them to get us started.
244 
245  // If no config given, use the global config and include envvars, otherwise use only the config.
246  if (m_config != KSharedConfig::Ptr()) {
247  cg = m_config->group(QLatin1String("Locale"));
248  useEnvironmentVariables = false;
249  } else if (tempConfig == 0 || tempConfig == KGlobal::config().data()) {
250  cg = KGlobal::config()->group(QLatin1String("Locale"));
251  useEnvironmentVariables = true;
252  } else {
253  cg = tempConfig->group(QLatin1String("Locale"));
254  useEnvironmentVariables = false;
255  }
256 
257  initEncoding();
258  initFileNameEncoding();
259  initCountry(country, cg.readEntry(QLatin1String("Country")));
260  initLanguageList(language, cg.readEntry(QLatin1String("Language")), useEnvironmentVariables);
261  // Now that we have a language, we can set up the config which uses it to setLocale()
262  initConfig(tempConfig);
263  initMainCatalogs();
264  initFormat();
265 }
266 
267 // Init the config, this is called during construction and by later setCountry/setLanguage calls.
268 // You _must_ have the m_language set to a valid language or en_US before calling this so a
269 // setLocale can be applied to the config
270 void KLocalePrivate::initConfig(KConfig *config)
271 {
272  // * If we were constructed with a KSharedConfig it means the user gave it to us
273  // to use for the life of the KLocale, so just keep using it after a setLocale
274  // * If passed in KConfig is null or the global config then use the global, but
275  // do the setLocale first.
276  // * If we have a KConfig we need to use that, but due to keeping old behaviour
277  // of not requiring access to it for life we can't keep a reference so instead
278  // take a copy and use that, but do setLocale first.
279 
280  if (m_config != KSharedConfig::Ptr()) {
281  m_config->setLocale(m_language);
282  } else {
283  // If no config given then use the global
284  if (config == 0 || config == KGlobal::config().data()) {
285  KGlobal::config()->setLocale(m_language);
286  } else {
287  config->setLocale(m_language);
288  m_config = KSharedConfig::openConfig();
289  config->copyTo(QString(), m_config.data());
290  m_config->markAsClean();
291  }
292  }
293 }
294 
295 void KLocalePrivate::initMainCatalogs()
296 {
297  KLocaleStaticData *s = staticData;
298  QMutexLocker lock(kLocaleMutex());
299 
300  if (!s->maincatalog.isEmpty()) {
301  // If setMainCatalog was called, then we use that
302  // (e.g. korgac calls setMainCatalog("korganizer") to use korganizer.po)
303  m_catalogName = s->maincatalog;
304  }
305 
306  if (m_catalogName.isEmpty()) {
307  kDebug(173) << "KLocale instance created called without valid "
308  << "catalog! Give an argument or call setMainCatalog "
309  << "before init" << endl;
310  } else {
311  // do not use insertCatalog here, that would already trigger updateCatalogs
312  m_catalogNames.append(KCatalogName(m_catalogName)); // application catalog
313 
314  // catalogs from which each application can draw translations
315  const int numberOfCatalogs = m_catalogNames.size();
316  m_catalogNames.append(KCatalogName(QString::fromLatin1("libphonon")));
317  m_catalogNames.append(KCatalogName(QString::fromLatin1("kio4")));
318  m_catalogNames.append(KCatalogName(QString::fromLatin1("kdelibs4")));
319  m_catalogNames.append(KCatalogName(QString::fromLatin1("kdeqt")));
320  m_catalogNames.append(KCatalogName(QString::fromLatin1("solid_qt")));
321  m_catalogNames.append(KCatalogName(QString::fromLatin1("kdecalendarsystems")));
322  m_numberOfSysCatalogs = m_catalogNames.size() - numberOfCatalogs;
323 
324  updateCatalogs(); // evaluate this for all languages
325  }
326 }
327 
328 void KLocalePrivate::getLanguagesFromVariable(QStringList &list, const char *variable, bool isLanguageList)
329 {
330  QByteArray var(qgetenv(variable));
331  if (!var.isEmpty()) {
332  QString value = QFile::decodeName(var);
333  if (isLanguageList) {
334  list += value.split(QLatin1Char(':'));
335  } else {
336  // Process the value to create possible combinations.
337  QString lang, ctry, modf, cset;
338  KLocale::splitLocale(value, lang, ctry, modf, cset);
339 
340  if (!ctry.isEmpty() && !modf.isEmpty()) {
341  list += lang + QLatin1Char('_') + ctry + QLatin1Char('@') + modf;
342  }
343  // NOTE: The priority is tricky in case both ctry and modf are present.
344  // Should really lang@modf be of higher priority than lang_ctry?
345  // For at least one case (Serbian language), it is better this way.
346  if (!modf.isEmpty()) {
347  list += lang + QLatin1Char('@') + modf;
348  }
349  if (!ctry.isEmpty()) {
350  list += lang + QLatin1Char('_') + ctry;
351  }
352  list += lang;
353  }
354  }
355 }
356 
357 // init the country at construction only, will ensure we always have a country set
358 void KLocalePrivate::initCountry(const QString &country, const QString &configCountry)
359 {
360  // Cache the valid countries list and add the default C as it is valid to use
361  QStringList validCountries = allCountriesList();
362  validCountries.append( defaultCountry() );
363 
364  // First check if the constructor passed in a value and if so if it is valid
365  QString putativeCountry = country;
366 
367  if ( putativeCountry.isEmpty() || !validCountries.contains( putativeCountry, Qt::CaseInsensitive ) ) {
368 
369  // If the requested country is not valid, try the country as set in the config:
370  putativeCountry = configCountry;
371 
372  if ( putativeCountry.isEmpty() || !validCountries.contains( putativeCountry, Qt::CaseInsensitive ) ) {
373 
374  // If the config country is not valid try the current host system country
375  putativeCountry = systemCountry();
376 
377  if ( putativeCountry.isEmpty() || !validCountries.contains( putativeCountry, Qt::CaseInsensitive ) ) {
378  // Only if no other option, resort to the default C
379  putativeCountry = defaultCountry();
380  }
381  }
382  }
383 
384  // Always save as lowercase, unless it's C when we want it uppercase
385  if ( putativeCountry.toLower() == defaultCountry().toLower() ) {
386  m_country = defaultCountry();
387  } else {
388  m_country = putativeCountry.toLower();
389  }
390 }
391 
392 QString KLocalePrivate::systemCountry() const
393 {
394  // Use QLocale for now as it supposedly provides a sensible default most times,
395  // e.g. if locale is only "de" it is assumed to mean country of "DE"
396  QString systemCountry, s1, s2, s3;
397  splitLocale( QLocale::system().name(), s1, systemCountry, s2, s3 );
398  return systemCountry.toLower();
399 }
400 
401 void KLocalePrivate::initLanguageList(const QString &language, const QString &configLanguages,
402  bool useEnvironmentVariables)
403 {
404  m_language = language;
405 
406  // Collect possible languages by decreasing priority.
407  // The priority is as follows:
408  // - the internally set language, if any
409  // - KDE_LANG environment variable (can be a list)
410  // - KDE configuration (can be a list)
411  // - environment variables considered by gettext(3)
412  // The environment variables are not considered if useEnvironmentVariables is false.
413  QStringList list;
414  if (!m_language.isEmpty()) {
415  list += m_language;
416  }
417 
418  // If the Locale object was created with a specific config file, then do not use the
419  // environmental variables. If the locale object was created with the global config, then
420  // do use the environmental variables.
421  if (useEnvironmentVariables) {
422  // KDE_LANG contains list of language codes, not locale string.
423  getLanguagesFromVariable(list, "KDE_LANG", true);
424  }
425 
426  if (!configLanguages.isEmpty()) {
427  list += configLanguages.split(QLatin1Char(':'));
428  }
429 
430  if (useEnvironmentVariables) {
431  // Collect languages by same order of priority as for gettext(3).
432  // LANGUAGE contains list of language codes, not locale string.
433  getLanguagesFromVariable(list, "LANGUAGE", true);
434  getLanguagesFromVariable(list, "LC_ALL");
435  getLanguagesFromVariable(list, "LC_MESSAGES");
436  getLanguagesFromVariable(list, "LANG");
437  }
438 
439  // fall back to the system language
440  list += systemLanguageList();
441 
442  // Send the list to filter for really present languages on the system.
443  setLanguage(list);
444 }
445 
446 QStringList KLocalePrivate::systemLanguageList() const
447 {
448  return QStringList();
449 }
450 
451 void KLocalePrivate::initFormat()
452 {
453  KConfigGroup cg(config(), "Locale");
454 
455  KConfig entryFile(KStandardDirs::locate("locale", QString::fromLatin1("l10n/%1/entry.desktop").arg(m_country)));
456  entryFile.setLocale(m_language);
457  KConfigGroup entry(&entryFile, "KCM Locale");
458 
459  //One-time conversion in 4.4 from FracDigits to DecimalPlaces and MonetaryDecimalPlaces
460  //If user has personal setting for FracDigits then use it for both Decimal Places
461  //TODO: Possible to do with kconf_update
462  if (cg.hasKey("FracDigits")) {
463  QString fracDigits = cg.readEntry("FracDigits", "");
464  if (!fracDigits.isEmpty()) {
465  cg.writeEntry("DecimalPlaces", fracDigits);
466  cg.writeEntry("MonetaryDecimalPlaces", fracDigits);
467  }
468  cg.deleteEntry("FracDigits");
469  cg.config()->sync();
470  }
471 
472  // Numeric
473 #define readConfigEntry(key, default, save) \
474  save = entry.readEntry(key, default); \
475  save = cg.readEntry(key, save);
476 
477 #define readConfigNumEntry(key, default, save, type) \
478  save = (type)entry.readEntry(key, int(default)); \
479  save = (type)cg.readEntry(key, int(save));
480 
481  // Country settings
482  readConfigEntry("CountryDivisionCode", QString(), m_countryDivisionCode);
483 
484  // Numeric formats
485  readConfigNumEntry("DecimalPlaces", 2, m_decimalPlaces, int);
486 
487  readConfigEntry("DecimalSymbol", ".", m_decimalSymbol);
488  readConfigEntry("ThousandsSeparator", ",", m_thousandsSeparator);
489  m_thousandsSeparator.remove(QString::fromLatin1("$0"));
490  QString digitGroupFormat;
491  readConfigEntry("DigitGroupFormat", "3", digitGroupFormat);
492  m_numericDigitGrouping = digitGroupFormatToList(digitGroupFormat);
493 
494  readConfigEntry("PositiveSign", "", m_positiveSign);
495  readConfigEntry("NegativeSign", "-", m_negativeSign);
496 
497  readConfigNumEntry("DigitSet", KLocale::ArabicDigits, m_digitSet, KLocale::DigitSet);
498  // FIXME: Temporary until full language-sensitivity implemented.
499  readConfigEntry("LanguageSensitiveDigits", true, m_languageSensitiveDigits);
500 
501  // Currency
502  readConfigEntry("CurrencyCode", "USD", m_currencyCode);
503  initCurrency();
504  readConfigEntry("CurrencySymbol", m_currency->defaultSymbol(), m_currencySymbol);
505  readConfigEntry("CurrencyCodesInUse", QStringList(m_currencyCode), m_currencyCodeList);
506 
507  // Monetary formats
508  readConfigNumEntry("MonetaryDecimalPlaces", m_currency->decimalPlaces(), m_monetaryDecimalPlaces, int);
509 
510  readConfigEntry("MonetaryDecimalSymbol", ".", m_monetaryDecimalSymbol);
511  readConfigEntry("MonetaryThousandsSeparator", ",", m_monetaryThousandsSeparator);
512  m_monetaryThousandsSeparator.remove(QString::fromLatin1("$0"));
513  readConfigEntry("MonetaryDigitGroupFormat", "3", digitGroupFormat);
514  m_monetaryDigitGrouping = digitGroupFormatToList(digitGroupFormat);
515 
516  readConfigEntry("PositivePrefixCurrencySymbol", true, m_positivePrefixCurrencySymbol);
517  readConfigEntry("NegativePrefixCurrencySymbol", true, m_negativePrefixCurrencySymbol);
518  readConfigNumEntry("PositiveMonetarySignPosition", KLocale::BeforeQuantityMoney,
519  m_positiveMonetarySignPosition, KLocale::SignPosition);
520  readConfigNumEntry("NegativeMonetarySignPosition", KLocale::ParensAround,
521  m_negativeMonetarySignPosition, KLocale::SignPosition);
522 
523  readConfigNumEntry("MonetaryDigitSet", KLocale::ArabicDigits,
524  m_monetaryDigitSet, KLocale::DigitSet);
525  readConfigNumEntry("BinaryUnitDialect", KLocale::IECBinaryDialect,
526  m_binaryUnitDialect, KLocale::BinaryUnitDialect);
527 
528  // Date and time
529  readConfigEntry("TimeFormat", "%H:%M:%S", m_timeFormat);
530  readConfigEntry("DateFormat", "%A %d %B %Y", m_dateFormat);
531  readConfigEntry("DateFormatShort", "%Y-%m-%d", m_dateFormatShort);
532  readConfigNumEntry("WeekStartDay", 1, m_weekStartDay, int); //default to Monday
533  readConfigNumEntry("WorkingWeekStartDay", 1, m_workingWeekStartDay, int); //default to Monday
534  readConfigNumEntry("WorkingWeekEndDay", 5, m_workingWeekEndDay, int); //default to Friday
535  readConfigNumEntry("WeekDayOfPray", 7, m_weekDayOfPray, int); //default to Sunday
536  readConfigNumEntry("DateTimeDigitSet", KLocale::ArabicDigits,
537  m_dateTimeDigitSet, KLocale::DigitSet);
538  readConfigNumEntry("WeekNumberSystem", KLocale::IsoWeekNumber,
539  m_weekNumberSystem, KLocale::WeekNumberSystem);
540 
541  // other
542 #ifndef QT_NO_PRINTER
543  readConfigNumEntry("PageSize", QPrinter::A4, m_pageSize, QPrinter::PageSize);
544 #endif
545  readConfigNumEntry("MeasureSystem", KLocale::Metric, m_measureSystem, KLocale::MeasureSystem);
546  QString calendarType;
547  readConfigEntry("CalendarSystem", "gregorian", calendarType);
548  setCalendar(calendarType);
549 
550  readConfigEntry("Transcript", true, m_useTranscript);
551 
552  //Grammatical
553  //Precedence here is l10n / i18n / config file
554  KConfig langCfg(KStandardDirs::locate("locale", QString::fromLatin1("%1/entry.desktop").arg(m_language)));
555  KConfigGroup lang(&langCfg, "KCM Locale");
556 #define read3ConfigBoolEntry(key, default, save) \
557  save = entry.readEntry(key, default); \
558  save = lang.readEntry(key, save); \
559  save = cg.readEntry(key, save);
560 
561  read3ConfigBoolEntry("NounDeclension", false, m_nounDeclension);
562  read3ConfigBoolEntry("DateMonthNamePossessive", false, m_dateMonthNamePossessive);
563 
564  initDayPeriods(cg);
565 }
566 
567 void KLocalePrivate::initDayPeriods(const KConfigGroup &cg)
568 {
569  // Prefer any l10n file value for country/language,
570  // otherwise default to language only value which will be filled in later when i18n available
571 
572  //Day Period are stored in config as one QStringList entry per Day Period
573  //PeriodCode,LongName,ShortName,NarrowName,StartTime,EndTime,Offset,OffsetIfZero
574  //where start and end time are in the format HH:MM:SS.MMM
575 
576  m_dayPeriods.clear();
577  QString periodKey = QString::fromLatin1("DayPeriod1");
578  int i = 1;
579  while (cg.hasKey(periodKey)) {
580  QStringList period = cg.readEntry(periodKey, QStringList());
581  if (period.count() == 8) {
582  m_dayPeriods.append(KDayPeriod(period[0], period[1], period[2], period[3],
583  QTime::fromString(period[4], QString::fromLatin1("HH:mm:ss.zzz")),
584  QTime::fromString(period[5], QString::fromLatin1("HH:mm:ss.zzz")),
585  period[6].toInt(), period[7].toInt()));
586  }
587  i = i + 1;
588  periodKey = QString::fromLatin1("DayPeriod%1").arg(i);
589  }
590 }
591 
592 bool KLocalePrivate::setCountry(const QString &country, KConfig *newConfig)
593 {
594  // Cache the valid countries list and add the default C as it is valid to use
595  QStringList validCountries = allCountriesList();
596  validCountries.append(defaultCountry());
597 
598  QString putativeCountry = country;
599 
600  if (putativeCountry.isEmpty()) {
601  // An empty string means to use the system country
602  putativeCountry = systemCountry();
603  if (putativeCountry.isEmpty() || !validCountries.contains(putativeCountry, Qt::CaseInsensitive)) {
604  // If the system country is not valid, use the default
605  putativeCountry = defaultCountry();
606  }
607  } else if (!validCountries.contains(putativeCountry, Qt::CaseInsensitive)) {
608  return false;
609  }
610 
611  // Always save as lowercase, unless it's C when we want it uppercase
612  if (putativeCountry.toLower() == defaultCountry().toLower()) {
613  m_country = defaultCountry();
614  } else {
615  m_country = putativeCountry.toLower();
616  }
617 
618  // Get rid of the old config, start again with the new
619  m_config = KSharedConfig::Ptr();
620  initConfig(newConfig);
621 
622  // Init all the settings
623  initFormat();
624 
625  return true;
626 }
627 
628 bool KLocalePrivate::setCountryDivisionCode(const QString &countryDivisionCode)
629 {
630  m_countryDivisionCode = countryDivisionCode;
631  return true;
632 }
633 
634 bool KLocalePrivate::setLanguage(const QString &language, KConfig *config)
635 {
636  QMutexLocker lock(kLocaleMutex());
637  m_languageList.removeAll(language);
638  m_languageList.prepend(language); // let us consider this language to be the most important one
639 
640  m_language = language; // remember main language for shortcut evaluation
641 
642  // important when called from the outside and harmless when called before
643  // populating the catalog name list
644  updateCatalogs();
645 
646  // Get rid of the old config, start again with the new
647  m_config = KSharedConfig::Ptr();
648  initConfig(config);
649 
650  // Init the new format settings
651  initFormat();
652 
653  // Maybe the mo-files for this language are empty, but in principle we can speak all languages
654  return true;
655 }
656 
657 // KDE5 Unlike the other setLanguage call this does not reparse the config so the localized config
658 // settings for the new primary language will _not_ be loaded. In KDE5 always keep the original
659 // config so this can be reparsed when required.
660 bool KLocalePrivate::setLanguage(const QStringList &languages)
661 {
662  QMutexLocker lock(kLocaleMutex());
663  // This list might contain
664  // 1) some empty strings that we have to eliminate
665  // 2) duplicate entries like in de:fr:de, where we have to keep the first occurrence of a
666  // language in order to preserve the order of precenence of the user
667  // 3) languages into which the application is not translated. For those languages we should not
668  // even load kdelibs.mo or kio.po. these languages have to be dropped. Otherwise we get
669  // strange side effects, e.g. with Hebrew: the right/left switch for languages that write
670  // from right to left (like Hebrew or Arabic) is set in kdelibs.mo. If you only have
671  // kdelibs.mo but nothing from appname.mo, you get a mostly English app with layout from
672  // right to left. That was considered to be a bug by the Hebrew translators.
673  QStringList list;
674  foreach(const QString &language, languages) {
675  if (!language.isEmpty() && !list.contains(language) && isApplicationTranslatedInto(language)) {
676  list.append(language);
677  }
678  }
679 
680  if (!list.contains(KLocale::defaultLanguage())) {
681  // English should always be added as final possibility; this is important
682  // for proper initialization of message text post-processors which are
683  // needed for English too, like semantic to visual formatting, etc.
684  list.append(KLocale::defaultLanguage());
685  }
686 
687  m_language = list.first(); // keep this for shortcut evaluations
688 
689  m_languageList = list; // keep this new list of languages to use
690 
691  // important when called from the outside and harmless when called before populating the
692  // catalog name list
693  updateCatalogs();
694 
695  return true; // we found something. Maybe it's only English, but we found something
696 }
697 
698 void KLocalePrivate::initCurrency()
699 {
700  if (m_currencyCode.isEmpty() || !KCurrencyCode::isValid(m_currencyCode)) {
701  m_currencyCode = KLocale::defaultCurrencyCode();
702  }
703 
704  if (!m_currency || m_currencyCode != m_currency->isoCurrencyCode() || !m_currency->isValid()) {
705  delete m_currency;
706  m_currency = new KCurrencyCode(m_currencyCode, m_language);
707  }
708 }
709 
710 void KLocalePrivate::setCurrencyCode(const QString &newCurrencyCode)
711 {
712  if (!newCurrencyCode.isEmpty() && newCurrencyCode != m_currency->isoCurrencyCode() &&
713  KCurrencyCode::isValid(newCurrencyCode)) {
714  m_currencyCode = newCurrencyCode;
715  initCurrency();
716  }
717 }
718 
719 bool KLocalePrivate::isApplicationTranslatedInto(const QString &lang)
720 {
721  if (lang.isEmpty()) {
722  return false;
723  }
724 
725  if (lang == KLocale::defaultLanguage()) {
726  // default language is always "installed"
727  return true;
728  }
729 
730  if (m_catalogName.isEmpty()) {
731  kDebug() << "no appName!";
732  return false;
733  }
734 
735  if (!KCatalog::catalogLocaleDir(m_catalogName, lang).isEmpty()) {
736  return true;
737  }
738  return false;
739 }
740 
741 void KLocalePrivate::splitLocale(const QString &aLocale, QString &language, QString &country,
742  QString &modifier, QString &charset)
743 {
744  QString locale = aLocale;
745 
746  language.clear();
747  country.clear();
748  modifier.clear();
749  charset.clear();
750 
751  // In case there are several concatenated locale specifications,
752  // truncate all but first.
753  int f = locale.indexOf(QLatin1Char(':'));
754  if (f >= 0) {
755  locale.truncate(f);
756  }
757 
758  f = locale.indexOf(QLatin1Char('.'));
759  if (f >= 0) {
760  charset = locale.mid(f + 1);
761  locale.truncate(f);
762  }
763 
764  f = locale.indexOf(QLatin1Char('@'));
765  if (f >= 0) {
766  modifier = locale.mid(f + 1);
767  locale.truncate(f);
768  }
769 
770  f = locale.indexOf(QLatin1Char('_'));
771  if (f >= 0) {
772  country = locale.mid(f + 1);
773  locale.truncate(f);
774  }
775 
776  language = locale;
777 }
778 
779 QString KLocalePrivate::language() const
780 {
781  return m_language;
782 }
783 
784 QString KLocalePrivate::country() const
785 {
786  return m_country;
787 }
788 
789 QString KLocalePrivate::countryDivisionCode() const
790 {
791  if (m_countryDivisionCode.isEmpty()) {
792  return country().toUpper();
793  } else {
794  return m_countryDivisionCode;
795  }
796 }
797 
798 KCurrencyCode *KLocalePrivate::currency()
799 {
800  if (!m_currency) {
801  initCurrency();
802  }
803  return m_currency;
804 }
805 
806 QString KLocalePrivate::currencyCode() const
807 {
808  return m_currencyCode;
809 }
810 
811 void KLocalePrivate::insertCatalog(const QString &catalog)
812 {
813  QMutexLocker lock(kLocaleMutex());
814  int pos = m_catalogNames.indexOf(KCatalogName(catalog));
815  if (pos != -1) {
816  ++m_catalogNames[pos].loadCount;
817  return;
818  }
819 
820  // Insert new catalog just before system catalogs, to preserve the
821  // lowest priority of system catalogs.
822  m_catalogNames.insert(m_catalogNames.size() - m_numberOfSysCatalogs, KCatalogName(catalog));
823  updateCatalogs(); // evaluate the changed list and generate the necessary KCatalog objects
824 }
825 
826 void KLocalePrivate::updateCatalogs()
827 {
828  // some changes have occurred. Maybe we have learned or forgotten some languages.
829  // Maybe the language precedence has changed.
830  // Maybe we have learned or forgotten some catalog names.
831 
832  QList<KCatalog> newCatalogs;
833 
834  // now iterate over all languages and all wanted catalog names and append or create them in the
835  // right order the sequence must be e.g. nds/appname nds/kdelibs nds/kio de/appname de/kdelibs
836  // de/kio etc. and not nds/appname de/appname nds/kdelibs de/kdelibs etc. Otherwise we would be
837  // in trouble with a language sequende nds,<default>,de. In this case <default> must hide
838  // everything after itself in the language list.
839  foreach(const QString &lang, m_languageList) {
840  if (lang == KLocale::defaultLanguage()) {
841  // Default language has no catalogs (messages from the code),
842  // so loading catalogs for languages below the default
843  // would later confuse the fallback resolution.
844  break;
845  }
846  foreach(const KCatalogName &name, m_catalogNames) {
847  // create and add catalog for this name and language if it exists
848  if (! KCatalog::catalogLocaleDir(name.name, lang).isEmpty()) {
849  newCatalogs.append(KCatalog(name.name, lang));
850  //kDebug(173) << "Catalog: " << name << ":" << lang;
851  }
852  }
853  }
854 
855  // notify KLocalizedString of catalog update.
856  m_catalogs = newCatalogs;
857  KLocalizedString::notifyCatalogsUpdated(m_languageList, m_catalogNames);
858 }
859 
860 void KLocalePrivate::removeCatalog(const QString &catalog)
861 {
862  QMutexLocker lock(kLocaleMutex());
863  int pos = m_catalogNames.indexOf(KCatalogName(catalog));
864  if (pos == -1) {
865  return;
866  }
867  if (--m_catalogNames[pos].loadCount > 0) {
868  return;
869  }
870  m_catalogNames.removeAt(pos);
871  if (KGlobal::hasMainComponent()) {
872  // walk through the KCatalog instances and weed out everything we no longer need
873  updateCatalogs();
874  }
875 }
876 
877 void KLocalePrivate::setActiveCatalog(const QString &catalog)
878 {
879  QMutexLocker lock(kLocaleMutex());
880  int pos = m_catalogNames.indexOf(KCatalogName(catalog));
881  if (pos == -1) {
882  return;
883  }
884  m_catalogNames.move(pos, 0);
885  // walk through the KCatalog instances and adapt to the new order
886  updateCatalogs();
887 }
888 
889 void KLocalePrivate::translateRawFrom(const char *catname, const char *msgctxt, const char *msgid, const char *msgid_plural,
890  unsigned long n, QString *language, QString *translation) const
891 {
892  if (!msgid || !msgid[0]) {
893  kDebug(173) << "KLocale: trying to look up \"\" in catalog. "
894  << "Fix the program" << endl;
895  language->clear();
896  translation->clear();
897  return;
898  }
899  if (msgctxt && !msgctxt[0]) {
900  kDebug(173) << "KLocale: trying to use \"\" as context to message. "
901  << "Fix the program" << endl;
902  }
903  if (msgid_plural && !msgid_plural[0]) {
904  kDebug(173) << "KLocale: trying to use \"\" as plural message. "
905  << "Fix the program" << endl;
906  }
907 
908  QMutexLocker locker(kLocaleMutex());
909  // determine the fallback string
910  QString fallback;
911  if (msgid_plural == NULL) {
912  fallback = QString::fromUtf8(msgid);
913  } else {
914  if (n == 1) {
915  fallback = QString::fromUtf8(msgid);
916  } else {
917  fallback = QString::fromUtf8(msgid_plural);
918  }
919  }
920  if (language) {
921  *language = KLocale::defaultLanguage();
922  }
923  if (translation) {
924  *translation = fallback;
925  }
926 
927  // shortcut evaluation if default language is main language: do not consult the catalogs
928  if (useDefaultLanguage()) {
929  return;
930  }
931 
932  const QList<KCatalog> catalogList = m_catalogs;
933  QString catNameDecoded;
934  if (catname != NULL) {
935  catNameDecoded = QString::fromUtf8(catname);
936  }
937  for (QList<KCatalog>::ConstIterator it = catalogList.constBegin(); it != catalogList.constEnd();
938  ++it) {
939  // shortcut evaluation: once we have arrived at default language, we cannot consult
940  // the catalog as it will not have an assiciated mo-file. For this default language we can
941  // immediately pick the fallback string.
942  if ((*it).language() == KLocale::defaultLanguage()) {
943  return;
944  }
945 
946  if (catNameDecoded.isEmpty() || catNameDecoded == (*it).name()) {
947  QString text;
948  if (msgctxt != NULL && msgid_plural != NULL) {
949  text = (*it).translateStrict(msgctxt, msgid, msgid_plural, n);
950  } else if (msgid_plural != NULL) {
951  text = (*it).translateStrict(msgid, msgid_plural, n);
952  } else if (msgctxt != NULL) {
953  text = (*it).translateStrict(msgctxt, msgid);
954  } else {
955  text = (*it).translateStrict(msgid);
956  }
957 
958  if (!text.isEmpty()) {
959  // we found it
960  if (language) {
961  *language = (*it).language();
962  }
963  if (translation) {
964  *translation = text;
965  }
966  return;
967  }
968  }
969  }
970 }
971 
972 QString KLocalePrivate::translateQt(const char *context, const char *sourceText, const char *comment) const
973 {
974  // Qt's context is normally the name of the class of the method which makes
975  // the tr(sourceText) call. However, it can also be manually supplied via
976  // translate(context, sourceText) call.
977  //
978  // Qt's sourceText is the actual message displayed to the user.
979  //
980  // Qt's comment is an optional argument of tr() and translate(), like
981  // tr(sourceText, comment) and translate(context, sourceText, comment).
982  //
983  // We handle this in the following way:
984  //
985  // If the comment is given, then it is considered gettext's msgctxt, so a
986  // context call is made.
987  //
988  // If the comment is not given, but context is given, then we treat it as
989  // msgctxt only if it was manually supplied (the one in translate()) -- but
990  // we don't know this, so we first try a context call, and if translation
991  // is not found, we fallback to ordinary call.
992  //
993  // If neither comment nor context are given, it's just an ordinary call
994  // on sourceText.
995 
996  if (!sourceText || !sourceText[0]) {
997  kDebug(173) << "KLocale: trying to look up \"\" in catalog. "
998  << "Fix the program" << endl;
999  return QString();
1000  }
1001 
1002  if (useDefaultLanguage()) {
1003  return QString();
1004  }
1005 
1006  QString translation;
1007  QString language;
1008 
1009  // NOTE: Condition (language != defaultLanguage()) means that translation
1010  // was found, otherwise we got the original string back as translation.
1011 
1012  if (comment && comment[0]) {
1013  // Comment given, go for context call.
1014  translateRawFrom(0, comment, sourceText, 0, 0, &language, &translation);
1015  } else {
1016  // Comment not given, go for try-fallback with context.
1017  if (context && context[0]) {
1018  translateRawFrom(0, context, sourceText, 0, 0, &language, &translation);
1019  }
1020  if (language.isEmpty() || language == defaultLanguage()) {
1021  translateRawFrom(0, 0, sourceText, 0, 0, &language, &translation);
1022  }
1023  }
1024 
1025  if (language != defaultLanguage()) {
1026  return translation;
1027  }
1028 
1029  // No proper translation found, return empty according to Qt's expectation.
1030  return QString();
1031 }
1032 
1033 QList<KLocale::DigitSet> KLocalePrivate::allDigitSetsList() const
1034 {
1035  QList<KLocale::DigitSet> digitSets;
1036  digitSets.append(KLocale::ArabicDigits);
1037  digitSets.append(KLocale::ArabicIndicDigits);
1038  digitSets.append(KLocale::BengaliDigits);
1039  digitSets.append(KLocale::DevenagariDigits);
1040  digitSets.append(KLocale::EasternArabicIndicDigits);
1041  digitSets.append(KLocale::GujaratiDigits);
1042  digitSets.append(KLocale::GurmukhiDigits);
1043  digitSets.append(KLocale::KannadaDigits);
1044  digitSets.append(KLocale::KhmerDigits);
1045  digitSets.append(KLocale::MalayalamDigits);
1046  digitSets.append(KLocale::OriyaDigits);
1047  digitSets.append(KLocale::TamilDigits);
1048  digitSets.append(KLocale::TeluguDigits);
1049  digitSets.append(KLocale::ThaiDigits);
1050  qSort(digitSets);
1051  return digitSets;
1052 }
1053 
1054 QString KLocalePrivate::digitSetString(KLocale::DigitSet digitSet)
1055 {
1056  switch (digitSet) {
1057  case KLocale::ArabicIndicDigits:
1058  return QString::fromUtf8("٠١٢٣٤٥٦٧٨٩");
1059  case KLocale::BengaliDigits:
1060  return QString::fromUtf8("০১২৩৪৫৬৭৮৯");
1061  case KLocale::DevenagariDigits:
1062  return QString::fromUtf8("०१२३४५६७८९");
1063  case KLocale::EasternArabicIndicDigits:
1064  return QString::fromUtf8("۰۱۲۳۴۵۶۷۸۹");
1065  case KLocale::GujaratiDigits:
1066  return QString::fromUtf8("૦૧૨૩૪૫૬૭૮૯");
1067  case KLocale::GurmukhiDigits:
1068  return QString::fromUtf8("੦੧੨੩੪੫੬੭੮੯");
1069  case KLocale::KannadaDigits:
1070  return QString::fromUtf8("೦೧೨೩೪೫೬೭೮೯");
1071  case KLocale::KhmerDigits:
1072  return QString::fromUtf8("០១២៣៤៥៦៧៨៩");
1073  case KLocale::MalayalamDigits:
1074  return QString::fromUtf8("൦൧൨൩൪൫൬൭൮൯");
1075  case KLocale::OriyaDigits:
1076  return QString::fromUtf8("୦୧୨୩୪୫୬୭୮୯");
1077  case KLocale::TamilDigits:
1078  return QString::fromUtf8("௦௧௨௩௪௫௬௭௮");
1079  case KLocale::TeluguDigits:
1080  return QString::fromUtf8("౦౧౨౩౪౫౬౭౯");
1081  case KLocale::ThaiDigits:
1082  return QString::fromUtf8("๐๑๒๓๔๕๖๗๘๙");
1083  default:
1084  return QString::fromUtf8("0123456789");
1085  }
1086 }
1087 
1088 QString KLocalePrivate::digitSetToName(KLocale::DigitSet digitSet, bool withDigits) const
1089 {
1090  QString name;
1091  switch (digitSet) {
1092  case KLocale::ArabicIndicDigits:
1093  name = i18nc("digit set", "Arabic-Indic");
1094  break;
1095  case KLocale::BengaliDigits:
1096  name = i18nc("digit set", "Bengali");
1097  break;
1098  case KLocale::DevenagariDigits:
1099  name = i18nc("digit set", "Devanagari");
1100  break;
1101  case KLocale::EasternArabicIndicDigits:
1102  name = i18nc("digit set", "Eastern Arabic-Indic");
1103  break;
1104  case KLocale::GujaratiDigits:
1105  name = i18nc("digit set", "Gujarati");
1106  break;
1107  case KLocale::GurmukhiDigits:
1108  name = i18nc("digit set", "Gurmukhi");
1109  break;
1110  case KLocale::KannadaDigits:
1111  name = i18nc("digit set", "Kannada");
1112  break;
1113  case KLocale::KhmerDigits:
1114  name = i18nc("digit set", "Khmer");
1115  break;
1116  case KLocale::MalayalamDigits:
1117  name = i18nc("digit set", "Malayalam");
1118  break;
1119  case KLocale::OriyaDigits:
1120  name = i18nc("digit set", "Oriya");
1121  break;
1122  case KLocale::TamilDigits:
1123  name = i18nc("digit set", "Tamil");
1124  break;
1125  case KLocale::TeluguDigits:
1126  name = i18nc("digit set", "Telugu");
1127  break;
1128  case KLocale::ThaiDigits:
1129  name = i18nc("digit set", "Thai");
1130  break;
1131  default:
1132  name = i18nc("digit set", "Arabic");
1133  }
1134  if (withDigits) {
1135  QString digits = digitSetString(digitSet);
1136  QString nameWithDigits = i18nc("name of digit set with digit string, "
1137  "e.g. 'Arabic (0123456789)'", "%1 (%2)", name, digits);
1138  return nameWithDigits;
1139  } else {
1140  return name;
1141  }
1142 }
1143 
1144 QString KLocalePrivate::convertDigits(const QString &str, KLocale::DigitSet digitSet, bool ignoreContext) const
1145 {
1146  if (!ignoreContext) {
1147  // Fall back to Western Arabic digits if requested digit set
1148  // is not appropriate for current application language.
1149  // FIXME: Temporary until full language-sensitivity implemented.
1150  KLocaleStaticData *s = staticData;
1151  if (m_languageSensitiveDigits && !s->languagesUsingDigitSet[digitSet].contains(m_language)) {
1152  digitSet = KLocale::ArabicDigits;
1153  }
1154  }
1155 
1156  QString nstr;
1157  QString digitDraw = digitSetString(digitSet);
1158  foreach(const QChar &c, str) {
1159  if (c.isDigit()) {
1160  nstr += digitDraw[c.digitValue()];
1161  } else {
1162  nstr += c;
1163  }
1164  }
1165  return nstr;
1166 }
1167 
1168 QString KLocalePrivate::toArabicDigits(const QString &str)
1169 {
1170  QString nstr;
1171  foreach(const QChar &c, str) {
1172  if (c.isDigit()) {
1173  nstr += QChar('0' + c.digitValue());
1174  } else {
1175  nstr += c;
1176  }
1177  }
1178  return nstr;
1179 }
1180 
1181 bool KLocalePrivate::nounDeclension() const
1182 {
1183  return m_nounDeclension;
1184 }
1185 
1186 bool KLocalePrivate::dateMonthNamePossessive() const
1187 {
1188  return m_dateMonthNamePossessive;
1189 }
1190 
1191 int KLocalePrivate::weekStartDay() const
1192 {
1193  return m_weekStartDay;
1194 }
1195 
1196 int KLocalePrivate::workingWeekStartDay() const
1197 {
1198  return m_workingWeekStartDay;
1199 }
1200 
1201 int KLocalePrivate::workingWeekEndDay() const
1202 {
1203  return m_workingWeekEndDay;
1204 }
1205 
1206 int KLocalePrivate::weekDayOfPray() const
1207 {
1208  return m_weekDayOfPray;
1209 }
1210 
1211 int KLocalePrivate::decimalPlaces() const
1212 {
1213  return m_decimalPlaces;
1214 }
1215 
1216 QString KLocalePrivate::decimalSymbol() const
1217 {
1218  return m_decimalSymbol;
1219 }
1220 
1221 QString KLocalePrivate::thousandsSeparator() const
1222 {
1223  return m_thousandsSeparator;
1224 }
1225 
1226 QList<int> KLocalePrivate::numericDigitGrouping() const
1227 {
1228  return m_numericDigitGrouping;
1229 }
1230 
1231 QString KLocalePrivate::currencySymbol() const
1232 {
1233  return m_currencySymbol;
1234 }
1235 
1236 QString KLocalePrivate::monetaryDecimalSymbol() const
1237 {
1238  return m_monetaryDecimalSymbol;
1239 }
1240 
1241 QString KLocalePrivate::monetaryThousandsSeparator() const
1242 {
1243  return m_monetaryThousandsSeparator;
1244 }
1245 
1246 QList<int> KLocalePrivate::monetaryDigitGrouping() const
1247 {
1248  return m_monetaryDigitGrouping;
1249 }
1250 
1251 QString KLocalePrivate::positiveSign() const
1252 {
1253  return m_positiveSign;
1254 }
1255 
1256 QString KLocalePrivate::negativeSign() const
1257 {
1258  return m_negativeSign;
1259 }
1260 
1261 /* Just copy to keep the diff looking clean, delete later
1262 int KLocale::fracDigits() const
1263 {
1264  return monetaryDecimalPlaces();
1265 }
1266 */
1267 
1268 int KLocalePrivate::monetaryDecimalPlaces() const
1269 {
1270  return m_monetaryDecimalPlaces;
1271 }
1272 
1273 bool KLocalePrivate::positivePrefixCurrencySymbol() const
1274 {
1275  return m_positivePrefixCurrencySymbol;
1276 }
1277 
1278 bool KLocalePrivate::negativePrefixCurrencySymbol() const
1279 {
1280  return m_negativePrefixCurrencySymbol;
1281 }
1282 
1283 KLocale::SignPosition KLocalePrivate::positiveMonetarySignPosition() const
1284 {
1285  return m_positiveMonetarySignPosition;
1286 }
1287 
1288 KLocale::SignPosition KLocalePrivate::negativeMonetarySignPosition() const
1289 {
1290  return m_negativeMonetarySignPosition;
1291 }
1292 
1293 static inline void put_it_in(QChar *buffer, int &index, const QString &s)
1294 {
1295  for (int l = 0; l < s.length(); l++) {
1296  buffer[index++] = s.at(l);
1297  }
1298 }
1299 
1300 static inline void put_it_in(QChar *buffer, int &index, int number)
1301 {
1302  buffer[index++] = number / 10 + '0';
1303  buffer[index++] = number % 10 + '0';
1304 }
1305 
1306 // Convert POSIX Digit Group Format string into a Qlist<int>, e.g. "3;2" converts to (3,2)
1307 QList<int> KLocalePrivate::digitGroupFormatToList(const QString &digitGroupFormat) const
1308 {
1309  QList<int> groupList;
1310  QStringList stringList = digitGroupFormat.split(QLatin1Char(';'));
1311  foreach(const QString &size, stringList) {
1312  groupList.append(size.toInt());
1313  }
1314  return groupList;
1315 }
1316 
1317 // Inserts all required occurrences of the group separator into a number string.
1318 QString KLocalePrivate::formatDigitGroup(const QString &number, const QString &groupSeparator, const QString &decimalSeperator, QList<int> groupList) const
1319 {
1320  if (groupList.isEmpty() || groupSeparator.isEmpty()) {
1321  return number;
1322  }
1323 
1324  QString num = number;
1325  int groupCount = groupList.count();
1326  int groupAt = 0;
1327  int groupSize = groupList.at(groupAt);
1328  int pos = num.indexOf(decimalSeperator);
1329  if (pos == -1) {
1330  pos = num.length();
1331  }
1332  pos = pos - groupSize;
1333 
1334  while (pos > 0 && groupSize > 0) {
1335  num.insert(pos, groupSeparator);
1336  if (groupAt + 1 < groupCount) {
1337  ++groupAt;
1338  groupSize = groupList.at(groupAt);
1339  }
1340  pos = pos - groupSize;
1341  }
1342 
1343  return num;
1344 }
1345 
1346 // Strips all occurrences of the group separator from a number, returns ok if the separators were all in the valid positions
1347 QString KLocalePrivate::parseDigitGroup(const QString &number, const QString &groupSeparator, const QString &decimalSeparator, QList<int> groupList, bool *ok) const
1348 {
1349  QString num = number;
1350  bool valid = true;
1351 
1352  if (!groupSeparator.isEmpty()) {
1353  if (!groupList.isEmpty()) {
1354  int separatorSize = groupSeparator.length();
1355  int groupCount = groupList.count();
1356  int groupAt = 0;
1357  int groupSize = groupList.at(groupAt);
1358  int pos = number.indexOf(decimalSeparator);
1359  if (pos == -1) {
1360  pos = number.length();
1361  }
1362  pos = pos - groupSize - separatorSize;
1363 
1364  while (pos > 0 && valid && groupSize > 0) {
1365  if (num.mid(pos, separatorSize) == groupSeparator) {
1366  num.remove(pos, separatorSize);
1367  if (groupAt + 1 < groupCount) {
1368  ++groupAt;
1369  groupSize = groupList.at(groupAt);
1370  }
1371  pos = pos - groupSize - separatorSize;
1372  } else {
1373  valid = false;
1374  }
1375  }
1376  }
1377 
1378  if (num.contains(groupSeparator)) {
1379  valid = false;
1380  num = num.remove(groupSeparator);
1381  }
1382  }
1383 
1384  if (ok) {
1385  *ok = valid;
1386  }
1387 
1388  return num;
1389 }
1390 
1391 QString KLocalePrivate::formatMoney(double num, const QString &symbol, int precision) const
1392 {
1393  // some defaults
1394  QString currencyString = symbol;
1395  if (symbol.isNull()) {
1396  currencyString = currencySymbol();
1397  }
1398  if (precision < 0) {
1399  precision = monetaryDecimalPlaces();
1400  }
1401 
1402  // the number itself
1403  bool neg = num < 0;
1404  QString res = QString::number(neg ? -num : num, 'f', precision);
1405 
1406  // Replace dot with locale decimal separator
1407  res.replace(QLatin1Char('.'), monetaryDecimalSymbol());
1408 
1409  // Insert the thousand separators
1410  res = formatDigitGroup(res, monetaryThousandsSeparator(), monetaryDecimalSymbol(), monetaryDigitGrouping());
1411 
1412  // set some variables we need later
1413  int signpos = neg
1414  ? negativeMonetarySignPosition()
1415  : positiveMonetarySignPosition();
1416  QString sign = neg
1417  ? negativeSign()
1418  : positiveSign();
1419 
1420  switch (signpos) {
1421  case KLocale::ParensAround:
1422  res.prepend(QLatin1Char('('));
1423  res.append(QLatin1Char(')'));
1424  break;
1425  case KLocale::BeforeQuantityMoney:
1426  res.prepend(sign);
1427  break;
1428  case KLocale::AfterQuantityMoney:
1429  res.append(sign);
1430  break;
1431  case KLocale::BeforeMoney:
1432  currencyString.prepend(sign);
1433  break;
1434  case KLocale::AfterMoney:
1435  currencyString.append(sign);
1436  break;
1437  }
1438 
1439  if (neg ? negativePrefixCurrencySymbol() :
1440  positivePrefixCurrencySymbol()) {
1441  res.prepend(QLatin1Char(' '));
1442  res.prepend(currencyString);
1443  } else {
1444  res.append(QLatin1Char(' '));
1445  res.append(currencyString);
1446  }
1447 
1448  // Convert to target digit set.
1449  res = convertDigits(res, m_monetaryDigitSet);
1450 
1451  return res;
1452 }
1453 
1454 
1455 QString KLocalePrivate::formatNumber(double num, int precision) const
1456 {
1457  if (precision < 0) {
1458  precision = decimalPlaces();
1459  }
1460  // no need to round since QString::number does this for us
1461  return formatNumber(QString::number(num, 'f', precision), false, 0);
1462 }
1463 
1464 QString KLocalePrivate::formatLong(long num) const
1465 {
1466  return formatNumber((double)num, 0);
1467 }
1468 
1469 // increase the digit at 'position' by one
1470 static void _inc_by_one(QString &str, int position)
1471 {
1472  for (int i = position; i >= 0; i--) {
1473  char last_char = str[i].toLatin1();
1474  switch (last_char) {
1475  case '0':
1476  str[i] = '1';
1477  break;
1478  case '1':
1479  str[i] = '2';
1480  break;
1481  case '2':
1482  str[i] = '3';
1483  break;
1484  case '3':
1485  str[i] = '4';
1486  break;
1487  case '4':
1488  str[i] = '5';
1489  break;
1490  case '5':
1491  str[i] = '6';
1492  break;
1493  case '6':
1494  str[i] = '7';
1495  break;
1496  case '7':
1497  str[i] = '8';
1498  break;
1499  case '8':
1500  str[i] = '9';
1501  break;
1502  case '9':
1503  str[i] = '0';
1504  if (i == 0) str.prepend(QLatin1Char('1'));
1505  continue;
1506  case '.':
1507  continue;
1508  }
1509  break;
1510  }
1511 }
1512 
1513 // Cut off if more digits in fractional part than 'precision'
1514 static void _round(QString &str, int precision)
1515 {
1516  int decimalSymbolPos = str.indexOf(QLatin1Char('.'));
1517 
1518  if (decimalSymbolPos == -1) {
1519  if (precision == 0) return;
1520  else if (precision > 0) { // add dot if missing (and needed)
1521  str.append(QLatin1Char('.'));
1522  decimalSymbolPos = str.length() - 1;
1523  }
1524  }
1525  // fill up with more than enough zeroes (in case fractional part too short)
1526  str.reserve(str.length() + precision);
1527  for (int i = 0; i < precision; ++i)
1528  str.append(QLatin1Char('0'));
1529 
1530  // Now decide whether to round up or down
1531  char last_char = str[decimalSymbolPos + precision + 1].toLatin1();
1532  switch (last_char) {
1533  case '0':
1534  case '1':
1535  case '2':
1536  case '3':
1537  case '4':
1538  // nothing to do, rounding down
1539  break;
1540  case '5':
1541  case '6':
1542  case '7':
1543  case '8':
1544  case '9':
1545  _inc_by_one(str, decimalSymbolPos + precision);
1546  break;
1547  default:
1548  break;
1549  }
1550 
1551  decimalSymbolPos = str.indexOf(QLatin1Char('.'));
1552  str.truncate(decimalSymbolPos + precision + 1);
1553 
1554  // if precision == 0 delete also '.'
1555  if (precision == 0) {
1556  str = str.left(decimalSymbolPos);
1557  }
1558 
1559  str.squeeze();
1560 }
1561 
1562 QString KLocalePrivate::formatNumber(const QString &numStr, bool round, int precision) const
1563 {
1564  QString tmpString = numStr;
1565 
1566  if (precision < 0) {
1567  precision = decimalPlaces();
1568  }
1569 
1570  // Skip the sign (for now)
1571  const bool neg = (tmpString[0] == QLatin1Char('-'));
1572  if (neg || tmpString[0] == QLatin1Char('+')) {
1573  tmpString.remove(0, 1);
1574  }
1575 
1576  //kDebug(173)<<"tmpString:"<<tmpString;
1577 
1578  // Split off exponential part (including 'e'-symbol)
1579  const int expPos = tmpString.indexOf(QLatin1Char('e')); // -1 if not found
1580  QString mantString = tmpString.left(expPos); // entire string if no 'e' found
1581  QString expString;
1582  if (expPos > -1) {
1583  expString = tmpString.mid(expPos); // includes the 'e', or empty if no 'e'
1584  if (expString.length() == 1) {
1585  expString.clear();
1586  }
1587  }
1588 
1589  //kDebug(173)<<"mantString:"<<mantString;
1590  //kDebug(173)<<"expString:"<<expString;
1591  if (mantString.isEmpty() || !mantString[0].isDigit()) {// invalid number
1592  mantString = QLatin1Char('0');
1593  }
1594 
1595  if (round) {
1596  _round(mantString, precision);
1597  }
1598 
1599  // Replace dot with locale decimal separator
1600  mantString.replace(QLatin1Char('.'), decimalSymbol());
1601 
1602  // Insert the thousand separators
1603  mantString = formatDigitGroup(mantString, thousandsSeparator(), decimalSymbol(), numericDigitGrouping());
1604 
1605  // How can we know where we should put the sign?
1606  mantString.prepend(neg ? negativeSign() : positiveSign());
1607 
1608  // Convert to target digit set.
1609  if (digitSet() != KLocale::ArabicDigits) {
1610  mantString = convertDigits(mantString, digitSet());
1611  expString = convertDigits(expString, digitSet());
1612  }
1613 
1614  return mantString + expString;
1615 }
1616 
1617 // Returns a list of already translated units to use later in formatByteSize
1618 // and friends. Account for every unit in KLocale::BinarySizeUnits
1619 QList<QString> KLocalePrivate::dialectUnitsList(KLocale::BinaryUnitDialect dialect)
1620 {
1621  QList<QString> binaryUnits;
1622  QString s; // Used in CACHE_BYTE_FMT macro defined shortly
1623 
1624  // Adds a given translation to the binaryUnits list.
1625 #define CACHE_BYTE_FMT(ctxt_text) \
1626  translateRawFrom(0, ctxt_text, 0, 0, 0, &s); \
1627  binaryUnits.append(s);
1628 
1629  // Do not remove i18n: comments below, they are used by the
1630  // translators.
1631 
1632  // This prefix is shared by all current dialects.
1633  // i18n: Dumb message, avoid any markup or scripting.
1634  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in bytes", "%1 B"));
1635 
1636  switch (dialect) {
1637  case KLocale::MetricBinaryDialect:
1638  // i18n: Dumb message, avoid any markup or scripting.
1639  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 1000 bytes", "%1 kB"));
1640  // i18n: Dumb message, avoid any markup or scripting.
1641  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^6 bytes", "%1 MB"));
1642  // i18n: Dumb message, avoid any markup or scripting.
1643  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^9 bytes", "%1 GB"));
1644  // i18n: Dumb message, avoid any markup or scripting.
1645  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^12 bytes", "%1 TB"));
1646  // i18n: Dumb message, avoid any markup or scripting.
1647  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^15 bytes", "%1 PB"));
1648  // i18n: Dumb message, avoid any markup or scripting.
1649  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^18 bytes", "%1 EB"));
1650  // i18n: Dumb message, avoid any markup or scripting.
1651  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^21 bytes", "%1 ZB"));
1652  // i18n: Dumb message, avoid any markup or scripting.
1653  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 10^24 bytes", "%1 YB"));
1654  break;
1655 
1656  case KLocale::JEDECBinaryDialect:
1657  // i18n: Dumb message, avoid any markup or scripting.
1658  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 1024 bytes", "%1 KB"));
1659  // i18n: Dumb message, avoid any markup or scripting.
1660  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^20 bytes", "%1 MB"));
1661  // i18n: Dumb message, avoid any markup or scripting.
1662  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^30 bytes", "%1 GB"));
1663  // i18n: Dumb message, avoid any markup or scripting.
1664  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^40 bytes", "%1 TB"));
1665  // i18n: Dumb message, avoid any markup or scripting.
1666  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^50 bytes", "%1 PB"));
1667  // i18n: Dumb message, avoid any markup or scripting.
1668  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^60 bytes", "%1 EB"));
1669  // i18n: Dumb message, avoid any markup or scripting.
1670  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^70 bytes", "%1 ZB"));
1671  // i18n: Dumb message, avoid any markup or scripting.
1672  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("memory size in 2^80 bytes", "%1 YB"));
1673  break;
1674 
1675  case KLocale::IECBinaryDialect:
1676  default:
1677  // i18n: Dumb message, avoid any markup or scripting.
1678  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 1024 bytes", "%1 KiB"));
1679  // i18n: Dumb message, avoid any markup or scripting.
1680  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^20 bytes", "%1 MiB"));
1681  // i18n: Dumb message, avoid any markup or scripting.
1682  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^30 bytes", "%1 GiB"));
1683  // i18n: Dumb message, avoid any markup or scripting.
1684  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^40 bytes", "%1 TiB"));
1685  // i18n: Dumb message, avoid any markup or scripting.
1686  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^50 bytes", "%1 PiB"));
1687  // i18n: Dumb message, avoid any markup or scripting.
1688  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^60 bytes", "%1 EiB"));
1689  // i18n: Dumb message, avoid any markup or scripting.
1690  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^70 bytes", "%1 ZiB"));
1691  // i18n: Dumb message, avoid any markup or scripting.
1692  CACHE_BYTE_FMT(I18N_NOOP2_NOSTRIP("size in 2^80 bytes", "%1 YiB"));
1693  break;
1694  }
1695 
1696  return binaryUnits;
1697 }
1698 
1699 QString KLocalePrivate::formatByteSize(double size, int precision, KLocale::BinaryUnitDialect dialect,
1700  KLocale::BinarySizeUnits specificUnit)
1701 {
1702  // Error checking
1703  if (dialect <= KLocale::DefaultBinaryDialect || dialect > KLocale::LastBinaryDialect) {
1704  dialect = m_binaryUnitDialect;
1705  }
1706 
1707  if (specificUnit < KLocale::DefaultBinaryUnits || specificUnit > KLocale::UnitLastUnit) {
1708  specificUnit = KLocale::DefaultBinaryUnits;
1709  }
1710 
1711  // Choose appropriate units.
1712  QList<QString> dialectUnits;
1713  if (dialect == m_binaryUnitDialect) {
1714  // Cache default units for speed
1715  if (m_byteSizeFmt.size() == 0) {
1716  QMutexLocker lock(kLocaleMutex());
1717 
1718  // We only cache the user's default dialect.
1719  m_byteSizeFmt = dialectUnitsList(m_binaryUnitDialect);
1720  }
1721 
1722  dialectUnits = m_byteSizeFmt;
1723  } else {
1724  dialectUnits = dialectUnitsList(dialect);
1725  }
1726 
1727  int unit = 0; // Selects what unit to use from cached list
1728  double multiplier = 1024.0;
1729 
1730  if (dialect == KLocale::MetricBinaryDialect) {
1731  multiplier = 1000.0;
1732  }
1733 
1734  // If a specific unit conversion is given, use it directly. Otherwise
1735  // search until the result is in [0, multiplier) (or out of our range).
1736  if (specificUnit == KLocale::DefaultBinaryUnits) {
1737  while (qAbs(size) >= multiplier && unit < (int) KLocale::UnitYottaByte) {
1738  size /= multiplier;
1739  unit++;
1740  }
1741  } else {
1742  // A specific unit is in use
1743  unit = static_cast<int>(specificUnit);
1744  if (unit > 0) {
1745  size /= pow(multiplier, unit);
1746  }
1747  }
1748 
1749  if (unit == 0) {
1750  // Bytes, no rounding
1751  return dialectUnits[unit].arg(formatNumber(size, 0));
1752  }
1753 
1754  return dialectUnits[unit].arg(formatNumber(size, precision));
1755 }
1756 
1757 QString KLocalePrivate::formatByteSize(double size)
1758 {
1759  return formatByteSize(size, 1);
1760 }
1761 
1762 KLocale::BinaryUnitDialect KLocalePrivate::binaryUnitDialect() const
1763 {
1764  return m_binaryUnitDialect;
1765 }
1766 
1767 void KLocalePrivate::setBinaryUnitDialect(KLocale::BinaryUnitDialect newDialect)
1768 {
1769  if (newDialect > KLocale::DefaultBinaryDialect && newDialect <= KLocale::LastBinaryDialect) {
1770  QMutexLocker lock(kLocaleMutex());
1771  m_binaryUnitDialect = newDialect;
1772  m_byteSizeFmt.clear(); // Reset cached translations.
1773  }
1774 }
1775 
1776 QString KLocalePrivate::formatDuration(unsigned long mSec) const
1777 {
1778  if (mSec >= 24*3600000) {
1779  return i18nc("@item:intext %1 is a real number, e.g. 1.23 days", "%1 days",
1780  formatNumber(mSec / (24 * 3600000.0), 2));
1781  } else if (mSec >= 3600000) {
1782  return i18nc("@item:intext %1 is a real number, e.g. 1.23 hours", "%1 hours",
1783  formatNumber(mSec / 3600000.0, 2));
1784  } else if (mSec >= 60000) {
1785  return i18nc("@item:intext %1 is a real number, e.g. 1.23 minutes", "%1 minutes",
1786  formatNumber(mSec / 60000.0, 2));
1787  } else if (mSec >= 1000) {
1788  return i18nc("@item:intext %1 is a real number, e.g. 1.23 seconds", "%1 seconds",
1789  formatNumber(mSec / 1000.0, 2));
1790  }
1791  return i18ncp("@item:intext", "%1 millisecond", "%1 milliseconds", mSec);
1792 }
1793 
1794 QString KLocalePrivate::formatSingleDuration(KLocalePrivate::DurationType durationType, int n)
1795 {
1796  switch (durationType) {
1797  case KLocalePrivate::DaysDurationType:
1798  return i18ncp("@item:intext", "1 day", "%1 days", n);
1799  case KLocalePrivate::HoursDurationType:
1800  return i18ncp("@item:intext", "1 hour", "%1 hours", n);
1801  case KLocalePrivate::MinutesDurationType:
1802  return i18ncp("@item:intext", "1 minute", "%1 minutes", n);
1803  case KLocalePrivate::SecondsDurationType:
1804  return i18ncp("@item:intext", "1 second", "%1 seconds", n);
1805  }
1806  return QString();
1807 }
1808 
1809 QString KLocalePrivate::prettyFormatDuration(unsigned long mSec) const
1810 {
1811  unsigned long ms = mSec;
1812  int days = ms / (24 * 3600000);
1813  ms = ms % (24 * 3600000);
1814  int hours = ms / 3600000;
1815  ms = ms % 3600000;
1816  int minutes = ms / 60000;
1817  ms = ms % 60000;
1818  int seconds = qRound(ms / 1000.0);
1819 
1820  // Handle correctly problematic case #1 (look at KLocaleTest::prettyFormatDuration()
1821  // at klocaletest.cpp)
1822  if (seconds == 60) {
1823  return prettyFormatDuration(mSec - ms + 60000);
1824  }
1825 
1826  if (days && hours) {
1827  return i18nc("@item:intext days and hours. This uses the previous item:intext messages. If this does not fit the grammar of your language please contact the i18n team to solve the problem",
1828  "%1 and %2", formatSingleDuration(KLocalePrivate::DaysDurationType, days),
1829  formatSingleDuration(KLocalePrivate::HoursDurationType, hours));
1830  } else if (days) {
1831  return formatSingleDuration(KLocalePrivate::DaysDurationType, days);
1832  } else if (hours && minutes) {
1833  return i18nc("@item:intext hours and minutes. This uses the previous item:intext messages. If this does not fit the grammar of your language please contact the i18n team to solve the problem",
1834  "%1 and %2",
1835  formatSingleDuration(KLocalePrivate::HoursDurationType, hours),
1836  formatSingleDuration(KLocalePrivate::MinutesDurationType, minutes));
1837  } else if (hours) {
1838  return formatSingleDuration(KLocalePrivate::HoursDurationType, hours);
1839  } else if (minutes && seconds) {
1840  return i18nc("@item:intext minutes and seconds. This uses the previous item:intext messages. If this does not fit the grammar of your language please contact the i18n team to solve the problem",
1841  "%1 and %2",
1842  formatSingleDuration(KLocalePrivate::MinutesDurationType, minutes),
1843  formatSingleDuration(KLocalePrivate::SecondsDurationType, seconds));
1844  } else if (minutes) {
1845  return formatSingleDuration(KLocalePrivate::MinutesDurationType, minutes);
1846  } else {
1847  return formatSingleDuration(KLocalePrivate::SecondsDurationType, seconds);
1848  }
1849 }
1850 
1851 QString KLocalePrivate::formatDate(const QDate &date, KLocale::DateFormat format)
1852 {
1853  return calendar()->formatDate(date, format);
1854 }
1855 
1856 void KLocalePrivate::setMainCatalog(const char *catalog)
1857 {
1858  KLocaleStaticData *s = staticData;
1859  s->maincatalog = QString::fromUtf8(catalog);
1860 }
1861 
1862 double KLocalePrivate::readNumber(const QString &_str, bool * ok) const
1863 {
1864  QString str = _str.trimmed();
1865  bool neg = false;
1866 
1867  // Check negative or positive signs
1868  // Assumes blank sign is positive even if pos sign set, unless already taken by negative
1869  if (!negativeSign().isEmpty() && str.indexOf(negativeSign()) == 0) {
1870  neg = true;
1871  str.remove(0, negativeSign().length());
1872  str = str.trimmed();
1873  } else if (!positiveSign().isEmpty() && str.indexOf(positiveSign()) == 0) {
1874  neg = false;
1875  str.remove(0, positiveSign().length());
1876  str = str.trimmed();
1877  } else if (negativeSign().isEmpty() && str[0].isDigit()) {
1878  neg = true;
1879  }
1880 
1881  /* will hold the scientific notation portion of the number.
1882  Example, with 2.34E+23, exponentialPart == "E+23"
1883  */
1884  QString exponentialPart;
1885  int EPos;
1886 
1887  EPos = str.indexOf(QLatin1Char('E'), 0, Qt::CaseInsensitive);
1888 
1889  if (EPos != -1) {
1890  exponentialPart = str.mid(EPos);
1891  str = str.left(EPos);
1892  str = str.trimmed();
1893  }
1894 
1895  // Remove group separators
1896  bool groupOk = true;
1897  if(str.contains(thousandsSeparator())) {
1898  str = parseDigitGroup(str, thousandsSeparator(), decimalSymbol(),
1899  numericDigitGrouping(), &groupOk);
1900  }
1901 
1902  if (!groupOk) {
1903  if (ok) {
1904  *ok = false;
1905  }
1906  return 0.0;
1907  }
1908 
1909  int pos = str.indexOf(decimalSymbol());
1910  QString major;
1911  QString minor;
1912  if (pos == -1) {
1913  major = str;
1914  } else {
1915  major = str.left(pos);
1916  minor = str.mid(pos + decimalSymbol().length());
1917  }
1918 
1919  // Check the major and minor parts are only digits
1920  bool digitTest = true;
1921  foreach (const QChar &ch, major) {
1922  if (!ch.isDigit()) {
1923  digitTest = false;
1924  break;
1925  }
1926  }
1927  foreach (const QChar &ch, minor) {
1928  if (!ch.isDigit()) {
1929  digitTest = false;
1930  break;
1931  }
1932  }
1933  if (!digitTest) {
1934  if (ok) {
1935  *ok = false;
1936  }
1937  return 0.0;
1938  }
1939 
1940  QString tot;
1941  if (neg) {
1942  tot = QLatin1Char('-');
1943  }
1944  tot += major + QLatin1Char('.') + minor + exponentialPart;
1945  tot = toArabicDigits(tot);
1946  return tot.toDouble(ok);
1947 }
1948 
1949 double KLocalePrivate::readMoney(const QString &_str, bool *ok) const
1950 {
1951  QString str = _str.trimmed();
1952  bool neg = false;
1953  bool currencyFound = false;
1954  QString symbol = currencySymbol();
1955 
1956  // First try removing currency symbol from either end
1957  int pos = str.indexOf(symbol);
1958  if (pos == 0 || pos == (int) str.length() - symbol.length()) {
1959  str.remove(pos, symbol.length());
1960  str = str.trimmed();
1961  currencyFound = true;
1962  }
1963  if (str.isEmpty()) {
1964  if (ok) {
1965  *ok = false;
1966  }
1967  return 0;
1968  }
1969 
1970  // Then try removing sign from either end (with a special case for parenthesis)
1971  if (str[0] == QLatin1Char('(') && str[str.length()-1] == QLatin1Char(')')) {
1972  if (positiveMonetarySignPosition() != KLocale::ParensAround) {
1973  neg = true;
1974  }
1975  str.remove(str.length() - 1, 1);
1976  str.remove(0, 1);
1977  str = str.trimmed();
1978  } else {
1979  int len = 0;
1980  QString sign;
1981  int negLen = negativeSign().length();
1982  QString negSign = negativeSign();
1983  if (!negSign.isEmpty() && (str.left(negLen) == negSign || str.right(negSign.length()) == negSign)) {
1984  neg = true;
1985  len = negLen;
1986  sign = negSign;
1987  } else {
1988  int posLen = positiveSign().length();
1989  QString posSign = positiveSign();
1990  if (!posSign.isEmpty() && (str.left(posLen) == posSign || str.right(posSign.length()) == posSign)) {
1991  len = posLen;
1992  sign = posSign;
1993  } else if (negSign.isEmpty() && str[0].isDigit() && str[str.length() - 1].isDigit()){
1994  neg = true;
1995  }
1996  }
1997  if (!sign.isEmpty()) {
1998  if (str.left(len) == sign) {
1999  str.remove(0, len);
2000  } else {
2001  str.remove(str.length() - len, len);
2002  }
2003  str = str.trimmed();
2004  }
2005  }
2006 
2007  // Finally try again for the currency symbol, if we didn't find
2008  // it already (because of the negative sign being in the way).
2009  if (!currencyFound) {
2010  pos = str.indexOf(symbol);
2011  if (pos == 0 || pos == (int) str.length() - symbol.length()) {
2012  str.remove(pos, symbol.length());
2013  str = str.trimmed();
2014  }
2015  }
2016 
2017  // Remove group separators
2018  bool groupOk = true;
2019  if(str.contains(monetaryThousandsSeparator())) {
2020  str = parseDigitGroup(str, monetaryThousandsSeparator(), monetaryDecimalSymbol(),
2021  monetaryDigitGrouping(), &groupOk);
2022  }
2023 
2024  if (!groupOk) {
2025  if (ok) {
2026  *ok = false;
2027  }
2028  return 0.0;
2029  }
2030 
2031  // And parse the rest as a number
2032  pos = str.indexOf(monetaryDecimalSymbol());
2033  QString major;
2034  QString minor;
2035  if (pos == -1) {
2036  major = str;
2037  } else {
2038  major = str.left(pos);
2039  minor = str.mid(pos + monetaryDecimalSymbol().length());
2040  }
2041 
2042  // Check the major and minor parts are only digits
2043  bool digitTest = true;
2044  foreach (const QChar &ch, major) {
2045  if (!ch.isDigit()) {
2046  digitTest = false;
2047  break;
2048  }
2049  }
2050  foreach (const QChar &ch, minor) {
2051  if (!ch.isDigit()) {
2052  digitTest = false;
2053  break;
2054  }
2055  }
2056  if (!digitTest) {
2057  if (ok) {
2058  *ok = false;
2059  }
2060  return 0.0;
2061  }
2062 
2063  QString tot;
2064  if (neg) {
2065  tot = QLatin1Char('-');
2066  }
2067  tot += major + QLatin1Char('.') + minor;
2068  tot = toArabicDigits(tot);
2069  return tot.toDouble(ok);
2070 }
2071 
2078 static int readInt(const QString &str, int &pos)
2079 {
2080  if (!str.at(pos).isDigit()) {
2081  return -1;
2082  }
2083  int result = 0;
2084  for (; str.length() > pos && str.at(pos).isDigit(); ++pos) {
2085  result *= 10;
2086  result += str.at(pos).digitValue();
2087  }
2088 
2089  return result;
2090 }
2091 
2092 QDate KLocalePrivate::readDate(const QString &intstr, bool *ok)
2093 {
2094  return calendar()->readDate(intstr, ok);
2095 }
2096 
2097 QDate KLocalePrivate::readDate(const QString &intstr, KLocale::ReadDateFlags flags, bool *ok)
2098 {
2099  return calendar()->readDate(intstr, flags, ok);
2100 }
2101 
2102 QDate KLocalePrivate::readDate(const QString &intstr, const QString &fmt, bool *ok)
2103 {
2104  return calendar()->readDate(intstr, fmt, ok);
2105 }
2106 
2107 QTime KLocalePrivate::readTime(const QString &intstr, bool *ok) const
2108 {
2109  QTime time = readLocaleTime(intstr, ok, KLocale::TimeDefault, KLocale::ProcessStrict);
2110  if (time.isValid()) {
2111  return time;
2112  }
2113  return readLocaleTime(intstr, ok, KLocale::TimeWithoutSeconds, KLocale::ProcessStrict);
2114 }
2115 
2116 QTime KLocalePrivate::readTime(const QString &intstr, KLocale::ReadTimeFlags flags, bool *ok) const
2117 {
2118  return readLocaleTime(intstr, ok, (flags == KLocale::WithSeconds) ? KLocale::TimeDefault : KLocale::TimeWithoutSeconds,
2119  KLocale::ProcessStrict);
2120 }
2121 
2122 // remove the first occurrence of the 2-character string
2123 // strip2char from inout and if found, also remove one preceding
2124 // punctuation character and arbitrary number of spaces.
2125 static void stripStringAndPreceedingSeparator(QString &inout, const QLatin1String &strip2char)
2126 {
2127  int remPos = inout.indexOf(strip2char);
2128  if (remPos == -1) {
2129  return;
2130  }
2131  int endPos = remPos + 2;
2132  int curPos = remPos - 1;
2133  while (curPos >= 0 && inout.at(curPos).isSpace()) {
2134  curPos--;
2135  }
2136  // remove the separator sign before the seconds
2137  // and assume that works everywhere
2138  if (curPos >= 0 && inout.at(curPos).isPunct() && inout.at(curPos) != QLatin1Char('%')) {
2139  curPos--;
2140  }
2141  while (curPos >= 0 && inout.at(curPos).isSpace()) {
2142  curPos--;
2143  }
2144 
2145  remPos = qMax(curPos + 1, 0);
2146  inout.remove(remPos, endPos - remPos);
2147 }
2148 
2149 // remove the first occurrence of the 2-character string
2150 // strip2char from inout and if found, also remove one
2151 // succeeding punctuation character and arbitrary number of spaces.
2152 static void stripStringAndSucceedingSeparator(QString &inout, const QLatin1String &strip2char)
2153 {
2154  int remPos = inout.indexOf(strip2char);
2155  if (remPos == -1) {
2156  return;
2157  }
2158  int curPos = remPos + 2;
2159  while (curPos < inout.size() &&
2160  (inout.at(curPos).isSpace() ||
2161  (inout.at(curPos).isPunct() && inout.at(curPos) != QLatin1Char('%')))) {
2162  curPos++;
2163  }
2164  inout.remove(remPos, curPos - remPos);
2165 }
2166 
2167 // remove the first occurrence of "%p" from the inout.
2168 static void stripAmPmFormat(QString &inout)
2169 {
2170  // NOTE: this function assumes that %p - if it's present -
2171  // is either the first or the last element of the format
2172  // string. Either a succeeding or a preceding
2173  // punctuation symbol is stripped.
2174  int length = inout.size();
2175  int ppos = inout.indexOf(QLatin1String("%p"));
2176  if (ppos == -1) {
2177  return;
2178  } else if (ppos == 0) {
2179  // first element, eat succeeding punctuation and spaces
2180  ppos = 2;
2181  while (ppos < length && (inout.at(ppos).isSpace() || inout.at(ppos).isPunct()) &&
2182  inout.at(ppos) != QLatin1Char('%')) {
2183  ppos++;
2184  }
2185  inout = inout.mid(ppos);
2186  } else {
2187  stripStringAndPreceedingSeparator(inout, QLatin1String("%p"));
2188  }
2189 }
2190 
2191 QTime KLocalePrivate::readLocaleTime(const QString &intstr, bool *ok, KLocale::TimeFormatOptions options,
2192  KLocale::TimeProcessingOptions processing) const
2193 {
2194  QString str(intstr.simplified().toLower());
2195  QString format(timeFormat().simplified());
2196 
2197  int hour = -1;
2198  int minute = -1;
2199  int second = -1;
2200  bool useDayPeriod = false;
2201  KDayPeriod dayPeriod = dayPeriodForTime(QTime(0,0,0));
2202  int strpos = 0;
2203  int formatpos = 0;
2204  bool error = false;
2205 
2206  bool excludeSecs = ((options & KLocale::TimeWithoutSeconds) == KLocale::TimeWithoutSeconds);
2207  bool isDuration = ((options & KLocale::TimeDuration) == KLocale::TimeDuration);
2208  bool noAmPm = ((options & KLocale::TimeWithoutAmPm) == KLocale::TimeWithoutAmPm);
2209  bool foldHours = ((options & KLocale::TimeFoldHours) == KLocale::TimeFoldHours);
2210  bool strict = ((processing & KLocale::ProcessStrict) == KLocale::ProcessStrict);
2211 
2212  // if seconds aren't needed, strip them from the timeFormat
2213  if (excludeSecs) {
2214  stripStringAndPreceedingSeparator(format, QLatin1String("%S"));
2215  second = 0; // seconds are always 0
2216  }
2217 
2218  // if hours are folded, strip them from the timeFormat
2219  if (foldHours) {
2220  stripStringAndSucceedingSeparator(format, QLatin1String("%H"));
2221  stripStringAndSucceedingSeparator(format, QLatin1String("%k"));
2222  stripStringAndSucceedingSeparator(format, QLatin1String("%I"));
2223  stripStringAndSucceedingSeparator(format, QLatin1String("%l"));
2224  }
2225 
2226  // if am/pm isn't needed, strip it from the timeFormat
2227  if (noAmPm) {
2228  stripAmPmFormat(format);
2229  }
2230 
2231  while (!error && (format.length() > formatpos || str.length() > strpos)) {
2232  if (!(format.length() > formatpos && str.length() > strpos)) {
2233  error = true;
2234  break;
2235  }
2236 
2237  QChar c = format.at(formatpos++);
2238  if (c.isSpace()) {
2239  if (strict) { // strict processing: space is needed
2240  if (!str.at(strpos).isSpace()) {
2241  error = true;
2242  break;
2243  }
2244  strpos++;
2245  } else { // lax processing: space in str not needed
2246  // 1 space maximum as str is simplified
2247  if (str.at(strpos).isSpace()) {
2248  strpos++;
2249  }
2250  }
2251  continue;
2252  }
2253 
2254  if (c != QLatin1Char('%')) {
2255  if (c != str.at(strpos++)) {
2256  error = true;
2257  break;
2258  }
2259  continue;
2260  }
2261 
2262  c = format.at(formatpos++);
2263  switch (c.unicode()) {
2264 
2265  case 'p': // Day Period, normally AM/PM
2266  case 'P': // Lowercase Day Period, normally am/pm
2267  {
2268  error = true;
2269  foreach (const KDayPeriod &testDayPeriod, dayPeriods()) {
2270  QString dayPeriodText = testDayPeriod.periodName(KLocale::ShortName);
2271  int len = dayPeriodText.length();
2272  if (str.mid(strpos, len) == dayPeriodText.toLower()) {
2273  dayPeriod = testDayPeriod;
2274  strpos += len;
2275  error = false;
2276  useDayPeriod = true;
2277  break;
2278  }
2279  }
2280  break;
2281  }
2282 
2283  case 'k': // 24h Hours Short Number
2284  case 'H': // 24h Hours Long Number
2285  useDayPeriod = false;
2286  hour = readInt(str, strpos);
2287  break;
2288 
2289  case 'l': // 12h Hours Short Number
2290  case 'I': // 12h Hours Long Number
2291  useDayPeriod = !isDuration;
2292  hour = readInt(str, strpos);
2293  break;
2294 
2295  case 'M':
2296  minute = readInt(str, strpos);
2297  // minutes can be bigger than 59 if hours are folded
2298  if (foldHours) {
2299  // if hours are folded, make sure minutes doesn't get bigger than 59.
2300  hour = minute / 60;
2301  minute = minute % 60;
2302  }
2303  break;
2304 
2305  case 'S':
2306  second = readInt(str, strpos);
2307  break;
2308  }
2309 
2310  // NOTE: if anything is performed inside this loop, be sure to
2311  // check for error!
2312  }
2313 
2314  QTime returnTime;
2315  if (!error) {
2316  if (useDayPeriod) {
2317  returnTime = dayPeriod.time(hour, minute, second);
2318  } else {
2319  returnTime = QTime(hour, minute, second);
2320  }
2321  }
2322  if (ok) {
2323  *ok = returnTime.isValid();
2324  }
2325  return returnTime;
2326 }
2327 
2328 QString KLocalePrivate::formatTime(const QTime &time, bool includeSecs, bool isDuration) const
2329 {
2330  KLocale::TimeFormatOptions options = KLocale::TimeDefault;
2331  if (!includeSecs) {
2332  options |= KLocale::TimeWithoutSeconds;
2333  }
2334  if (isDuration) {
2335  options |= KLocale::TimeDuration;
2336  }
2337  return formatLocaleTime(time, options);
2338 }
2339 
2340 QString KLocalePrivate::formatLocaleTime(const QTime &time, KLocale::TimeFormatOptions options) const
2341 {
2342  QString rst(timeFormat());
2343 
2344  bool excludeSecs = ((options & KLocale::TimeWithoutSeconds) == KLocale::TimeWithoutSeconds);
2345  bool isDuration = ((options & KLocale::TimeDuration) == KLocale::TimeDuration);
2346  bool noAmPm = ((options & KLocale::TimeWithoutAmPm) == KLocale::TimeWithoutAmPm);
2347  bool foldHours = ((options & KLocale::TimeFoldHours) == KLocale::TimeFoldHours);
2348 
2349  // if seconds aren't needed, strip them from the timeFormat
2350  if (excludeSecs) {
2351  stripStringAndPreceedingSeparator(rst, QLatin1String("%S"));
2352  }
2353 
2354  // if hours should be folded, strip all hour symbols from the timeFormat
2355  if (foldHours) {
2356  stripStringAndSucceedingSeparator(rst, QLatin1String("%H"));
2357  stripStringAndSucceedingSeparator(rst, QLatin1String("%k"));
2358  stripStringAndSucceedingSeparator(rst, QLatin1String("%I"));
2359  stripStringAndSucceedingSeparator(rst, QLatin1String("%l"));
2360  }
2361 
2362  // if am/pm isn't needed, strip it from the timeFormat
2363  if (noAmPm) {
2364  stripAmPmFormat(rst);
2365  }
2366 
2367  // only "pm/am" and %M here can grow, the rest shrinks, but
2368  // I'm rather safe than sorry
2369  QChar *buffer = new QChar[rst.length() * 3 / 2 + 32];
2370 
2371  int index = 0;
2372  bool escape = false;
2373  int number = 0;
2374 
2375  for (int format_index = 0; format_index < rst.length(); format_index++) {
2376  if (!escape) {
2377  if (rst.at(format_index).unicode() == '%') {
2378  escape = true;
2379  } else {
2380  buffer[index++] = rst.at(format_index);
2381  }
2382  } else {
2383  switch (rst.at(format_index).unicode()) {
2384  case '%':
2385  buffer[index++] = QLatin1Char('%');
2386  break;
2387  case 'H':
2388  put_it_in(buffer, index, time.hour());
2389  break;
2390  case 'I':
2391  if (isDuration) {
2392  put_it_in(buffer, index, time.hour());
2393  } else {
2394  put_it_in(buffer, index, dayPeriodForTime(time).hourInPeriod(time));
2395  }
2396  break;
2397  case 'M':
2398  if (foldHours) {
2399  put_it_in(buffer, index, QString::number(time.hour() * 60 + time.minute()));
2400  } else {
2401  put_it_in(buffer, index, time.minute());
2402  }
2403  break;
2404  case 'S':
2405  put_it_in(buffer, index, time.second());
2406  break;
2407  case 'k':
2408  case 'l':
2409  // to share the code
2410  if (!isDuration && rst.at(format_index).unicode() == 'l') {
2411  number = dayPeriodForTime(time).hourInPeriod(time);
2412  } else {
2413  number = time.hour();
2414  }
2415  if (number / 10) {
2416  buffer[index++] = number / 10 + '0';
2417  }
2418  buffer[index++] = number % 10 + '0';
2419  break;
2420  case 'p':
2421  {
2422  put_it_in(buffer, index, dayPeriodForTime(time).periodName(KLocale::ShortName));
2423  break;
2424  }
2425  default:
2426  buffer[index++] = rst.at(format_index);
2427  break;
2428  }
2429  escape = false;
2430  }
2431  }
2432  QString ret(buffer, index);
2433  delete [] buffer;
2434  ret = convertDigits(ret, dateTimeDigitSet());
2435  return ret.trimmed();
2436 }
2437 
2438 bool KLocalePrivate::use12Clock() const
2439 {
2440  if ((timeFormat().contains(QString::fromLatin1("%I")) > 0) ||
2441  (timeFormat().contains(QString::fromLatin1("%l")) > 0)) {
2442  return true;
2443  } else {
2444  return false;
2445  }
2446 }
2447 
2448 void KLocalePrivate::setDayPeriods(const QList<KDayPeriod> &dayPeriods)
2449 {
2450  if (dayPeriods.count() > 0) {
2451  foreach (const KDayPeriod &dayPeriod, dayPeriods) {
2452  if (!dayPeriod.isValid()) {
2453  return;
2454  }
2455  }
2456  m_dayPeriods = dayPeriods;
2457  }
2458 }
2459 
2460 QList<KDayPeriod> KLocalePrivate::dayPeriods() const
2461 {
2462  // If no Day Periods currently loaded then it means there were no country specific ones defined
2463  // in the country l10n file, so default to standard AM/PM translations for the users language.
2464  // Note we couldn't do this in initDayPeriods() as i18n isn't available until we have a
2465  // valid loacle constructed.
2466  if (m_dayPeriods.isEmpty()) {
2467  m_dayPeriods.append(KDayPeriod(QString::fromLatin1("am"),
2468  i18nc( "Before Noon KLocale::LongName", "Ante Meridiem" ),
2469  i18nc( "Before Noon KLocale::ShortName", "AM" ),
2470  i18nc( "Before Noon KLocale::NarrowName", "A" ),
2471  QTime( 0, 0, 0 ), QTime( 11, 59, 59, 999 ), 0, 12 ));
2472  m_dayPeriods.append(KDayPeriod(QString::fromLatin1("pm"),
2473  i18nc( "After Noon KLocale::LongName", "Post Meridiem" ),
2474  i18nc( "After Noon KLocale::ShortName", "PM" ),
2475  i18nc( "After Noon KLocale::NarrowName", "P" ),
2476  QTime( 12, 0, 0 ), QTime( 23, 59, 59, 999 ), 0, 12 ));
2477  }
2478  return m_dayPeriods;
2479 }
2480 
2481 KDayPeriod KLocalePrivate::dayPeriodForTime(const QTime &time) const
2482 {
2483  if (time.isValid()) {
2484  foreach (const KDayPeriod &dayPeriod, dayPeriods()) {
2485  if (dayPeriod.isValid(time)) {
2486  return dayPeriod;
2487  }
2488  }
2489  }
2490  return KDayPeriod();
2491 }
2492 
2493 QStringList KLocalePrivate::languageList() const
2494 {
2495  return m_languageList;
2496 }
2497 
2498 QStringList KLocalePrivate::currencyCodeList() const
2499 {
2500  return m_currencyCodeList;
2501 }
2502 
2503 QString KLocalePrivate::formatDateTime(const KLocale *locale, const QDateTime &dateTime, KLocale::DateFormat format,
2504  bool includeSeconds, int daysTo, int secsTo)
2505 {
2506  // Have to do Fancy Date formatting here rather than using normal KCalendarSystem::formatDate()
2507  // as daysTo is relative to the time spec which formatDate doesn't know about. Needs to be
2508  // kept in sync with Fancy Date code in KCalendarSystem::formatDate(). Fix in KDE5.
2509 
2510  // Only do Fancy if less than an hour into the future or less than a week in the past
2511  if ((daysTo == 0 && secsTo > 3600) || daysTo < 0 || daysTo > 6) {
2512  if (format == KLocale::FancyShortDate) {
2513  format = KLocale::ShortDate;
2514  } else if (format == KLocale::FancyLongDate) {
2515  format = KLocale::LongDate;
2516  }
2517  }
2518 
2519  QString dateStr;
2520  if (format == KLocale::FancyShortDate || format == KLocale::FancyLongDate) {
2521  switch (daysTo) {
2522  case 0:
2523  dateStr = i18n("Today");
2524  break;
2525  case 1:
2526  dateStr = i18n("Yesterday");
2527  break;
2528  default:
2529  dateStr = locale->calendar()->weekDayName(dateTime.date());
2530  }
2531  } else {
2532  dateStr = locale->formatDate(dateTime.date(), format);
2533  }
2534 
2535  KLocale::TimeFormatOption timeFormat;
2536  if (includeSeconds) {
2537  timeFormat = KLocale::TimeDefault;
2538  } else {
2539  timeFormat = KLocale::TimeWithoutSeconds;
2540  }
2541 
2542  return i18nc("concatenation of dates and time", "%1 %2", dateStr,
2543  locale->formatLocaleTime(dateTime.time(), timeFormat));
2544 }
2545 
2546 QString KLocalePrivate::formatDateTime(const QDateTime &dateTime, KLocale::DateFormat format, bool includeSeconds) const
2547 {
2548  QDateTime now = QDateTime::currentDateTime();
2549  int daysTo = dateTime.date().daysTo(now.date());
2550  int secsTo = now.secsTo(dateTime);
2551  return KLocalePrivate::formatDateTime(q, dateTime, format, includeSeconds, daysTo, secsTo);
2552 }
2553 
2554 QString KLocalePrivate::formatDateTime(const KDateTime &dateTime, KLocale::DateFormat format,
2555  KLocale::DateTimeFormatOptions options)
2556 {
2557  QString dt;
2558 
2559  if (dateTime.isDateOnly()) {
2560  dt = formatDate(dateTime.date(), format);
2561  } else {
2562  KDateTime now = KDateTime::currentDateTime(dateTime.timeSpec());
2563  int daysTo = dateTime.date().daysTo(now.date());
2564  int secsTo = now.secsTo(dateTime);
2565  dt = KLocalePrivate::formatDateTime(q, dateTime.dateTime(), format, (options & KLocale::Seconds), daysTo, secsTo);
2566  }
2567 
2568  if (options & KLocale::TimeZone) {
2569  QString tz;
2570  switch (dateTime.timeType()) {
2571  case KDateTime::OffsetFromUTC:
2572  tz = i18n(dateTime.toString(QString::fromLatin1("%z")).toUtf8());
2573  break;
2574  case KDateTime::UTC:
2575  case KDateTime::TimeZone:
2576  tz = i18n(dateTime.toString(QString::fromLatin1((format == KLocale::ShortDate) ? "%Z" : "%:Z")).toUtf8());
2577  break;
2578  case KDateTime::ClockTime:
2579  default:
2580  break;
2581  }
2582  return i18nc("concatenation of date/time and time zone", "%1 %2", dt, tz);
2583  }
2584 
2585  return dt;
2586 }
2587 
2588 QString KLocalePrivate::langLookup(const QString &fname, const char *rtype)
2589 {
2590  QStringList search;
2591 
2592  // assemble the local search paths
2593  const QStringList localDoc = KGlobal::dirs()->resourceDirs(rtype);
2594 
2595  // look up the different languages
2596  for (int id = localDoc.count() - 1; id >= 0; --id) {
2597  QStringList langs = KGlobal::locale()->languageList();
2598  // FIXME: KDE 4.5, change such that English is not assumed.
2599  langs.replaceInStrings(QLatin1String("en_US"), QLatin1String("en"));
2600  langs.append(QLatin1String("en"));
2601  Q_FOREACH(const QString &lang, langs)
2602  search.append(QString::fromLatin1("%1%2/%3").arg(localDoc[id]).arg(lang).arg(fname));
2603  }
2604 
2605  // try to locate the file
2606  Q_FOREACH(const QString &file, search) {
2607  kDebug(173) << "Looking for help in: " << file;
2608 
2609  QFileInfo info(file);
2610  if (info.exists() && info.isFile() && info.isReadable())
2611  return file;
2612  }
2613 
2614  return QString();
2615 }
2616 
2617 bool KLocalePrivate::useDefaultLanguage() const
2618 {
2619  return language() == KLocale::defaultLanguage();
2620 }
2621 
2622 void KLocalePrivate::initEncoding()
2623 {
2624  m_codecForEncoding = 0;
2625 
2626  // This all made more sense when we still had the EncodingEnum config key.
2627 
2628  QByteArray codeset = systemCodeset();
2629 
2630  if (!codeset.isEmpty()) {
2631  QTextCodec* codec = QTextCodec::codecForName(codeset);
2632  if (codec) {
2633  setEncoding(codec->mibEnum());
2634  }
2635  } else {
2636  setEncoding(QTextCodec::codecForLocale()->mibEnum());
2637  }
2638 
2639  if (!m_codecForEncoding) {
2640  kWarning() << "Cannot resolve system encoding, defaulting to ISO 8859-1.";
2641  const int mibDefault = 4; // ISO 8859-1
2642  setEncoding(mibDefault);
2643  }
2644 
2645  Q_ASSERT(m_codecForEncoding);
2646 }
2647 
2648 QByteArray KLocalePrivate::systemCodeset() const
2649 {
2650  QByteArray codeset;
2651 #if HAVE_LANGINFO_H
2652  // Qt since 4.2 always returns 'System' as codecForLocale and KDE (for example
2653  // KEncodingFileDialog) expects real encoding name. So on systems that have langinfo.h use
2654  // nl_langinfo instead, just like Qt compiled without iconv does. Windows already has its own
2655  // workaround
2656 
2657  codeset = nl_langinfo(CODESET);
2658 
2659  if ((codeset == "ANSI_X3.4-1968") || (codeset == "US-ASCII")) {
2660  // means ascii, "C"; QTextCodec doesn't know, so avoid warning
2661  codeset = "ISO-8859-1";
2662  }
2663 #endif
2664  return codeset;
2665 }
2666 
2667 void KLocalePrivate::initFileNameEncoding()
2668 {
2669  // If the following environment variable is set, assume all filenames
2670  // are in UTF-8 regardless of the current C locale.
2671  m_utf8FileEncoding = !qgetenv("KDE_UTF8_FILENAMES").isEmpty();
2672  if (m_utf8FileEncoding) {
2673  QFile::setEncodingFunction(KLocalePrivate::encodeFileNameUTF8);
2674  QFile::setDecodingFunction(KLocalePrivate::decodeFileNameUTF8);
2675  }
2676  // Otherwise, stay with QFile's default filename encoding functions
2677  // which, on Unix platforms, use the locale's codec.
2678 }
2679 
2680 QByteArray KLocalePrivate::encodeFileNameUTF8(const QString & fileName)
2681 {
2682  return fileName.toUtf8();
2683 }
2684 
2685 QString KLocalePrivate::decodeFileNameUTF8(const QByteArray &localFileName)
2686 {
2687  return QString::fromUtf8(localFileName);
2688 }
2689 
2690 void KLocalePrivate::setDateFormat(const QString &format)
2691 {
2692  m_dateFormat = format.trimmed();
2693 }
2694 
2695 void KLocalePrivate::setDateFormatShort(const QString &format)
2696 {
2697  m_dateFormatShort = format.trimmed();
2698 }
2699 
2700 void KLocalePrivate::setDateMonthNamePossessive(bool possessive)
2701 {
2702  m_dateMonthNamePossessive = possessive;
2703 }
2704 
2705 void KLocalePrivate::setTimeFormat(const QString &format)
2706 {
2707  m_timeFormat = format.trimmed();
2708 }
2709 
2710 void KLocalePrivate::setWeekStartDay(int day)
2711 {
2712  if (day >= 1 && day <= calendar()->daysInWeek(QDate())) {
2713  m_weekStartDay = day;
2714  }
2715 }
2716 
2717 void KLocalePrivate::setWorkingWeekStartDay(int day)
2718 {
2719  if (day >= 1 && day <= calendar()->daysInWeek(QDate())) {
2720  m_workingWeekStartDay = day;
2721  }
2722 }
2723 
2724 void KLocalePrivate::setWorkingWeekEndDay(int day)
2725 {
2726  if (day >= 1 && day <= calendar()->daysInWeek(QDate())) {
2727  m_workingWeekEndDay = day;
2728  }
2729 }
2730 
2731 void KLocalePrivate::setWeekDayOfPray(int day)
2732 {
2733  if (day >= 0 && day <= calendar()->daysInWeek(QDate())) { // 0 = None
2734  m_weekDayOfPray = day;
2735  }
2736 }
2737 
2738 QString KLocalePrivate::dateFormat() const
2739 {
2740  return m_dateFormat;
2741 }
2742 
2743 QString KLocalePrivate::dateFormatShort() const
2744 {
2745  return m_dateFormatShort;
2746 }
2747 
2748 QString KLocalePrivate::timeFormat() const
2749 {
2750  return m_timeFormat;
2751 }
2752 
2753 void KLocalePrivate::setDecimalPlaces(int digits)
2754 {
2755  m_decimalPlaces = digits;
2756 }
2757 
2758 void KLocalePrivate::setDecimalSymbol(const QString &symbol)
2759 {
2760  m_decimalSymbol = symbol.trimmed();
2761 }
2762 
2763 void KLocalePrivate::setThousandsSeparator(const QString &separator)
2764 {
2765  // allow spaces here
2766  m_thousandsSeparator = separator;
2767 }
2768 
2769 void KLocalePrivate::setNumericDigitGrouping(QList<int> groupList)
2770 {
2771  m_numericDigitGrouping = groupList;
2772 }
2773 
2774 void KLocalePrivate::setPositiveSign(const QString &sign)
2775 {
2776  m_positiveSign = sign.trimmed();
2777 }
2778 
2779 void KLocalePrivate::setNegativeSign(const QString &sign)
2780 {
2781  m_negativeSign = sign.trimmed();
2782 }
2783 
2784 void KLocalePrivate::setPositiveMonetarySignPosition(KLocale::SignPosition signpos)
2785 {
2786  m_positiveMonetarySignPosition = signpos;
2787 }
2788 
2789 void KLocalePrivate::setNegativeMonetarySignPosition(KLocale::SignPosition signpos)
2790 {
2791  m_negativeMonetarySignPosition = signpos;
2792 }
2793 
2794 void KLocalePrivate::setPositivePrefixCurrencySymbol(bool prefix)
2795 {
2796  m_positivePrefixCurrencySymbol = prefix;
2797 }
2798 
2799 void KLocalePrivate::setNegativePrefixCurrencySymbol(bool prefix)
2800 {
2801  m_negativePrefixCurrencySymbol = prefix;
2802 }
2803 
2804 void KLocalePrivate::setMonetaryDecimalPlaces(int digits)
2805 {
2806  m_monetaryDecimalPlaces = digits;
2807 }
2808 
2809 void KLocalePrivate::setMonetaryThousandsSeparator(const QString &separator)
2810 {
2811  // allow spaces here
2812  m_monetaryThousandsSeparator = separator;
2813 }
2814 
2815 void KLocalePrivate::setMonetaryDigitGrouping(QList<int> groupList)
2816 {
2817  m_monetaryDigitGrouping = groupList;
2818 }
2819 
2820 void KLocalePrivate::setMonetaryDecimalSymbol(const QString &symbol)
2821 {
2822  m_monetaryDecimalSymbol = symbol.trimmed();
2823 }
2824 
2825 void KLocalePrivate::setCurrencySymbol(const QString & symbol)
2826 {
2827  m_currencySymbol = symbol.trimmed();
2828 }
2829 
2830 int KLocalePrivate::pageSize() const
2831 {
2832  return m_pageSize;
2833 }
2834 
2835 void KLocalePrivate::setPageSize(int size)
2836 {
2837  // #### check if it's in range??
2838  m_pageSize = size;
2839 }
2840 
2841 KLocale::MeasureSystem KLocalePrivate::measureSystem() const
2842 {
2843  return m_measureSystem;
2844 }
2845 
2846 void KLocalePrivate::setMeasureSystem(KLocale::MeasureSystem value)
2847 {
2848  m_measureSystem = value;
2849 }
2850 
2851 QString KLocalePrivate::defaultLanguage()
2852 {
2853  static const QString en_US = QString::fromLatin1("en_US");
2854  return en_US;
2855 }
2856 
2857 QString KLocalePrivate::defaultCountry()
2858 {
2859  return QString::fromLatin1("C");
2860 }
2861 
2862 QString KLocalePrivate::defaultCurrencyCode()
2863 {
2864  return QString::fromLatin1("USD");
2865 }
2866 
2867 bool KLocalePrivate::useTranscript() const
2868 {
2869  return m_useTranscript;
2870 }
2871 
2872 const QByteArray KLocalePrivate::encoding()
2873 {
2874  return codecForEncoding()->name();
2875 }
2876 
2877 int KLocalePrivate::encodingMib() const
2878 {
2879  return codecForEncoding()->mibEnum();
2880 }
2881 
2882 int KLocalePrivate::fileEncodingMib() const
2883 {
2884  if (m_utf8FileEncoding) {
2885  return 106;
2886  }
2887  return codecForEncoding()->mibEnum();
2888 }
2889 
2890 QTextCodec *KLocalePrivate::codecForEncoding() const
2891 {
2892  return m_codecForEncoding;
2893 }
2894 
2895 bool KLocalePrivate::setEncoding(int mibEnum)
2896 {
2897  QTextCodec * codec = QTextCodec::codecForMib(mibEnum);
2898  if (codec) {
2899  m_codecForEncoding = codec;
2900  }
2901 
2902  return codec != 0;
2903 }
2904 
2905 QStringList KLocalePrivate::allLanguagesList()
2906 {
2907  if (!m_languages) {
2908  m_languages = new KConfig(QLatin1String("all_languages"), KConfig::NoGlobals, "locale");
2909  }
2910  return m_languages->groupList();
2911 }
2912 
2913 QStringList KLocalePrivate::installedLanguages()
2914 {
2915  QStringList languages;
2916  QStringList paths = KGlobal::dirs()->findAllResources("locale", QLatin1String("*/entry.desktop"));
2917  foreach (const QString &path, paths) {
2918  QString part = path.left(path.length() - 14);
2919  languages.append(part.mid(part.lastIndexOf(QLatin1Char('/')) + 1));
2920  }
2921  languages.sort();
2922  return languages;
2923 }
2924 
2925 QString KLocalePrivate::languageCodeToName(const QString &language)
2926 {
2927  if (!m_languages) {
2928  m_languages = new KConfig(QLatin1String("all_languages"), KConfig::NoGlobals, "locale");
2929  }
2930 
2931  KConfigGroup cg(m_languages, language);
2932  return cg.readEntry("Name");
2933 }
2934 
2935 QStringList KLocalePrivate::allCountriesList() const
2936 {
2937  QStringList countries;
2938  const QStringList paths = KGlobal::dirs()->findAllResources("locale", QLatin1String("l10n/*/entry.desktop"));
2939  for (QStringList::ConstIterator it = paths.begin(); it != paths.end(); ++it) {
2940  QString code = (*it).mid((*it).length() - 16, 2);
2941  if (code != QLatin1String("/C")) {
2942  countries.append(code);
2943  }
2944  }
2945  return countries;
2946 }
2947 
2948 QString KLocalePrivate::countryCodeToName(const QString &country) const
2949 {
2950  QString countryName;
2951  QString entryFile = KStandardDirs::locate("locale", QString::fromLatin1("l10n/") + country.toLower() + QLatin1String("/entry.desktop"));
2952  if (!entryFile.isEmpty()) {
2953  KConfig cfg(entryFile);
2954  KConfigGroup cg(&cfg, "KCM Locale");
2955  countryName = cg.readEntry("Name");
2956  }
2957  return countryName;
2958 }
2959 
2960 KLocale::CalendarSystem KLocalePrivate::calendarTypeToCalendarSystem(const QString &calendarType) const
2961 {
2962  if (calendarType == QLatin1String("coptic")) {
2963  return KLocale::CopticCalendar;
2964  } else if (calendarType == QLatin1String("ethiopian")) {
2965  return KLocale::EthiopianCalendar;
2966  } else if (calendarType == QLatin1String("gregorian")) {
2967  return KLocale::QDateCalendar;
2968  } else if (calendarType == QLatin1String("gregorian-proleptic")) {
2969  return KLocale::GregorianCalendar;
2970  } else if (calendarType == QLatin1String("hebrew")) {
2971  return KLocale::HebrewCalendar;
2972  } else if (calendarType == QLatin1String("hijri")) {
2973  return KLocale::IslamicCivilCalendar;
2974  } else if (calendarType == QLatin1String("indian-national")) {
2975  return KLocale::IndianNationalCalendar;
2976  } else if (calendarType == QLatin1String("jalali")) {
2977  return KLocale::JalaliCalendar;
2978  } else if (calendarType == QLatin1String("japanese")) {
2979  return KLocale::JapaneseCalendar;
2980  } else if (calendarType == QLatin1String("julian")) {
2981  return KLocale::JulianCalendar;
2982  } else if (calendarType == QLatin1String("minguo")) {
2983  return KLocale::MinguoCalendar;
2984  } else if (calendarType == QLatin1String("thai")) {
2985  return KLocale::ThaiCalendar;
2986  } else {
2987  return KLocale::QDateCalendar;
2988  }
2989 }
2990 
2991 QString KLocalePrivate::calendarSystemToCalendarType(KLocale::CalendarSystem calendarSystem) const
2992 {
2993  switch (calendarSystem) {
2994  case KLocale::QDateCalendar:
2995  return QLatin1String("gregorian");
2996  case KLocale::CopticCalendar:
2997  return QLatin1String("coptic");
2998  case KLocale::EthiopianCalendar:
2999  return QLatin1String("ethiopian");
3000  case KLocale::GregorianCalendar:
3001  return QLatin1String("gregorian-proleptic");
3002  case KLocale::HebrewCalendar:
3003  return QLatin1String("hebrew");
3004  case KLocale::IslamicCivilCalendar:
3005  return QLatin1String("hijri");
3006  case KLocale::IndianNationalCalendar:
3007  return QLatin1String("indian-national");
3008  case KLocale::JalaliCalendar:
3009  return QLatin1String("jalali");
3010  case KLocale::JapaneseCalendar:
3011  return QLatin1String("japanese");
3012  case KLocale::JulianCalendar:
3013  return QLatin1String("julian");
3014  case KLocale::MinguoCalendar:
3015  return QLatin1String("minguo");
3016  case KLocale::ThaiCalendar:
3017  return QLatin1String("thai");
3018  default:
3019  return QLatin1String("gregorian");
3020  }
3021 }
3022 
3023 void KLocalePrivate::setCalendar(const QString &calendarType)
3024 {
3025  setCalendarSystem(calendarTypeToCalendarSystem(calendarType));
3026 }
3027 
3028 void KLocalePrivate::setCalendarSystem(KLocale::CalendarSystem calendarSystem)
3029 {
3030  m_calendarSystem = calendarSystem;
3031  delete m_calendar;
3032  m_calendar = 0;
3033 }
3034 
3035 QString KLocalePrivate::calendarType() const
3036 {
3037  return calendarSystemToCalendarType(m_calendarSystem);
3038 }
3039 
3040 KLocale::CalendarSystem KLocalePrivate::calendarSystem() const
3041 {
3042  return m_calendarSystem;
3043 }
3044 
3045 const KCalendarSystem * KLocalePrivate::calendar()
3046 {
3047  if (!m_calendar) {
3048  m_calendar = KCalendarSystem::create(m_calendarSystem, m_config, q);
3049  }
3050 
3051  return m_calendar;
3052 }
3053 
3054 void KLocalePrivate::setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem)
3055 {
3056  m_weekNumberSystem = weekNumberSystem;
3057 }
3058 
3059 KLocale::WeekNumberSystem KLocalePrivate::weekNumberSystem()
3060 {
3061  return m_weekNumberSystem;
3062 }
3063 
3064 void KLocalePrivate::copyCatalogsTo(KLocale *locale)
3065 {
3066  QMutexLocker lock(kLocaleMutex());
3067  locale->d->m_catalogNames = m_catalogNames;
3068  locale->d->updateCatalogs();
3069 }
3070 
3071 QString KLocalePrivate::localizedFilePath(const QString &filePath) const
3072 {
3073  // Stop here if the default language is primary.
3074  if (useDefaultLanguage()) {
3075  return filePath;
3076  }
3077 
3078  // Check if l10n sudir is present, stop if not.
3079  QFileInfo fileInfo(filePath);
3080  QString locDirPath = fileInfo.path() + QLatin1String("/l10n");
3081  QFileInfo locDirInfo(locDirPath);
3082  if (!locDirInfo.isDir()) {
3083  return filePath;
3084  }
3085 
3086  // Go through possible localized paths by priority of languages,
3087  // return first that exists.
3088  QString fileName = fileInfo.fileName();
3089  foreach(const QString &lang, languageList()) {
3090  // Stop when the default language is reached.
3091  if (lang == KLocale::defaultLanguage()) {
3092  return filePath;
3093  }
3094  QString locFilePath = locDirPath + QLatin1Char('/') + lang + QLatin1Char('/') + fileName;
3095  QFileInfo locFileInfo(locFilePath);
3096  if (locFileInfo.isFile() && locFileInfo.isReadable()) {
3097  return locFilePath;
3098  }
3099  }
3100 
3101  return filePath;
3102 }
3103 
3104 QString KLocalePrivate::removeAcceleratorMarker(const QString &label) const
3105 {
3106  return ::removeAcceleratorMarker(label);
3107 }
3108 
3109 void KLocalePrivate::setDigitSet(KLocale::DigitSet digitSet)
3110 {
3111  m_digitSet = digitSet;
3112 }
3113 
3114 KLocale::DigitSet KLocalePrivate::digitSet() const
3115 {
3116  return m_digitSet;
3117 }
3118 
3119 void KLocalePrivate::setMonetaryDigitSet(KLocale::DigitSet digitSet)
3120 {
3121  m_monetaryDigitSet = digitSet;
3122 }
3123 
3124 KLocale::DigitSet KLocalePrivate::monetaryDigitSet() const
3125 {
3126  return m_monetaryDigitSet;
3127 }
3128 
3129 void KLocalePrivate::setDateTimeDigitSet(KLocale::DigitSet digitSet)
3130 {
3131  m_dateTimeDigitSet = digitSet;
3132 }
3133 
3134 KLocale::DigitSet KLocalePrivate::dateTimeDigitSet() const
3135 {
3136  return m_dateTimeDigitSet;
3137 }
3138 
3139 Q_GLOBAL_STATIC_WITH_ARGS(QMutex, s_kLocaleMutex, (QMutex::Recursive))
3140 
3141 QMutex *kLocaleMutex()
3142 {
3143  return s_kLocaleMutex();
3144 }
KDayPeriod::periodName
QString periodName(KLocale::DateTimeComponentFormat format=KLocale::ShortName) const
Return translated Period Name in the required format e.g.
Definition: kdayperiod.cpp:138
KLocale::TimeZone
Include a time zone string.
Definition: klocale.h:968
KLocale::AfterMoney
Suffix the currency symbol with the sign, e.g.
Definition: klocale.h:301
i18n
QString i18n(const char *text)
Returns a localized version of a string.
Definition: klocalizedstring.h:630
KLocalePrivate::setPositiveMonetarySignPosition
virtual void setPositiveMonetarySignPosition(KLocale::SignPosition signpos)
Definition: klocale_kde.cpp:2784
KSharedPtr< KSharedConfig >
KConfig::sync
void sync()
Definition: kconfig.cpp:414
KLocalePrivate::currencyCode
virtual QString currencyCode() const
Definition: klocale_kde.cpp:806
read3ConfigBoolEntry
#define read3ConfigBoolEntry(key, default, save)
KLocale::TimeFoldHours
Read/format time string as duration.
Definition: klocale.h:1030
KLocalePrivate::setEncoding
virtual bool setEncoding(int mibEnum)
Definition: klocale_kde.cpp:2895
KLocale::EthiopianCalendar
Ethiopian Calendar, aka Ethiopic Calendar.
Definition: klocale.h:786
KLocalizedString::notifyCatalogsUpdated
static void notifyCatalogsUpdated(const QStringList &languages, const QList< KCatalogName > &catalogs)
Definition: klocalizedstring.cpp:974
KSharedConfig
KConfig variant using shared memory.
Definition: ksharedconfig.h:40
KLocalePrivate::prettyFormatDuration
virtual QString prettyFormatDuration(unsigned long mSec) const
Definition: klocale_kde.cpp:1809
KLocalePrivate::monetaryDigitGrouping
virtual QList< int > monetaryDigitGrouping() const
Definition: klocale_kde.cpp:1246
stripAmPmFormat
static void stripAmPmFormat(QString &inout)
Definition: klocale_kde.cpp:2168
KLocale::ParensAround
Put parantheses around the quantity, e.g.
Definition: klocale.h:285
KLocalePrivate::formatNumber
virtual QString formatNumber(double num, int precision=-1) const
Definition: klocale_kde.cpp:1455
kdebug.h
KSharedPtr::data
T * data()
Definition: ksharedptr.h:111
KLocalePrivate::thousandsSeparator
virtual QString thousandsSeparator() const
Definition: klocale_kde.cpp:1221
kdatetime.h
Date/times with associated time zone.
KLocale::JapaneseCalendar
Japanese Calendar, Gregorian calculation using Japanese Era (Nengô)
Definition: klocale.h:799
KLocale::WithSeconds
Only accept a time string with seconds. Default (no flag set)
Definition: klocale.h:1298
KLocalePrivate::setDateTimeDigitSet
virtual void setDateTimeDigitSet(KLocale::DigitSet digitSet)
Definition: klocale_kde.cpp:3129
KLocalePrivate::systemCodeset
virtual QByteArray systemCodeset() const
Definition: klocale_kde.cpp:2648
KLocale::defaultCurrencyCode
static QString defaultCurrencyCode()
Definition: klocale.cpp:625
KLocalePrivate::readNumber
virtual double readNumber(const QString &numStr, bool *ok=0) const
Definition: klocale_kde.cpp:1862
KLocale::LastBinaryDialect
Definition: klocale.h:661
KLocalePrivate::formatSingleDuration
static QString formatSingleDuration(KLocalePrivate::DurationType durationType, int n)
Definition: klocale_kde.cpp:1794
KCatalog::catalogLocaleDir
static QString catalogLocaleDir(const QString &name, const QString &language)
Finds the locale directory for the given catalog in given language.
Definition: kcatalog.cpp:149
put_it_in
static void put_it_in(QChar *buffer, int &index, const QString &s)
Definition: klocale_kde.cpp:1293
KLocalePrivate::setWorkingWeekStartDay
virtual void setWorkingWeekStartDay(int day)
Definition: klocale_kde.cpp:2717
KLocalePrivate::setDateMonthNamePossessive
virtual void setDateMonthNamePossessive(bool possessive)
Definition: klocale_kde.cpp:2700
KLocalePrivate::dateMonthNamePossessive
virtual bool dateMonthNamePossessive() const
Definition: klocale_kde.cpp:1186
KLocale::ProcessStrict
Process time in a strict manner, ie.
Definition: klocale.h:1326
KLocalePrivate::monetaryThousandsSeparator
virtual QString monetaryThousandsSeparator() const
Definition: klocale_kde.cpp:1241
KLocalePrivate::workingWeekEndDay
virtual int workingWeekEndDay() const
Definition: klocale_kde.cpp:1201
KLocalePrivate::monetaryDigitSet
virtual KLocale::DigitSet monetaryDigitSet() const
Definition: klocale_kde.cpp:3124
KLocalePrivate::measureSystem
virtual KLocale::MeasureSystem measureSystem() const
Definition: klocale_kde.cpp:2841
KLocalePrivate::init
virtual void init(const QString &catalogName, const QString &language, const QString &country, KSharedConfig::Ptr persistantconfig, KConfig *tempConfig)
Definition: klocale_kde.cpp:228
KDateTime::timeSpec
Spec timeSpec() const
Returns the time specification of the date/time, i.e.
Definition: kdatetime.cpp:842
KLocalePrivate::countryDivisionCode
QString countryDivisionCode() const
Definition: klocale_kde.cpp:789
KLocale::MeasureSystem
MeasureSystem
The Metric system will give you information in mm, while the Imperial system will give you informatio...
Definition: klocale.h:1780
KLocale::TamilDigits
௦௧௨௩௪௫௬௭௮ (Tamil)
Definition: klocale.h:322
KLocalePrivate::useTranscript
virtual bool useTranscript() const
Definition: klocale_kde.cpp:2867
KLocalePrivate::monetaryDecimalSymbol
virtual QString monetaryDecimalSymbol() const
Definition: klocale_kde.cpp:1236
readConfigEntry
#define readConfigEntry(key, default, save)
KLocalePrivate::setCountryDivisionCode
bool setCountryDivisionCode(const QString &countryDivision)
Definition: klocale_kde.cpp:628
K_GLOBAL_STATIC
#define K_GLOBAL_STATIC(TYPE, NAME)
This macro makes it easy to use non-POD types as global statics.
Definition: kglobal.h:221
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
This function is just for convenience.
Definition: kstandarddirs.cpp:2104
KLocalePrivate::initMainCatalogs
virtual void initMainCatalogs()
Definition: klocale_kde.cpp:295
kconfig.h
KLocale::ShortDate
Locale Short date format, e.g.
Definition: klocale.h:923
KLocalePrivate::calendarTypeToCalendarSystem
virtual KLocale::CalendarSystem calendarTypeToCalendarSystem(const QString &calendarType) const
Definition: klocale_kde.cpp:2960
KDayPeriod::time
QTime time(int hourInPeriod, int minute, int second, int millisecond=0) const
Calculate and return the 24hr time for a given hms in the Day Period.
Definition: kdayperiod.cpp:161
KLocalePrivate::toArabicDigits
static QString toArabicDigits(const QString &str)
Definition: klocale_kde.cpp:1168
KGlobal::dirs
KStandardDirs * dirs()
Returns the application standard dirs object.
stripStringAndSucceedingSeparator
static void stripStringAndSucceedingSeparator(QString &inout, const QLatin1String &strip2char)
Definition: klocale_kde.cpp:2152
KDayPeriod::hourInPeriod
int hourInPeriod(const QTime &time) const
Calculate and return the hour in the Day Period for a given 24h time.
Definition: kdayperiod.cpp:149
KLocalePrivate::copy
virtual void copy(const KLocalePrivate &rhs)
Definition: klocale_kde.cpp:138
KLocale::DateFormat
DateFormat
Format for date string.
Definition: klocale.h:922
KLocale::formatLocaleTime
QString formatLocaleTime(const QTime &pTime, TimeFormatOptions options=KLocale::TimeDefault) const
Definition: klocale.cpp:424
klocale_p.h
KLocalePrivate::localizedFilePath
virtual QString localizedFilePath(const QString &filePath) const
Definition: klocale_kde.cpp:3071
KLocale::GurmukhiDigits
੦੧੨੩੪੫੬੭੮੯ (Punjabi)
Definition: klocale.h:317
KLocalePrivate::splitLocale
static void splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, QString &charset)
Definition: klocale_kde.cpp:741
KLocalePrivate::allDigitSetsList
virtual QList< KLocale::DigitSet > allDigitSetsList() const
Definition: klocale_kde.cpp:1033
KConfigBase::group
KConfigGroup group(const QByteArray &group)
Returns an object for the named subgroup.
Definition: kconfigbase.cpp:44
KDateTime::toString
QString toString(const QString &format) const
Returns the date/time as a string.
Definition: kdatetime.cpp:1434
KLocalePrivate::calendarSystemToCalendarType
virtual QString calendarSystemToCalendarType(KLocale::CalendarSystem) const
Definition: klocale_kde.cpp:2991
KLocalePrivate::decimalPlaces
virtual int decimalPlaces() const
Definition: klocale_kde.cpp:1211
KConfigGroup::writeEntry
void writeEntry(const QString &key, const QVariant &value, WriteConfigFlags pFlags=Normal)
Writes a value to the configuration object.
Definition: kconfiggroup.cpp:1038
KLocale::BeforeMoney
Prefix the currency symbol with the sign, e.g.
Definition: klocale.h:297
KLocale::AfterQuantityMoney
Suffix the quanitity with the sign, e.g.
Definition: klocale.h:293
KLocale::CopticCalendar
Coptic Calendar as used Coptic Church and some parts of Egypt.
Definition: klocale.h:785
kcalendarsystem.h
KLocalePrivate::langLookup
static QString langLookup(const QString &fname, const char *rtype="html")
Definition: klocale_kde.cpp:2588
KDateTime::isDateOnly
bool isDateOnly() const
Returns whether the instance represents a date/time or a date-only value.
Definition: kdatetime.cpp:832
KCatalogName
Definition: kcatalogname_p.h:25
KLocale::IECBinaryDialect
KDE Default, KiB, MiB, etc. 2^(10*n)
Definition: klocale.h:658
QString
KLocale::ThaiDigits
๐๑๒๓๔๕๖๗๘๙ (Thai)
Definition: klocale.h:324
_round
static void _round(QString &str, int precision)
Definition: klocale_kde.cpp:1514
QHash< KLocale::DigitSet, QStringList >
KLocalePrivate::~KLocalePrivate
virtual ~KLocalePrivate()
Destructor.
Definition: klocale_kde.cpp:219
KLocalePrivate::SecondsDurationType
Definition: klocale_p.h:982
removeAcceleratorMarker
QString removeAcceleratorMarker(const QString &label_)
Definition: common_helpers.cpp:52
KLocalePrivate::removeCatalog
virtual void removeCatalog(const QString &catalog)
Definition: klocale_kde.cpp:860
KLocale::HebrewCalendar
Hebrew Calendar, aka Jewish Calendar.
Definition: klocale.h:789
KLocalePrivate::convertDigits
virtual QString convertDigits(const QString &str, KLocale::DigitSet digitSet, bool ignoreContext=false) const
Definition: klocale_kde.cpp:1144
common_helpers_p.h
KLocale::BinarySizeUnits
BinarySizeUnits
These binary units are used in KDE by the formatByteSize() functions.
Definition: klocale.h:621
KLocalePrivate::dateFormatShort
virtual QString dateFormatShort() const
Definition: klocale_kde.cpp:2743
KLocalePrivate::initFileNameEncoding
virtual void initFileNameEncoding()
Definition: klocale_kde.cpp:2667
KLocalePrivate::setWorkingWeekEndDay
virtual void setWorkingWeekEndDay(int day)
Definition: klocale_kde.cpp:2724
KCatalogName::name
QString name
Definition: kcatalogname_p.h:28
KLocale::MalayalamDigits
൦൧൨൩൪൫൬൭൮൯ (Malayalam)
Definition: klocale.h:320
KLocalePrivate::digitSetToName
virtual QString digitSetToName(KLocale::DigitSet digitSet, bool withDigits=false) const
Definition: klocale_kde.cpp:1088
KCalendarSystem::create
static KCalendarSystem * create(const QString &calType=QLatin1String("gregorian"), const KLocale *locale=0)
Definition: kcalendarsystem.cpp:47
KLocalePrivate::initConfig
virtual void initConfig(KConfig *config)
Definition: klocale_kde.cpp:270
KLocalePrivate::encodeFileNameUTF8
static QByteArray encodeFileNameUTF8(const QString &fileName)
Definition: klocale_kde.cpp:2680
KLocale::TimeDuration
Read/format time string as duration.
Definition: klocale.h:1025
prefix
QString prefix()
Definition: kstandarddirs_win.cpp:28
KCalendarSystem
KCalendarSystem abstract base class, provides support for local Calendar Systems in KDE...
Definition: kcalendarsystem.h:40
i18nc
QString i18nc(const char *ctxt, const char *text)
Returns a localized version of a string and a context.
Definition: klocalizedstring.h:797
KLocalePrivate::setPositivePrefixCurrencySymbol
virtual void setPositivePrefixCurrencySymbol(bool prefix)
Definition: klocale_kde.cpp:2794
KGlobal::config
KSharedConfigPtr config()
Returns the general config object.
Definition: kglobal.cpp:138
KLocalePrivate::installedLanguages
virtual QStringList installedLanguages()
Definition: klocale_kde.cpp:2913
KLocalePrivate::config
KConfig * config()
Definition: klocale_kde.cpp:129
KLocalePrivate::setCalendarSystem
virtual void setCalendarSystem(KLocale::CalendarSystem)
Definition: klocale_kde.cpp:3028
KLocalePrivate::DurationType
DurationType
Definition: klocale_p.h:978
KLocalePrivate::formatByteSize
virtual QString formatByteSize(double size)
Definition: klocale_kde.cpp:1757
KLocalePrivate::initDayPeriods
virtual void initDayPeriods(const KConfigGroup &cg)
Definition: klocale_kde.cpp:567
KConfigGroup::deleteEntry
void deleteEntry(const QString &pKey, WriteConfigFlags pFlags=Normal)
Deletes the entry specified by pKey in the current group.
Definition: kconfiggroup.cpp:1113
KLocale::IndianNationalCalendar
Indian National Calendar, not the Lunar Calendar.
Definition: klocale.h:794
KLocale::JEDECBinaryDialect
KDE 3.5 default, KB, MB, etc. 2^(10*n)
Definition: klocale.h:659
KCurrencyCode
Definition: kcurrencycode.h:45
readConfigNumEntry
#define readConfigNumEntry(key, default, save, type)
kglobal.h
KLocale::calendar
const KCalendarSystem * calendar() const
Returns a pointer to the calendar system object.
Definition: klocale.cpp:705
KConfig::copyTo
KConfig * copyTo(const QString &file, KConfig *config=0) const
Copies all entries from this config object to a new config object that will save itself to file...
Definition: kconfig.cpp:512
KLocale::DefaultBinaryUnits
Auto-choose a unit such that the result is in the range [0, 1000 or 1024)
Definition: klocale.h:623
KLocalePrivate::setMainCatalog
static void setMainCatalog(const char *catalog)
Definition: klocale_kde.cpp:1856
I18N_NOOP2_NOSTRIP
#define I18N_NOOP2_NOSTRIP(ctxt, text)
Definition: klocalizedstring.h:102
KLocalePrivate::setCalendar
virtual void setCalendar(const QString &calendarType)
Definition: klocale_kde.cpp:3023
KLocalePrivate::numericDigitGrouping
virtual QList< int > numericDigitGrouping() const
Definition: klocale_kde.cpp:1226
KLocale::ReadTimeFlags
ReadTimeFlags
Flags for the old version of readTime()
Definition: klocale.h:1297
KLocalePrivate::setMonetaryDecimalPlaces
virtual void setMonetaryDecimalPlaces(int digits)
Definition: klocale_kde.cpp:2804
KLocalePrivate::translateQt
virtual QString translateQt(const char *context, const char *sourceText, const char *comment) const
Definition: klocale_kde.cpp:972
KLocale::CalendarSystem
CalendarSystem
Definition: klocale.h:780
KLocalePrivate::language
virtual QString language() const
Definition: klocale_kde.cpp:779
KConfig::NoGlobals
Cascade to system settings, but omit user&#39;s globals.
Definition: kconfig.h:98
KLocalePrivate::formatLong
virtual QString formatLong(long num) const
Definition: klocale_kde.cpp:1464
KLocalePrivate::currencyCodeList
virtual QStringList currencyCodeList() const
Definition: klocale_kde.cpp:2498
KLocalePrivate::initCurrency
virtual void initCurrency()
Definition: klocale_kde.cpp:698
KLocalePrivate::setMonetaryDigitSet
virtual void setMonetaryDigitSet(KLocale::DigitSet digitSet)
Definition: klocale_kde.cpp:3119
KLocale::MinguoCalendar
Minguo Calendar, aka ROC, Republic of China or Taiwanese.
Definition: klocale.h:802
KConfig::setLocale
bool setLocale(const QString &aLocale)
Sets the locale to aLocale.
Definition: kconfig.cpp:719
KLocale::IsoWeekNumber
ISO Week Number.
Definition: klocale.h:817
KCalendarSystem::formatDate
virtual QString formatDate(const QDate &fromDate, KLocale::DateFormat toFormat=KLocale::LongDate) const
Returns a string formatted to the current locale&#39;s conventions regarding dates.
Definition: kcalendarsystem.cpp:2048
KLocalePrivate::setActiveCatalog
virtual void setActiveCatalog(const QString &catalog)
Sets the active catalog for translation lookup.
Definition: klocale_kde.cpp:877
i18ncp
QString i18ncp(const char *ctxt, const char *sing, const char *plur, const A1 &a1)
Returns a localized version of a string with 1 argument and a context using correct plural form...
Definition: klocalizedstring.h:1123
KLocale::JalaliCalendar
Jalali Calendar, aka Persian or Iranian, also used in Afghanistan.
Definition: klocale.h:796
KConfig::groupList
QStringList groupList() const
Definition: kconfig.cpp:291
KLocalePrivate::setNegativeSign
virtual void setNegativeSign(const QString &sign)
Definition: klocale_kde.cpp:2779
QStringList
KLocalePrivate::DaysDurationType
Definition: klocale_p.h:979
KLocalePrivate::allLanguagesList
virtual QStringList allLanguagesList()
Definition: klocale_kde.cpp:2905
KLocalePrivate::readTime
virtual QTime readTime(const QString &str, bool *ok=0) const
Definition: klocale_kde.cpp:2107
KLocalePrivate::pageSize
virtual int pageSize() const
Definition: klocale_kde.cpp:2830
KLocalePrivate::setCountry
virtual bool setCountry(const QString &country, KConfig *config)
Definition: klocale_kde.cpp:592
KLocalePrivate::currency
virtual KCurrencyCode * currency()
Definition: klocale_kde.cpp:798
KDateTime::date
QDate date() const
Returns the date part of the date/time.
Definition: kdatetime.cpp:838
KLocale::UnitYottaByte
YiB/YB/YB 2^80/10^24 bytes.
Definition: klocale.h:634
KDateTime::dateTime
QDateTime dateTime() const
Returns the date/time component of the instance, ignoring the time zone.
Definition: kdatetime.cpp:840
KLocalePrivate::weekDayOfPray
virtual int weekDayOfPray() const
Definition: klocale_kde.cpp:1206
KLocale::WeekNumberSystem
WeekNumberSystem
Definition: klocale.h:815
KLocale::MetricBinaryDialect
SI Units, kB, MB, etc. 10^(3*n)
Definition: klocale.h:660
KLocale::QDateCalendar
KDE Default, hybrid of Gregorian and Julian as used by QDate.
Definition: klocale.h:781
KLocale::TimeWithoutAmPm
Read/format time string without am/pm suffix but keep the 12/24h format as specified by locale time f...
Definition: klocale.h:1021
KLocalePrivate::defaultLanguage
static QString defaultLanguage()
Definition: klocale_kde.cpp:2851
KLocalePrivate::readMoney
virtual double readMoney(const QString &numStr, bool *ok=0) const
Definition: klocale_kde.cpp:1949
KLocalePrivate::dayPeriods
virtual QList< KDayPeriod > dayPeriods() const
Definition: klocale_kde.cpp:2460
KLocalePrivate::setTimeFormat
virtual void setTimeFormat(const QString &format)
Definition: klocale_kde.cpp:2705
KSharedConfig::Ptr
KSharedPtr< KSharedConfig > Ptr
Definition: ksharedconfig.h:43
KLocale::OriyaDigits
୦୧୨୩୪୫୬୭୮୯ (Oriya)
Definition: klocale.h:321
KLocalePrivate::operator=
KLocalePrivate & operator=(const KLocalePrivate &rhs)
Assignment operator.
Definition: klocale_kde.cpp:123
KDateTime::ClockTime
a clock time which ignores time zones and simply uses whatever the local system clock says the time i...
Definition: kdatetime.h:203
KLocalePrivate::setWeekNumberSystem
void setWeekNumberSystem(KLocale::WeekNumberSystem weekNumberSystem)
Definition: klocale_kde.cpp:3054
KLocalePrivate::HoursDurationType
Definition: klocale_p.h:980
KDateTime::secsTo
int secsTo(const KDateTime &other) const
Returns the number of seconds from this date/time to the other date/time.
Definition: kdatetime.cpp:1159
KLocalePrivate::readLocaleTime
virtual QTime readLocaleTime(const QString &str, bool *ok=0, KLocale::TimeFormatOptions options=KLocale::TimeDefault, KLocale::TimeProcessingOptions processing=KLocale::ProcessNonStrict) const
Definition: klocale_kde.cpp:2191
KLocalePrivate::formatTime
virtual QString formatTime(const QTime &pTime, bool includeSecs=false, bool isDuration=false) const
Definition: klocale_kde.cpp:2328
KLocale::ReadDateFlags
ReadDateFlags
Flags for readDate()
Definition: klocale.h:1249
KLocalePrivate::digitSetString
static QString digitSetString(KLocale::DigitSet digitSet)
Definition: klocale_kde.cpp:1054
KLocalePrivate::setDecimalSymbol
virtual void setDecimalSymbol(const QString &symbol)
Definition: klocale_kde.cpp:2758
KLocalePrivate::copyCatalogsTo
virtual void copyCatalogsTo(KLocale *locale)
Definition: klocale_kde.cpp:3064
KLocale::TeluguDigits
౦౧౨౩౪౫౬౭౯ (Telugu)
Definition: klocale.h:323
KLocalePrivate::encoding
virtual const QByteArray encoding()
Definition: klocale_kde.cpp:2872
KLocalePrivate::setMeasureSystem
virtual void setMeasureSystem(KLocale::MeasureSystem value)
Definition: klocale_kde.cpp:2846
KLocalePrivate::positiveMonetarySignPosition
virtual KLocale::SignPosition positiveMonetarySignPosition() const
Definition: klocale_kde.cpp:1283
KLocale::GregorianCalendar
Gregorian Calendar, pure proleptic implementation.
Definition: klocale.h:788
KLocalePrivate::setMonetaryDigitGrouping
virtual void setMonetaryDigitGrouping(QList< int > groupList)
Definition: klocale_kde.cpp:2815
KLocale::BengaliDigits
০১২৩৪৫৬৭৮৯ (Bengali and Assamese)
Definition: klocale.h:315
KLocalePrivate::systemLanguageList
virtual QStringList systemLanguageList() const
Definition: klocale_kde.cpp:446
KDateTime::currentDateTime
static KDateTime currentDateTime(const Spec &spec)
Returns the current date and time, as reported by the system clock, expressed in a given time specifi...
Definition: kdatetime.cpp:1262
KLocalePrivate::negativeMonetarySignPosition
virtual KLocale::SignPosition negativeMonetarySignPosition() const
Definition: klocale_kde.cpp:1288
KLocalePrivate::country
virtual QString country() const
Definition: klocale_kde.cpp:784
KLocalePrivate::formatLocaleTime
virtual QString formatLocaleTime(const QTime &pTime, KLocale::TimeFormatOptions options=KLocale::TimeDefault) const
Definition: klocale_kde.cpp:2340
KLocalePrivate::languageCodeToName
virtual QString languageCodeToName(const QString &language)
Definition: klocale_kde.cpp:2925
KLocalePrivate::initLanguageList
virtual void initLanguageList(const QString &language, const QString &configLanguages, bool useEnv)
Definition: klocale_kde.cpp:401
KLocalePrivate::digitSet
virtual KLocale::DigitSet digitSet() const
Definition: klocale_kde.cpp:3114
KLocalePrivate::dateFormat
virtual QString dateFormat() const
Definition: klocale_kde.cpp:2738
KLocalePrivate::setLanguage
virtual bool setLanguage(const QString &language, KConfig *config)
Definition: klocale_kde.cpp:634
KLocalePrivate::readDate
virtual QDate readDate(const QString &str, bool *ok=0)
Definition: klocale_kde.cpp:2092
KLocalePrivate::systemCountry
virtual QString systemCountry() const
Definition: klocale_kde.cpp:392
KLocalePrivate::updateCatalogs
virtual void updateCatalogs()
Definition: klocale_kde.cpp:826
KCurrencyCode::decimalPlaces
int decimalPlaces() const
Return the number of decimal places required to display the currency subunits.
Definition: kcurrencycode.cpp:256
KDateTime
A class representing a date and time with an associated time zone.
Definition: kdatetime.h:171
KLocalePrivate::dialectUnitsList
QList< QString > dialectUnitsList(KLocale::BinaryUnitDialect dialect)
Definition: klocale_kde.cpp:1619
readInt
static int readInt(const QString &str, int &pos)
helper function to read integers
Definition: klocale_kde.cpp:2078
kWarning
#define kWarning
Definition: kdebug.h:322
KStandardDirs::resourceDirs
QStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
Definition: kstandarddirs.cpp:1063
KLocale::DefaultBinaryDialect
Used if no specific preference.
Definition: klocale.h:657
KConfigGroup::hasKey
bool hasKey(const QString &key) const
Checks whether the key has an entry in this group.
Definition: kconfiggroup.cpp:1156
kcatalog_p.h
KLocalePrivate::q
KLocale * q
Definition: klocale_p.h:1150
KLocale::ShortName
Short text format, e.g.
Definition: klocale.h:914
KLocalePrivate::KLocalePrivate
KLocalePrivate(KLocale *q_ptr)
Constructors.
Definition: klocale_kde.cpp:105
KLocalePrivate::setNumericDigitGrouping
virtual void setNumericDigitGrouping(QList< int > groupList)
Definition: klocale_kde.cpp:2769
KGlobal::locale
KLocale * locale()
Returns the global locale object.
Definition: kglobal.cpp:169
QDateTime
KLocale::TimeDefault
Default formatting using seconds and the format as specified by the locale.
Definition: klocale.h:1018
KConfigGroup
A class for one specific group in a KConfig object.
Definition: kconfiggroup.h:53
KLocalePrivate::weekStartDay
virtual int weekStartDay() const
Definition: klocale_kde.cpp:1191
KLocalePrivate::setDigitSet
virtual void setDigitSet(KLocale::DigitSet digitSet)
Definition: klocale_kde.cpp:3109
KCurrencyCode::isoCurrencyCode
QString isoCurrencyCode() const
Return the ISO 4217 Currency Code in Alpha 3 format, e.g.
Definition: kcurrencycode.cpp:167
KLocalePrivate::setCurrencyCode
virtual void setCurrencyCode(const QString &newCurrencyCode)
Definition: klocale_kde.cpp:710
kcatalogname_p.h
CACHE_BYTE_FMT
#define CACHE_BYTE_FMT(ctxt_text)
KLocalePrivate::getLanguagesFromVariable
static void getLanguagesFromVariable(QStringList &list, const char *variable, bool isLanguageList=false)
Definition: klocale_kde.cpp:328
KDateTime::OffsetFromUTC
a local time which has a fixed offset from UTC.
Definition: kdatetime.h:185
KConfig
The central class of the KDE configuration data system.
Definition: kconfig.h:70
KLocalePrivate::setCurrencySymbol
virtual void setCurrencySymbol(const QString &symbol)
Definition: klocale_kde.cpp:2825
KLocale::languageList
QStringList languageList() const
Returns the language codes selected by user, ordered by decreasing priority.
Definition: klocale.cpp:439
KLocalePrivate::setDayPeriods
virtual void setDayPeriods(const QList< KDayPeriod > &dayPeriods)
Definition: klocale_kde.cpp:2448
KLocalePrivate::setMonetaryThousandsSeparator
virtual void setMonetaryThousandsSeparator(const QString &separator)
Definition: klocale_kde.cpp:2809
KConfigGroup::config
KConfig * config()
Return the config object that this group belongs to.
Definition: kconfiggroup.cpp:610
kdayperiod_p.h
KLocale::FancyShortDate
Same as ShortDate for dates a week or more ago.
Definition: klocale.h:925
KCalendarSystem::readDate
virtual QDate readDate(const QString &str, bool *ok=0) const
Converts a localized date string to a QDate.
Definition: kcalendarsystem.cpp:2333
KLocalePrivate::negativePrefixCurrencySymbol
virtual bool negativePrefixCurrencySymbol() const
Definition: klocale_kde.cpp:1278
KLocalePrivate::initFormat
virtual void initFormat()
Reads the format configuration from disk.
Definition: klocale_kde.cpp:451
stripStringAndPreceedingSeparator
static void stripStringAndPreceedingSeparator(QString &inout, const QLatin1String &strip2char)
Definition: klocale_kde.cpp:2125
KDateTime::UTC
a UTC time.
Definition: kdatetime.h:184
KConfig::markAsClean
void markAsClean()
Definition: kconfig.cpp:484
KLocale
KLocale provides support for country specific stuff like the national language.
Definition: klocale.h:69
KLocalePrivate::defaultCurrencyCode
static QString defaultCurrencyCode()
Definition: klocale_kde.cpp:2862
KCurrencyCode::isValid
bool isValid() const
Return if the currency object loaded/initialised correctly.
Definition: kcurrencycode.cpp:266
kLocaleMutex
QMutex * kLocaleMutex()
Definition: klocale_kde.cpp:3141
KLocalePrivate::formatDuration
virtual QString formatDuration(unsigned long mSec) const
Definition: klocale_kde.cpp:1776
KLocalePrivate::calendar
virtual const KCalendarSystem * calendar()
Definition: klocale_kde.cpp:3045
klocalizedstring.h
KLocalePrivate::setDateFormat
virtual void setDateFormat(const QString &format)
Definition: klocale_kde.cpp:2690
KLocale::SignPosition
SignPosition
Various positions for where to place the positive or negative sign when they are related to a monetar...
Definition: klocale.h:281
Q_GLOBAL_STATIC_WITH_ARGS
Q_GLOBAL_STATIC_WITH_ARGS(org::kde::KLauncher, klauncherIface,(QString::fromLatin1("org.kde.klauncher"), QString::fromLatin1("/KLauncher"), QDBusConnection::sessionBus())) org
Definition: ktoolinvocation.cpp:55
KLocalePrivate::insertCatalog
virtual void insertCatalog(const QString &catalog)
Definition: klocale_kde.cpp:811
kstandarddirs.h
KLocalePrivate::nounDeclension
virtual bool nounDeclension() const
Definition: klocale_kde.cpp:1181
KLocalePrivate::translateRawFrom
virtual void translateRawFrom(const char *catname, const char *msgctxt, const char *msgid, const char *msgid_plural=0, unsigned long n=0, QString *language=0, QString *translation=0) const
Definition: klocale_kde.cpp:889
KLocalePrivate::setNegativeMonetarySignPosition
virtual void setNegativeMonetarySignPosition(KLocale::SignPosition signpos)
Definition: klocale_kde.cpp:2789
KLocalePrivate::setPageSize
virtual void setPageSize(int paperFormat)
Definition: klocale_kde.cpp:2835
KLocale::EasternArabicIndicDigits
۰۱۲۳۴۵۶۷۸۹ (Persian and Urdu)
Definition: klocale.h:313
KLocalePrivate::positiveSign
virtual QString positiveSign() const
Definition: klocale_kde.cpp:1251
KLocalePrivate::negativeSign
virtual QString negativeSign() const
Definition: klocale_kde.cpp:1256
KLocale::TimeFormatOption
TimeFormatOption
Definition: klocale.h:1017
KLocalePrivate::setThousandsSeparator
virtual void setThousandsSeparator(const QString &separator)
Definition: klocale_kde.cpp:2763
KLocalePrivate::formatDateTime
static QString formatDateTime(const KLocale *locale, const QDateTime &dateTime, KLocale::DateFormat, bool includeSeconds, int daysToNow, int secsToNow)
Definition: klocale_kde.cpp:2503
KGlobal::hasMainComponent
bool hasMainComponent()
Definition: kglobal.cpp:150
KLocalePrivate::decimalSymbol
virtual QString decimalSymbol() const
Definition: klocale_kde.cpp:1216
KLocalePrivate::useDefaultLanguage
virtual bool useDefaultLanguage() const
Definition: klocale_kde.cpp:2617
KLocale::UnitLastUnit
Definition: klocale.h:635
KLocale::KannadaDigits
೦೧೨೩೪೫೬೭೮೯ (Kannada)
Definition: klocale.h:318
KDayPeriod
Definition: kdayperiod_p.h:54
KCatalog
This class abstracts a gettext message catalog.
Definition: kcatalog_p.h:35
KLocalePrivate::setDecimalPlaces
virtual void setDecimalPlaces(int digits)
Definition: klocale_kde.cpp:2753
KLocale::BeforeQuantityMoney
Prefix the quantity with the sign, e.g.
Definition: klocale.h:289
KLocale::formatDate
QString formatDate(const QDate &date, DateFormat format=LongDate) const
Returns a string formatted to the current locale&#39;s conventions regarding dates.
Definition: klocale.cpp:368
kDebug
#define kDebug
Definition: kdebug.h:316
KLocale::Seconds
Include the seconds value.
Definition: klocale.h:969
KLocale::LongDate
Locale Long date format, e.g.
Definition: klocale.h:924
KLocale::BinaryUnitDialect
BinaryUnitDialect
This enum chooses what dialect is used for binary units.
Definition: klocale.h:656
KLocalePrivate::setPositiveSign
virtual void setPositiveSign(const QString &sign)
Definition: klocale_kde.cpp:2774
KLocalePrivate::calendarSystem
KLocale::CalendarSystem calendarSystem() const
Definition: klocale_kde.cpp:3040
KLocalePrivate::encodingMib
virtual int encodingMib() const
Definition: klocale_kde.cpp:2877
KLocalePrivate::binaryUnitDialect
virtual KLocale::BinaryUnitDialect binaryUnitDialect() const
Definition: klocale_kde.cpp:1762
KLocalePrivate::use12Clock
virtual bool use12Clock() const
Definition: klocale_kde.cpp:2438
KLocalePrivate::allCountriesList
virtual QStringList allCountriesList() const
Definition: klocale_kde.cpp:2935
KLocale::DigitSet
DigitSet
Definition: klocale.h:309
kcurrencycode.h
KStandardDirs::findAllResources
QStringList findAllResources(const char *type, const QString &filter=QString(), SearchOptions options=NoSearchOptions) const
Tries to find all resources with the specified type.
Definition: kstandarddirs.cpp:894
KLocalePrivate::countryCodeToName
virtual QString countryCodeToName(const QString &country) const
Definition: klocale_kde.cpp:2948
KLocalePrivate::dayPeriodForTime
virtual KDayPeriod dayPeriodForTime(const QTime &time) const
Definition: klocale_kde.cpp:2481
KLocalePrivate::calendarType
virtual QString calendarType() const
Definition: klocale_kde.cpp:3035
KLocalePrivate::decodeFileNameUTF8
static QString decodeFileNameUTF8(const QByteArray &localFileName)
Definition: klocale_kde.cpp:2685
KLocalePrivate::formatDate
virtual QString formatDate(const QDate &date, KLocale::DateFormat format=KLocale::LongDate)
Definition: klocale_kde.cpp:1851
KLocalePrivate::setMonetaryDecimalSymbol
virtual void setMonetaryDecimalSymbol(const QString &symbol)
Definition: klocale_kde.cpp:2820
KLocale::FancyLongDate
Same as LongDate for dates a week or more ago.
Definition: klocale.h:928
kcomponentdata.h
KSharedConfig::openConfig
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, const char *resourceType="config")
Creates a KSharedConfig object to manipulate a configuration file.
Definition: ksharedconfig.cpp:31
KDayPeriod::isValid
bool isValid() const
Return if the Day Period is valid.
Definition: kdayperiod.cpp:186
KLocalePrivate::MinutesDurationType
Definition: klocale_p.h:981
KLocale::splitLocale
static void splitLocale(const QString &locale, QString &language, QString &country, QString &modifier, QString &charset)
Parses locale string into distinct parts.
Definition: klocale.cpp:105
KLocale::ArabicDigits
0123456789 (European and some Asian languages and western Arabic dialects)
Definition: klocale.h:310
KLocalePrivate
Definition: klocale_p.h:34
KLocalePrivate::formatMoney
virtual QString formatMoney(double num, const QString &currency=QString(), int precision=-1) const
Definition: klocale_kde.cpp:1391
KLocale::Metric
Metric system (used e.g. in Europe)
Definition: klocale.h:1781
KLocale::KhmerDigits
០១២៣៤៥៦៧៨៩ (Khmer)
Definition: klocale.h:319
KLocale::ThaiCalendar
Thai Calendar, aka Buddhist or Thai Buddhist.
Definition: klocale.h:803
KConfigGroup::readEntry
T readEntry(const QString &key, const T &aDefault) const
Reads the value of an entry specified by pKey in the current group.
Definition: kconfiggroup.h:248
KLocalePrivate::workingWeekStartDay
virtual int workingWeekStartDay() const
Definition: klocale_kde.cpp:1196
KLocale::GujaratiDigits
૦૧૨૩૪૫૬૭૮૯ (Gujarati)
Definition: klocale.h:316
KLocale::ArabicIndicDigits
٠١٢٣٤٥٦٧٨٩ (eastern Arabic dialects)
Definition: klocale.h:312
KLocale::JulianCalendar
Julian Calendar, as used in Orthodox Churches.
Definition: klocale.h:801
KLocalePrivate::defaultCountry
static QString defaultCountry()
Definition: klocale_kde.cpp:2857
KLocale::DevenagariDigits
०१२३४५६७८९ (Hindi)
Definition: klocale.h:314
KDateTime::timeType
SpecType timeType() const
Returns the time specification type of the date/time, i.e.
Definition: kdatetime.cpp:843
KLocalePrivate::timeFormat
virtual QString timeFormat() const
Definition: klocale_kde.cpp:2748
KLocalePrivate::monetaryDecimalPlaces
virtual int monetaryDecimalPlaces() const
Definition: klocale_kde.cpp:1268
KLocalePrivate::setWeekDayOfPray
virtual void setWeekDayOfPray(int day)
Definition: klocale_kde.cpp:2731
KLocalePrivate::setNegativePrefixCurrencySymbol
virtual void setNegativePrefixCurrencySymbol(bool prefix)
Definition: klocale_kde.cpp:2799
KLocalePrivate::positivePrefixCurrencySymbol
virtual bool positivePrefixCurrencySymbol() const
Definition: klocale_kde.cpp:1273
KCalendarSystem::weekDayName
virtual QString weekDayName(int weekDay, WeekDayNameFormat format=LongDayName) const =0
Gets specific calendar type week day name.
Definition: kcalendarsystem.cpp:1881
KLocalePrivate::languageList
virtual QStringList languageList() const
Definition: klocale_kde.cpp:2493
KLocalePrivate::initCountry
virtual void initCountry(const QString &country, const QString &configCountry)
Definition: klocale_kde.cpp:358
KLocalePrivate::currencySymbol
virtual QString currencySymbol() const
Definition: klocale_kde.cpp:1231
KCurrencyCode::defaultSymbol
QString defaultSymbol() const
Return the default Symbol for the Currency, e.g.
Definition: kcurrencycode.cpp:218
KLocalePrivate::setDateFormatShort
virtual void setDateFormatShort(const QString &format)
Definition: klocale_kde.cpp:2695
KLocalePrivate::setWeekStartDay
virtual void setWeekStartDay(int day)
Definition: klocale_kde.cpp:2710
KLocalePrivate::dateTimeDigitSet
virtual KLocale::DigitSet dateTimeDigitSet() const
Definition: klocale_kde.cpp:3134
KLocalePrivate::isApplicationTranslatedInto
virtual bool isApplicationTranslatedInto(const QString &language)
Definition: klocale_kde.cpp:719
KLocale::defaultLanguage
static QString defaultLanguage()
Returns the name of the internal language.
Definition: klocale.cpp:615
KLocale::IslamicCivilCalendar
Islamic Civil Calendar, aka Hijri, not the Lunar Calendar.
Definition: klocale.h:792
kconfiggroup.h
KLocalePrivate::codecForEncoding
virtual QTextCodec * codecForEncoding() const
Definition: klocale_kde.cpp:2890
KDateTime::TimeZone
a time in a specified time zone.
Definition: kdatetime.h:186
QList< KCatalog >
KLocalePrivate::fileEncodingMib
virtual int fileEncodingMib() const
Definition: klocale_kde.cpp:2882
KLocalePrivate::removeAcceleratorMarker
virtual QString removeAcceleratorMarker(const QString &label) const
Definition: klocale_kde.cpp:3104
KLocalePrivate::weekNumberSystem
KLocale::WeekNumberSystem weekNumberSystem()
Definition: klocale_kde.cpp:3059
KLocalePrivate::setBinaryUnitDialect
virtual void setBinaryUnitDialect(KLocale::BinaryUnitDialect newDialect)
Definition: klocale_kde.cpp:1767
_inc_by_one
static void _inc_by_one(QString &str, int position)
Definition: klocale_kde.cpp:1470
KLocale::TimeWithoutSeconds
Exclude the seconds part of the time from display.
Definition: klocale.h:1020
KLocalePrivate::initEncoding
virtual void initEncoding()
Definition: klocale_kde.cpp:2622
This file is part of the KDE documentation.
Documentation copyright © 1996-2017 The KDE developers.
Generated on Sat Feb 25 2017 06:44:26 by doxygen 1.8.5 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.10.5 API Reference

Skip menu "kdelibs-4.10.5 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal