• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdelocale.cpp
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 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #include <config.h>
24 
25 #include <stdlib.h> // getenv
26 
27 #include <tqtextcodec.h>
28 #include <tqfile.h>
29 #include <tqprinter.h>
30 #include <tqdatetime.h>
31 #include <tqfileinfo.h>
32 #include <tqregexp.h>
33 
34 #include "kcatalogue.h"
35 #include "tdeglobal.h"
36 #include "kstandarddirs.h"
37 #include "ksimpleconfig.h"
38 #include "kinstance.h"
39 #include "tdeconfig.h"
40 #include "kdebug.h"
41 #include "kcalendarsystem.h"
42 #include "kcalendarsystemfactory.h"
43 #include "tdelocale.h"
44 
45 #ifdef Q_WS_WIN
46 #include <windows.h>
47 #endif
48 
49 static const char * const SYSTEM_MESSAGES = "tdelibs";
50 
51 static const char *maincatalogue = 0;
52 
53 class TDELocalePrivate
54 {
55 public:
56  int weekStartDay;
57  bool nounDeclension;
58  bool dateMonthNamePossessive;
59  TQStringList languageList;
60  TQStringList catalogNames; // list of all catalogs (regardless of language)
61  TQValueList<KCatalogue> catalogues; // list of all loaded catalogs, contains one instance per catalog name and language
62  TQString encoding;
63  TQTextCodec * codecForEncoding;
64  TDEConfig * config;
65  bool formatInited;
66  int /*TQPrinter::PageSize*/ pageSize;
67  TDELocale::MeasureSystem measureSystem;
68  TQStringList langTwoAlpha;
69  TDEConfig *languages;
70 
71  TQString calendarType;
72  KCalendarSystem * calendar;
73  bool utf8FileEncoding;
74  TQString appName;
75 #ifdef Q_WS_WIN
76  char win32SystemEncoding[3+7]; //"cp " + lang ID
77 #endif
78  bool useMainCatalogue;
79 };
80 
81 static TDELocale *this_klocale = 0;
82 
83 TDELocale::TDELocale( const TQString & catalog, TDEConfig * config )
84 {
85  d = new TDELocalePrivate;
86  d->config = config;
87  d->languages = 0;
88  d->calendar = 0;
89  d->formatInited = false;
90 
91  initEncoding(0);
92  initFileNameEncoding(0);
93 
94  TDEConfig *cfg = d->config;
95  this_klocale = this;
96  if (!cfg) cfg = TDEGlobal::instance()->config();
97  this_klocale = 0;
98  Q_ASSERT( cfg );
99 
100  d->appName = catalog;
101  initLanguageList( cfg, config == 0);
102  initMainCatalogues(catalog);
103 }
104 
105 TQString TDELocale::_initLanguage(TDEConfigBase *config)
106 {
107  if (this_klocale)
108  {
109  // ### HPB Why this cast??
110  this_klocale->initLanguageList((TDEConfig *) config, true);
111  // todo: adapt current catalog list: remove unused languages, insert main catalogs, if not already found
112  return this_klocale->language();
113  }
114  return TQString::null;
115 }
116 
117 void TDELocale::initMainCatalogues(const TQString & catalog)
118 {
119  // Use the first non-null string.
120  TQString mainCatalogue = catalog;
121 
122  // don't use main catalogue if we're looking up .desktop translations
123  if (mainCatalogue.contains("desktop") == 0 || mainCatalogue.contains("kdesktop") == 1) {
124  if (maincatalogue) {
125  mainCatalogue = TQString::fromLatin1(maincatalogue);
126  }
127  }
128 
129  if (mainCatalogue.isEmpty()) {
130  kdDebug(173) << "TDELocale instance created called without valid "
131  << "catalog! Give an argument or call setMainCatalogue "
132  << "before init" << endl;
133  }
134  else {
135  // do not use insertCatalogue here, that would already trigger updateCatalogs
136  d->catalogNames.append( mainCatalogue ); // application catalog
137  if (mainCatalogue.contains("desktop") == 0 || mainCatalogue.contains("kdesktop") == 1) { //don't bother if we're looking up desktop translations
138  d->catalogNames.append( SYSTEM_MESSAGES ); // always include tdelibs.mo
139  d->catalogNames.append( "tdeio" ); // always include tdeio.mo
140  d->catalogNames.append( "xdg-user-dirs" );
141  }
142  updateCatalogues(); // evaluate this for all languages
143  }
144 }
145 
146 void TDELocale::initLanguageList(TDEConfig * config, bool useEnv)
147 {
148  TDEConfigGroupSaver saver(config, "Locale");
149 
150  m_country = config->readEntry( "Country" );
151  if ( m_country.isEmpty() )
152  m_country = defaultCountry();
153 
154  // Reset the list and add the new languages
155  TQStringList languageList;
156  if ( useEnv )
157  languageList += TQStringList::split
158  (':', TQFile::decodeName( ::getenv("TDE_LANG") ));
159 
160  languageList += config->readListEntry("Language", ':');
161 
162  // same order as setlocale use
163  if ( useEnv )
164  {
165  // HPB: Only run splitLocale on the environment variables..
166  TQStringList langs;
167 
168  langs << TQFile::decodeName( ::getenv("LC_ALL") );
169  langs << TQFile::decodeName( ::getenv("LC_MESSAGES") );
170  langs << TQFile::decodeName( ::getenv("LANG") );
171 
172  for ( TQStringList::Iterator it = langs.begin();
173  it != langs.end();
174  ++it )
175  {
176  TQString ln, ct, chrset;
177  splitLocale(*it, ln, ct, chrset);
178 
179  if (!ct.isEmpty()) {
180  langs.insert(it, ln + '_' + ct);
181  if (!chrset.isEmpty())
182  langs.insert(it, ln + '_' + ct + '.' + chrset);
183  }
184 
185  langs.insert(it, ln);
186  }
187 
188  languageList += langs;
189  }
190 
191  // now we have a language list -- let's use the first OK language
192  setLanguage( languageList );
193 }
194 
195 void TDELocale::initPluralTypes()
196 {
197  for ( TQValueList<KCatalogue>::Iterator it = d->catalogues.begin();
198  it != d->catalogues.end();
199  ++it )
200  {
201  TQString language = (*it).language();
202  int pt = pluralType( language );
203  (*it).setPluralType( pt );
204  }
205 }
206 
207 
208 int TDELocale::pluralType( const TQString & language )
209 {
210  for ( TQValueList<KCatalogue>::ConstIterator it = d->catalogues.begin();
211  it != d->catalogues.end();
212  ++it )
213  {
214  if ( ((*it).name() == SYSTEM_MESSAGES ) && ((*it).language() == language )) {
215  return pluralType( *it );
216  }
217  }
218  // tdelibs.mo does not seem to exist for this language
219  return -1;
220 }
221 
222 int TDELocale::pluralType( const KCatalogue& catalog )
223 {
224  const char* pluralFormString =
225  I18N_NOOP("_: Dear translator, please do not translate this string "
226  "in any form, but pick the _right_ value out of "
227  "NoPlural/TwoForms/French... If not sure what to do mail "
228  "thd@kde.org and coolo@kde.org, they will tell you. "
229  "Better leave that out if unsure, the programs will "
230  "crash!!\nDefinition of PluralForm - to be set by the "
231  "translator of tdelibs.po");
232  TQString pf (catalog.translate( pluralFormString));
233  if ( pf.isEmpty() ) {
234  return -1;
235  }
236  else if ( pf == "NoPlural" )
237  return 0;
238  else if ( pf == "TwoForms" )
239  return 1;
240  else if ( pf == "French" )
241  return 2;
242  else if ( pf == "OneTwoRest" )
243  return 3;
244  else if ( pf == "Russian" )
245  return 4;
246  else if ( pf == "Polish" )
247  return 5;
248  else if ( pf == "Slovenian" )
249  return 6;
250  else if ( pf == "Lithuanian" )
251  return 7;
252  else if ( pf == "Czech" )
253  return 8;
254  else if ( pf == "Slovak" )
255  return 9;
256  else if ( pf == "Maltese" )
257  return 10;
258  else if ( pf == "Arabic" )
259  return 11;
260  else if ( pf == "Balcan" )
261  return 12;
262  else if ( pf == "Macedonian" )
263  return 13;
264  else if ( pf == "Gaeilge" )
265  return 14;
266  else {
267  kdWarning(173) << "Definition of PluralForm is none of "
268  << "NoPlural/"
269  << "TwoForms/"
270  << "French/"
271  << "OneTwoRest/"
272  << "Russian/"
273  << "Polish/"
274  << "Slovenian/"
275  << "Lithuanian/"
276  << "Czech/"
277  << "Slovak/"
278  << "Arabic/"
279  << "Balcan/"
280  << "Macedonian/"
281  << "Gaeilge/"
282  << "Maltese: " << pf << endl;
283  exit(1);
284  }
285 }
286 
287 void TDELocale::doFormatInit() const
288 {
289  if ( d->formatInited ) return;
290 
291  TDELocale * that = const_cast<TDELocale *>(this);
292  that->initFormat();
293 
294  d->formatInited = true;
295 }
296 
297 void TDELocale::initFormat()
298 {
299  TDEConfig *config = d->config;
300  if (!config) config = TDEGlobal::instance()->config();
301  Q_ASSERT( config );
302 
303  kdDebug(173) << "TDELocale::initFormat" << endl;
304 
305  // make sure the config files are read using the correct locale
306  // ### Why not add a TDEConfigBase::setLocale( const TDELocale * )?
307  // ### Then we could remove this hack
308  TDELocale *lsave = TDEGlobal::_locale;
309  TDEGlobal::_locale = this;
310 
311  TDEConfigGroupSaver saver(config, "Locale");
312 
313  KSimpleConfig entry(locate("locale",
314  TQString::fromLatin1("l10n/%1/entry.desktop")
315  .arg(m_country)), true);
316  entry.setGroup("KCM Locale");
317 
318  // Numeric
319 #define readConfigEntry(key, default, save) \
320  save = entry.readEntry(key, TQString::fromLatin1(default)); \
321  save = config->readEntry(key, save);
322 
323 #define readConfigNumEntry(key, default, save, type) \
324  save = (type)entry.readNumEntry(key, default); \
325  save = (type)config->readNumEntry(key, save);
326 
327 #define readConfigBoolEntry(key, default, save) \
328  save = entry.readBoolEntry(key, default); \
329  save = config->readBoolEntry(key, save);
330 
331  readConfigEntry("DecimalSymbol", ".", m_decimalSymbol);
332  readConfigEntry("ThousandsSeparator", ",", m_thousandsSeparator);
333  m_thousandsSeparator.replace( TQString::fromLatin1("$0"), TQString() );
334  //kdDebug(173) << "m_thousandsSeparator=" << m_thousandsSeparator << endl;
335 
336  readConfigEntry("PositiveSign", "", m_positiveSign);
337  readConfigEntry("NegativeSign", "-", m_negativeSign);
338 
339  // Monetary
340  readConfigEntry("CurrencySymbol", "$", m_currencySymbol);
341  readConfigEntry("MonetaryDecimalSymbol", ".", m_monetaryDecimalSymbol);
342  readConfigEntry("MonetaryThousandsSeparator", ",",
343  m_monetaryThousandsSeparator);
344  m_monetaryThousandsSeparator.replace(TQString::fromLatin1("$0"), TQString());
345 
346  readConfigNumEntry("FracDigits", 2, m_fracDigits, int);
347  readConfigBoolEntry("PositivePrefixCurrencySymbol", true,
348  m_positivePrefixCurrencySymbol);
349  readConfigBoolEntry("NegativePrefixCurrencySymbol", true,
350  m_negativePrefixCurrencySymbol);
351  readConfigNumEntry("PositiveMonetarySignPosition", (int)BeforeQuantityMoney,
352  m_positiveMonetarySignPosition, SignPosition);
353  readConfigNumEntry("NegativeMonetarySignPosition", (int)ParensAround,
354  m_negativeMonetarySignPosition, SignPosition);
355 
356 
357  // Date and time
358  readConfigEntry("TimeFormat", "%H:%M:%S", m_timeFormat);
359  readConfigEntry("DateFormat", "%A %d %B %Y", m_dateFormat);
360  readConfigEntry("DateFormatShort", "%Y-%m-%d", m_dateFormatShort);
361  readConfigNumEntry("WeekStartDay", 1, d->weekStartDay, int);
362 
363  // other
364  readConfigNumEntry("PageSize", (int)TQPrinter::A4, d->pageSize, int);
365  readConfigNumEntry("MeasureSystem", (int)Metric, d->measureSystem,
366  MeasureSystem);
367  readConfigEntry("CalendarSystem", "gregorian", d->calendarType);
368  delete d->calendar;
369  d->calendar = 0; // ### HPB Is this the correct place?
370 
371  //Grammatical
372  //Precedence here is l10n / i18n / config file
373  KSimpleConfig language(locate("locale",
374  TQString::fromLatin1("%1/entry.desktop")
375  .arg(m_language)), true);
376  language.setGroup("KCM Locale");
377 #define read3ConfigBoolEntry(key, default, save) \
378  save = entry.readBoolEntry(key, default); \
379  save = language.readBoolEntry(key, save); \
380  save = config->readBoolEntry(key, save);
381 
382  read3ConfigBoolEntry("NounDeclension", false, d->nounDeclension);
383  read3ConfigBoolEntry("DateMonthNamePossessive", false,
384  d->dateMonthNamePossessive);
385 
386  // end of hack
387  TDEGlobal::_locale = lsave;
388 }
389 
390 bool TDELocale::setCountry(const TQString & country)
391 {
392  // Check if the file exists too??
393  if ( country.isEmpty() )
394  return false;
395 
396  m_country = country;
397 
398  d->formatInited = false;
399 
400  return true;
401 }
402 
403 TQString TDELocale::catalogueFileName(const TQString & language,
404  const KCatalogue & catalog)
405 {
406  TQString path = TQString::fromLatin1("%1/LC_MESSAGES/%2.mo")
407  .arg( language )
408  .arg( catalog.name() );
409 
410  TQString fileName = locate( "locale", path );
411  if (fileName.isEmpty())
412  fileName = locate( "locale-bundle", path );
413 
414  return fileName;
415 }
416 
417 bool TDELocale::setLanguage(const TQString & language)
418 {
419  if ( d->languageList.contains( language ) ) {
420  d->languageList.remove( language );
421  }
422  d->languageList.prepend( language ); // let us consider this language to be the most important one
423 
424  m_language = language; // remember main language for shortcut evaluation
425 
426  // important when called from the outside and harmless when called before populating the
427  // catalog name list
428  updateCatalogues();
429 
430  d->formatInited = false;
431 
432  return true; // Maybe the mo-files for this language are empty, but in principle we can speak all languages
433 }
434 
435 bool TDELocale::setLanguage(const TQStringList & languages)
436 {
437  TQStringList languageList( languages );
438  // This list might contain
439  // 1) some empty strings that we have to eliminate
440  // 2) duplicate entries like in de:fr:de, where we have to keep the first occurrance of a language in order
441  // to preserve the order of precenence of the user => iterate backwards
442  // 3) languages into which the application is not translated. For those languages we should not even load tdelibs.mo or tdeio.po.
443  // these langugage have to be dropped. Otherwise we get strange side effects, e.g. with Hebrew:
444  // the right/left switch for languages that write from
445  // right to left (like Hebrew or Arabic) is set in tdelibs.mo. If you only have tdelibs.mo
446  // but nothing from appname.mo, you get a mostly English app with layout from right to left.
447  // That was considered to be a bug by the Hebrew translators.
448  for( TQStringList::Iterator it = languageList.fromLast();
449  it != languageList.begin(); --it )
450  {
451  // kdDebug() << "checking " << (*it) << endl;
452  bool bIsTranslated = isApplicationTranslatedInto( *it );
453  if ( languageList.contains(*it) > 1 || (*it).isEmpty() || (!bIsTranslated) ) {
454  // kdDebug() << "removing " << (*it) << endl;
455  it = languageList.remove( it );
456  }
457  }
458  // now this has left the first element of the list unchecked.
459  // The question why this is the case is left as an exercise for the reader...
460  // Besides the list might have been empty all the way, so check that too.
461  if ( languageList.begin() != languageList.end() ) {
462  TQStringList::Iterator it = languageList.begin(); // now pointing to the first element
463  // kdDebug() << "checking " << (*it) << endl;
464  if( (*it).isEmpty() || !(isApplicationTranslatedInto( *it )) ) {
465  // kdDebug() << "removing " << (*it) << endl;
466  languageList.remove( it ); // that's what the iterator was for...
467  }
468  }
469 
470  if ( languageList.isEmpty() ) {
471  // user picked no language, so we assume he/she speaks English.
472  languageList.append( defaultLanguage() );
473  }
474  m_language = languageList.first(); // keep this for shortcut evaluations
475 
476  d->languageList = languageList; // keep this new list of languages to use
477  d->langTwoAlpha.clear(); // Flush cache
478 
479  // important when called from the outside and harmless when called before populating the
480  // catalog name list
481  updateCatalogues();
482 
483  return true; // we found something. Maybe it's only English, but we found something
484 }
485 
486 bool TDELocale::isApplicationTranslatedInto( const TQString & language)
487 {
488  if ( language.isEmpty() ) {
489  return false;
490  }
491 
492  if ( language == defaultLanguage() ) {
493  // en_us is always "installed"
494  return true;
495  }
496 
497  TQString appName = d->appName;
498  if (maincatalogue) {
499  appName = TQString::fromLatin1(maincatalogue);
500  }
501  // sorry, catalogueFileName requires catalog object,k which we do not have here
502  // path finding was supposed to be moved completely to KCatalogue. The interface cannot
503  // be changed that far during deep freeze. So in order to fix the bug now, we have
504  // duplicated code for file path evaluation. Cleanup will follow later. We could have e.g.
505  // a static method in KCataloge that can translate between these file names.
506  // a stat
507  TQString sFileName = TQString::fromLatin1("%1/LC_MESSAGES/%2.mo")
508  .arg( language )
509  .arg( appName );
510  // kdDebug() << "isApplicationTranslatedInto: filename " << sFileName << endl;
511 
512  TQString sAbsFileName = locate( "locale", sFileName );
513  if (sAbsFileName.isEmpty())
514  sAbsFileName = locate( "locale-bundle", sFileName );
515 
516  // kdDebug() << "isApplicationTranslatedInto: absname " << sAbsFileName << endl;
517  return ! sAbsFileName.isEmpty();
518 }
519 
520 void TDELocale::splitLocale(const TQString & aStr,
521  TQString & language,
522  TQString & country,
523  TQString & chrset)
524 {
525  TQString str = aStr;
526 
527  // just in case, there is another language appended
528  int f = str.find(':');
529  if (f >= 0)
530  str.truncate(f);
531 
532  country = TQString::null;
533  chrset = TQString::null;
534  language = TQString::null;
535 
536  f = str.find('.');
537  if (f >= 0)
538  {
539  chrset = str.mid(f + 1);
540  str.truncate(f);
541  }
542 
543  f = str.find('_');
544  if (f >= 0)
545  {
546  country = str.mid(f + 1);
547  str.truncate(f);
548  }
549 
550  language = str;
551 }
552 
553 TQString TDELocale::language() const
554 {
555  return m_language;
556 }
557 
558 TQString TDELocale::country() const
559 {
560  return m_country;
561 }
562 
563 TQString TDELocale::monthName(int i, bool shortName) const
564 {
565  if ( shortName )
566  switch ( i )
567  {
568  case 1: return translate("January", "Jan");
569  case 2: return translate("February", "Feb");
570  case 3: return translate("March", "Mar");
571  case 4: return translate("April", "Apr");
572  case 5: return translate("May short", "May");
573  case 6: return translate("June", "Jun");
574  case 7: return translate("July", "Jul");
575  case 8: return translate("August", "Aug");
576  case 9: return translate("September", "Sep");
577  case 10: return translate("October", "Oct");
578  case 11: return translate("November", "Nov");
579  case 12: return translate("December", "Dec");
580  }
581  else
582  switch (i)
583  {
584  case 1: return translate("January");
585  case 2: return translate("February");
586  case 3: return translate("March");
587  case 4: return translate("April");
588  case 5: return translate("May long", "May");
589  case 6: return translate("June");
590  case 7: return translate("July");
591  case 8: return translate("August");
592  case 9: return translate("September");
593  case 10: return translate("October");
594  case 11: return translate("November");
595  case 12: return translate("December");
596  }
597 
598  return TQString::null;
599 }
600 
601 TQString TDELocale::monthNamePossessive(int i, bool shortName) const
602 {
603  if ( shortName )
604  switch ( i )
605  {
606  case 1: return translate("of January", "of Jan");
607  case 2: return translate("of February", "of Feb");
608  case 3: return translate("of March", "of Mar");
609  case 4: return translate("of April", "of Apr");
610  case 5: return translate("of May short", "of May");
611  case 6: return translate("of June", "of Jun");
612  case 7: return translate("of July", "of Jul");
613  case 8: return translate("of August", "of Aug");
614  case 9: return translate("of September", "of Sep");
615  case 10: return translate("of October", "of Oct");
616  case 11: return translate("of November", "of Nov");
617  case 12: return translate("of December", "of Dec");
618  }
619  else
620  switch (i)
621  {
622  case 1: return translate("of January");
623  case 2: return translate("of February");
624  case 3: return translate("of March");
625  case 4: return translate("of April");
626  case 5: return translate("of May long", "of May");
627  case 6: return translate("of June");
628  case 7: return translate("of July");
629  case 8: return translate("of August");
630  case 9: return translate("of September");
631  case 10: return translate("of October");
632  case 11: return translate("of November");
633  case 12: return translate("of December");
634  }
635 
636  return TQString::null;
637 }
638 
639 TQString TDELocale::weekDayName (int i, bool shortName) const
640 {
641  return calendar()->weekDayName(i, shortName);
642 }
643 
644 void TDELocale::insertCatalogue( const TQString & catalog )
645 {
646  if ( !d->catalogNames.contains( catalog) ) {
647  d->catalogNames.append( catalog );
648  }
649  updateCatalogues( ); // evaluate the changed list and generate the neccessary KCatalog objects
650 }
651 
652 void TDELocale::updateCatalogues( )
653 {
654  // some changes have occured. Maybe we have learned or forgotten some languages.
655  // Maybe the language precedence has changed.
656  // Maybe we have learned or forgotten some catalog names.
657  // Now examine the list of KCatalogue objects and change it according to the new circumstances.
658 
659  // this could be optimized: try to reuse old KCatalog objects, but remember that the order of
660  // catalogs might have changed: e.g. in this fashion
661  // 1) move all catalogs into a temporary list
662  // 2) iterate over all languages and catalog names
663  // 3.1) pick the catalog from the saved list, if it already exists
664  // 3.2) else create a new catalog.
665  // but we will do this later.
666 
667  for ( TQValueList<KCatalogue>::Iterator it = d->catalogues.begin();
668  it != d->catalogues.end(); )
669  {
670  it = d->catalogues.remove(it);
671  }
672 
673  // now iterate over all languages and all wanted catalog names and append or create them in the right order
674  // the sequence must be e.g. nds/appname nds/tdelibs nds/tdeio de/appname de/tdelibs de/tdeio etc.
675  // and not nds/appname de/appname nds/tdelibs de/tdelibs etc. Otherwise we would be in trouble with a language
676  // sequende nds,en_US, de. In this case en_US must hide everything below in the language list.
677  for ( TQStringList::ConstIterator itLangs = d->languageList.begin();
678  itLangs != d->languageList.end(); ++itLangs)
679  {
680  for ( TQStringList::ConstIterator itNames = d->catalogNames.begin();
681  itNames != d->catalogNames.end(); ++itNames)
682  {
683  KCatalogue cat( *itNames, *itLangs ); // create Catalog for this name and this language
684  d->catalogues.append( cat );
685  }
686  }
687  initPluralTypes(); // evaluate the plural type for all languages and remember this in each KCatalogue
688 }
689 
690 
691 
692 
693 void TDELocale::removeCatalogue(const TQString &catalog)
694 {
695  if ( d->catalogNames.contains( catalog )) {
696  d->catalogNames.remove( catalog );
697  if (TDEGlobal::_instance)
698  updateCatalogues(); // walk through the KCatalogue instances and weed out everything we no longer need
699  }
700 }
701 
702 void TDELocale::setActiveCatalogue(const TQString &catalog)
703 {
704  if ( d->catalogNames.contains( catalog ) ) {
705  d->catalogNames.remove( catalog );
706  d->catalogNames.prepend( catalog );
707  updateCatalogues(); // walk through the KCatalogue instances and adapt to the new order
708  }
709 }
710 
711 TDELocale::~TDELocale()
712 {
713  delete d->calendar;
714  delete d->languages;
715  delete d;
716  d = 0L;
717 }
718 
719 TQString TDELocale::translate_priv(const char *msgid,
720  const char *fallback,
721  const char **translated,
722  int* pluralType ) const
723 {
724  if ( pluralType) {
725  *pluralType = -1; // unless we find something more precise
726  }
727  if (!msgid || !msgid[0])
728  {
729  kdWarning() << "TDELocale: trying to look up \"\" in catalog. "
730  << "Fix the program" << endl;
731  return TQString::null;
732  }
733 
734  if ( useDefaultLanguage() ) { // shortcut evaluation if en_US is main language: do not consult the catalogs
735  return TQString::fromUtf8( fallback );
736  }
737 
738  for ( TQValueList<KCatalogue>::ConstIterator it = d->catalogues.begin();
739  it != d->catalogues.end();
740  ++it )
741  {
742  // shortcut evaluation: once we have arrived at en_US (default language) we cannot consult
743  // the catalog as it will not have an assiciated mo-file. For this default language we can
744  // immediately pick the fallback string.
745  if ( (*it).language() == defaultLanguage() ) {
746  return TQString::fromUtf8( fallback );
747  }
748 
749  const char * text = (*it).translate( msgid );
750 
751  if ( text )
752  {
753  // we found it
754  if (translated) {
755  *translated = text;
756  }
757  if ( pluralType) {
758  *pluralType = (*it).pluralType(); // remember the plural type information from the catalog that was used
759  }
760  return TQString::fromUtf8( text );
761  }
762  }
763 
764  // Always use UTF-8 if the string was not found
765  return TQString::fromUtf8( fallback );
766 }
767 
768 TQString TDELocale::translate(const char* msgid) const
769 {
770  return translate_priv(msgid, msgid);
771 }
772 
773 TQString TDELocale::translate( const char *index, const char *fallback) const
774 {
775  if (!index || !index[0] || !fallback || !fallback[0])
776  {
777  kdDebug(173) << "TDELocale: trying to look up \"\" in catalog. "
778  << "Fix the program" << endl;
779  return TQString::null;
780  }
781 
782  if ( useDefaultLanguage() )
783  return TQString::fromUtf8( fallback );
784 
785  char *newstring = new char[strlen(index) + strlen(fallback) + 5];
786  sprintf(newstring, "_: %s\n%s", index, fallback);
787  // as copying TQString is very fast, it looks slower as it is ;/
788  TQString r = translate_priv(newstring, fallback);
789  delete [] newstring;
790 
791  return r;
792 }
793 
794 static TQString put_n_in(const TQString &orig, unsigned long n)
795 {
796  TQString ret = orig;
797  int index = ret.find("%n");
798  if (index == -1)
799  return ret;
800  ret.replace(index, 2, TQString::number(n));
801  return ret;
802 }
803 
804 #define EXPECT_LENGTH(x) \
805  if (forms.count() != x) { \
806  kdError() << "translation of \"" << singular << "\" doesn't contain " << x << " different plural forms as expected\n"; \
807  return TQString( "BROKEN TRANSLATION %1" ).arg( singular ); }
808 
809 TQString TDELocale::translate( const char *singular, const char *plural,
810  unsigned long n ) const
811 {
812  if (!singular || !singular[0] || !plural || !plural[0])
813  {
814  kdWarning() << "TDELocale: trying to look up \"\" in catalog. "
815  << "Fix the program" << endl;
816  return TQString::null;
817  }
818 
819  char *newstring = new char[strlen(singular) + strlen(plural) + 6];
820  sprintf(newstring, "_n: %s\n%s", singular, plural);
821  // as copying TQString is very fast, it looks slower as it is ;/
822  int pluralType = -1;
823  TQString r = translate_priv(newstring, 0, 0, &pluralType);
824  delete [] newstring;
825 
826  if ( r.isEmpty() || useDefaultLanguage() || pluralType == -1) {
827  if ( n == 1 ) {
828  return put_n_in( TQString::fromUtf8( singular ), n );
829  } else {
830  TQString tmp = TQString::fromUtf8( plural );
831 #ifndef NDEBUG
832  if (tmp.find("%n") == -1) {
833  kdDebug() << "the message for i18n should contain a '%n'! " << plural << endl;
834  }
835 #endif
836  return put_n_in( tmp, n );
837  }
838  }
839 
840  TQStringList forms = TQStringList::split( "\n", r, false );
841  switch ( pluralType ) {
842  case 0: // NoPlural
843  EXPECT_LENGTH( 1 );
844  return put_n_in( forms[0], n);
845  case 1: // TwoForms
846  EXPECT_LENGTH( 2 );
847  if ( n == 1 )
848  return put_n_in( forms[0], n);
849  else
850  return put_n_in( forms[1], n);
851  case 2: // French
852  EXPECT_LENGTH( 2 );
853  if ( n == 1 || n == 0 )
854  return put_n_in( forms[0], n);
855  else
856  return put_n_in( forms[1], n);
857  case 3: // OneTwoRest
858  EXPECT_LENGTH( 3 );
859  if ( n == 1 )
860  return put_n_in( forms[0], n);
861  else if ( n == 2 )
862  return put_n_in( forms[1], n);
863  else
864  return put_n_in( forms[2], n);
865  case 4: // Russian, corrected by mok
866  EXPECT_LENGTH( 3 );
867  if ( n%10 == 1 && n%100 != 11)
868  return put_n_in( forms[0], n); // odin fail
869  else if (( n%10 >= 2 && n%10 <=4 ) && (n%100<10 || n%100>20))
870  return put_n_in( forms[1], n); // dva faila
871  else
872  return put_n_in( forms[2], n); // desyat' failov
873  case 5: // Polish
874  EXPECT_LENGTH( 3 );
875  if ( n == 1 )
876  return put_n_in( forms[0], n);
877  else if ( n%10 >= 2 && n%10 <=4 && (n%100<10 || n%100>=20) )
878  return put_n_in( forms[1], n);
879  else
880  return put_n_in( forms[2], n);
881  case 6: // Slovenian
882  EXPECT_LENGTH( 4 );
883  if ( n%100 == 1 )
884  return put_n_in( forms[1], n); // ena datoteka
885  else if ( n%100 == 2 )
886  return put_n_in( forms[2], n); // dve datoteki
887  else if ( n%100 == 3 || n%100 == 4 )
888  return put_n_in( forms[3], n); // tri datoteke
889  else
890  return put_n_in( forms[0], n); // sto datotek
891  case 7: // Lithuanian
892  EXPECT_LENGTH( 3 );
893  if ( n%10 == 0 || (n%100>=11 && n%100<=19) )
894  return put_n_in( forms[2], n);
895  else if ( n%10 == 1 )
896  return put_n_in( forms[0], n);
897  else
898  return put_n_in( forms[1], n);
899  case 8: // Czech - use modern form which is equivalent to Slovak
900  case 9: // Slovak
901  EXPECT_LENGTH( 3 );
902  if ( n == 1 )
903  return put_n_in( forms[0], n);
904  else if (( n >= 2 ) && ( n <= 4 ))
905  return put_n_in( forms[1], n);
906  else
907  return put_n_in( forms[2], n);
908  case 10: // Maltese
909  EXPECT_LENGTH( 4 );
910  if ( n == 1 )
911  return put_n_in( forms[0], n );
912  else if ( ( n == 0 ) || ( n%100 > 0 && n%100 <= 10 ) )
913  return put_n_in( forms[1], n );
914  else if ( n%100 > 10 && n%100 < 20 )
915  return put_n_in( forms[2], n );
916  else
917  return put_n_in( forms[3], n );
918  case 11: // Arabic
919  EXPECT_LENGTH( 4 );
920  if (n == 1)
921  return put_n_in(forms[0], n);
922  else if (n == 2)
923  return put_n_in(forms[1], n);
924  else if ( n < 11)
925  return put_n_in(forms[2], n);
926  else
927  return put_n_in(forms[3], n);
928  case 12: // Balcan
929  EXPECT_LENGTH( 3 );
930  if (n != 11 && n % 10 == 1)
931  return put_n_in(forms[0], n);
932  else if (n / 10 != 1 && n % 10 >= 2 && n % 10 <= 4)
933  return put_n_in(forms[1], n);
934  else
935  return put_n_in(forms[2], n);
936  case 13: // Macedonian
937  EXPECT_LENGTH(3);
938  if (n % 10 == 1)
939  return put_n_in(forms[0], n);
940  else if (n % 10 == 2)
941  return put_n_in(forms[1], n);
942  else
943  return put_n_in(forms[2], n);
944  case 14: // Gaeilge
945  EXPECT_LENGTH(5);
946  if (n == 1) // "ceann amhain"
947  return put_n_in(forms[0], n);
948  else if (n == 2) // "dha cheann"
949  return put_n_in(forms[1], n);
950  else if (n < 7) // "%n cinn"
951  return put_n_in(forms[2], n);
952  else if (n < 11) // "%n gcinn"
953  return put_n_in(forms[3], n);
954  else // "%n ceann"
955  return put_n_in(forms[4], n);
956  }
957  kdFatal() << "The function should have been returned in another way\n";
958 
959  return TQString::null;
960 }
961 
962 TQString TDELocale::translateQt( const char *context, const char *source,
963  const char *message) const
964 {
965  if (!source || !source[0]) {
966  kdWarning() << "TDELocale: trying to look up \"\" in catalog. "
967  << "Fix the program" << endl;
968  return TQString::null;
969  }
970 
971  if ( useDefaultLanguage() ) {
972  return TQString::null;
973  }
974 
975  char *newstring = 0;
976  const char *translation = 0;
977  TQString r;
978 
979  if ( message && message[0]) {
980  char *newstring = new char[strlen(source) + strlen(message) + 5];
981  sprintf(newstring, "_: %s\n%s", source, message);
982  const char *translation = 0;
983  // as copying TQString is very fast, it looks slower as it is ;/
984  r = translate_priv(newstring, source, &translation);
985  delete [] newstring;
986  if (translation)
987  return r;
988  }
989 
990  if ( context && context[0] && message && message[0]) {
991  newstring = new char[strlen(context) + strlen(message) + 5];
992  sprintf(newstring, "_: %s\n%s", context, message);
993  // as copying TQString is very fast, it looks slower as it is ;/
994  r = translate_priv(newstring, source, &translation);
995  delete [] newstring;
996  if (translation)
997  return r;
998  }
999 
1000  r = translate_priv(source, source, &translation);
1001  if (translation)
1002  return r;
1003  return TQString::null;
1004 }
1005 
1006 bool TDELocale::nounDeclension() const
1007 {
1008  doFormatInit();
1009  return d->nounDeclension;
1010 }
1011 
1012 bool TDELocale::dateMonthNamePossessive() const
1013 {
1014  doFormatInit();
1015  return d->dateMonthNamePossessive;
1016 }
1017 
1018 int TDELocale::weekStartDay() const
1019 {
1020  doFormatInit();
1021  return d->weekStartDay;
1022 }
1023 
1024 bool TDELocale::weekStartsMonday() const //deprecated
1025 {
1026  doFormatInit();
1027  return (d->weekStartDay==1);
1028 }
1029 
1030 TQString TDELocale::decimalSymbol() const
1031 {
1032  doFormatInit();
1033  return m_decimalSymbol;
1034 }
1035 
1036 TQString TDELocale::thousandsSeparator() const
1037 {
1038  doFormatInit();
1039  return m_thousandsSeparator;
1040 }
1041 
1042 TQString TDELocale::currencySymbol() const
1043 {
1044  doFormatInit();
1045  return m_currencySymbol;
1046 }
1047 
1048 TQString TDELocale::monetaryDecimalSymbol() const
1049 {
1050  doFormatInit();
1051  return m_monetaryDecimalSymbol;
1052 }
1053 
1054 TQString TDELocale::monetaryThousandsSeparator() const
1055 {
1056  doFormatInit();
1057  return m_monetaryThousandsSeparator;
1058 }
1059 
1060 TQString TDELocale::positiveSign() const
1061 {
1062  doFormatInit();
1063  return m_positiveSign;
1064 }
1065 
1066 TQString TDELocale::negativeSign() const
1067 {
1068  doFormatInit();
1069  return m_negativeSign;
1070 }
1071 
1072 int TDELocale::fracDigits() const
1073 {
1074  doFormatInit();
1075  return m_fracDigits;
1076 }
1077 
1078 bool TDELocale::positivePrefixCurrencySymbol() const
1079 {
1080  doFormatInit();
1081  return m_positivePrefixCurrencySymbol;
1082 }
1083 
1084 bool TDELocale::negativePrefixCurrencySymbol() const
1085 {
1086  doFormatInit();
1087  return m_negativePrefixCurrencySymbol;
1088 }
1089 
1090 TDELocale::SignPosition TDELocale::positiveMonetarySignPosition() const
1091 {
1092  doFormatInit();
1093  return m_positiveMonetarySignPosition;
1094 }
1095 
1096 TDELocale::SignPosition TDELocale::negativeMonetarySignPosition() const
1097 {
1098  doFormatInit();
1099  return m_negativeMonetarySignPosition;
1100 }
1101 
1102 static inline void put_it_in( TQChar *buffer, uint& index, const TQString &s )
1103 {
1104  for ( uint l = 0; l < s.length(); l++ )
1105  buffer[index++] = s.at( l );
1106 }
1107 
1108 static inline void put_it_in( TQChar *buffer, uint& index, int number )
1109 {
1110  buffer[index++] = number / 10 + '0';
1111  buffer[index++] = number % 10 + '0';
1112 }
1113 
1114 // insert (thousands)-"separator"s into the non-fractional part of str
1115 static void _insertSeparator(TQString &str, const TQString &separator,
1116  const TQString &decimalSymbol)
1117 {
1118  // leave fractional part untouched
1119  TQString mainPart = str.section(decimalSymbol, 0, 0);
1120  TQString fracPart = str.section(decimalSymbol, 1, 1,
1121  TQString::SectionIncludeLeadingSep);
1122 
1123  for (int pos = mainPart.length() - 3; pos > 0; pos -= 3)
1124  mainPart.insert(pos, separator);
1125 
1126  str = mainPart + fracPart;
1127 }
1128 
1129 TQString TDELocale::formatMoney(double num,
1130  const TQString & symbol,
1131  int precision) const
1132 {
1133  // some defaults
1134  TQString currency = symbol.isNull()
1135  ? currencySymbol()
1136  : symbol;
1137  if (precision < 0) precision = fracDigits();
1138 
1139  // the number itself
1140  bool neg = num < 0;
1141  TQString res = TQString::number(neg?-num:num, 'f', precision);
1142 
1143  // Replace dot with locale decimal separator
1144  res.replace(TQChar('.'), monetaryDecimalSymbol());
1145 
1146  // Insert the thousand separators
1147  _insertSeparator(res, monetaryThousandsSeparator(), monetaryDecimalSymbol());
1148 
1149  // set some variables we need later
1150  int signpos = neg
1151  ? negativeMonetarySignPosition()
1152  : positiveMonetarySignPosition();
1153  TQString sign = neg
1154  ? negativeSign()
1155  : positiveSign();
1156 
1157  switch (signpos)
1158  {
1159  case ParensAround:
1160  res.prepend('(');
1161  res.append (')');
1162  break;
1163  case BeforeQuantityMoney:
1164  res.prepend(sign);
1165  break;
1166  case AfterQuantityMoney:
1167  res.append(sign);
1168  break;
1169  case BeforeMoney:
1170  currency.prepend(sign);
1171  break;
1172  case AfterMoney:
1173  currency.append(sign);
1174  break;
1175  }
1176 
1177  if (neg?negativePrefixCurrencySymbol():
1178  positivePrefixCurrencySymbol())
1179  {
1180  res.prepend(' ');
1181  res.prepend(currency);
1182  } else {
1183  res.append (' ');
1184  res.append (currency);
1185  }
1186 
1187  return res;
1188 }
1189 
1190 TQString TDELocale::formatMoney(const TQString &numStr) const
1191 {
1192  return formatMoney(numStr.toDouble());
1193 }
1194 
1195 TQString TDELocale::formatNumber(double num, int precision) const
1196 {
1197  if (precision == -1) precision = 2;
1198  // no need to round since TQString::number does this for us
1199  return formatNumber(TQString::number(num, 'f', precision), false, 0);
1200 }
1201 
1202 TQString TDELocale::formatLong(long num) const
1203 {
1204  return formatNumber((double)num, 0);
1205 }
1206 
1207 TQString TDELocale::formatNumber(const TQString &numStr) const
1208 {
1209  return formatNumber(numStr, true, 2);
1210 }
1211 
1212 // increase the digit at 'position' by one
1213 static void _inc_by_one(TQString &str, int position)
1214 {
1215  for (int i = position; i >= 0; i--)
1216  {
1217  char last_char = str[i].latin1();
1218  switch(last_char)
1219  {
1220  case '0':
1221  str[i] = (QChar)'1';
1222  break;
1223  case '1':
1224  str[i] = (QChar)'2';
1225  break;
1226  case '2':
1227  str[i] = (QChar)'3';
1228  break;
1229  case '3':
1230  str[i] = (QChar)'4';
1231  break;
1232  case '4':
1233  str[i] = (QChar)'5';
1234  break;
1235  case '5':
1236  str[i] = (QChar)'6';
1237  break;
1238  case '6':
1239  str[i] = (QChar)'7';
1240  break;
1241  case '7':
1242  str[i] = (QChar)'8';
1243  break;
1244  case '8':
1245  str[i] = (QChar)'9';
1246  break;
1247  case '9':
1248  str[i] = (QChar)'0';
1249  if (i == 0) str.prepend('1');
1250  continue;
1251  case '.':
1252  continue;
1253  }
1254  break;
1255  }
1256 }
1257 
1258 // Cut off if more digits in fractional part than 'precision'
1259 static void _round(TQString &str, int precision)
1260 {
1261  int decimalSymbolPos = str.find('.');
1262 
1263  if (decimalSymbolPos == -1)
1264  if (precision == 0) return;
1265  else if (precision > 0) // add dot if missing (and needed)
1266  {
1267  str.append('.');
1268  decimalSymbolPos = str.length() - 1;
1269  }
1270 
1271  // fill up with more than enough zeroes (in case fractional part too short)
1272  str.append(TQString().fill('0', precision));
1273 
1274  // Now decide whether to round up or down
1275  char last_char = str[decimalSymbolPos + precision + 1].latin1();
1276  switch (last_char)
1277  {
1278  case '0':
1279  case '1':
1280  case '2':
1281  case '3':
1282  case '4':
1283  // nothing to do, rounding down
1284  break;
1285  case '5':
1286  case '6':
1287  case '7':
1288  case '8':
1289  case '9':
1290  _inc_by_one(str, decimalSymbolPos + precision);
1291  break;
1292  default:
1293  break;
1294  }
1295 
1296  decimalSymbolPos = str.find('.');
1297  str.truncate(decimalSymbolPos + precision + 1);
1298 
1299  // if precision == 0 delete also '.'
1300  if (precision == 0) str = str.section('.', 0, 0);
1301 }
1302 
1303 TQString TDELocale::formatNumber(const TQString &numStr, bool round,
1304  int precision) const
1305 {
1306  TQString tmpString = numStr;
1307  if ((round && precision < 0) ||
1308  ! TQRegExp("^[+-]?\\d+(\\.\\d+)*(e[+-]?\\d+)?$").exactMatch(tmpString))
1309  return numStr;
1310 
1311 
1312  // Skip the sign (for now)
1313  bool neg = (tmpString[0] == (QChar)'-');
1314  if (neg || tmpString[0] == (QChar)'+') tmpString.remove(0, 1);
1315 
1316  // Split off exponential part (including 'e'-symbol)
1317  TQString mantString = tmpString.section('e', 0, 0,
1318  TQString::SectionCaseInsensitiveSeps);
1319  TQString expString = tmpString.section('e', 1, 1,
1320  TQString::SectionCaseInsensitiveSeps |
1321  TQString::SectionIncludeLeadingSep);
1322 
1323  if (round) _round(mantString, precision);
1324 
1325  // Replace dot with locale decimal separator
1326  mantString.replace(TQChar('.'), decimalSymbol());
1327 
1328  // Insert the thousand separators
1329  _insertSeparator(mantString, thousandsSeparator(), decimalSymbol());
1330 
1331  // How can we know where we should put the sign?
1332  mantString.prepend(neg?negativeSign():positiveSign());
1333 
1334  return mantString + expString;
1335 }
1336 
1337 TQString TDELocale::formatDate(const TQDate &pDate, bool shortFormat) const
1338 {
1339  const TQString rst = shortFormat?dateFormatShort():dateFormat();
1340 
1341  TQString buffer;
1342 
1343  if ( ! pDate.isValid() ) return buffer;
1344 
1345  bool escape = false;
1346 
1347  int year = calendar()->year(pDate);
1348  int month = calendar()->month(pDate);
1349 
1350  for ( uint format_index = 0; format_index < rst.length(); ++format_index )
1351  {
1352  if ( !escape )
1353  {
1354  if ( (TQChar(rst.at( format_index )).unicode()) == '%' )
1355  escape = true;
1356  else
1357  buffer.append(rst.at(format_index));
1358  }
1359  else
1360  {
1361  switch ( TQChar(rst.at( format_index )).unicode() )
1362  {
1363  case '%':
1364  buffer.append('%');
1365  break;
1366  case 'Y':
1367  buffer.append(calendar()->yearString(pDate, false));
1368  break;
1369  case 'y':
1370  buffer.append(calendar()->yearString(pDate, true));
1371  break;
1372  case 'n':
1373  buffer.append(calendar()->monthString(pDate, true));
1374  break;
1375  case 'e':
1376  buffer.append(calendar()->dayString(pDate, true));
1377  break;
1378  case 'm':
1379  buffer.append(calendar()->monthString(pDate, false));
1380  break;
1381  case 'b':
1382  if (d->nounDeclension && d->dateMonthNamePossessive)
1383  buffer.append(calendar()->monthNamePossessive(month, year, true));
1384  else
1385  buffer.append(calendar()->monthName(month, year, true));
1386  break;
1387  case 'B':
1388  if (d->nounDeclension && d->dateMonthNamePossessive)
1389  buffer.append(calendar()->monthNamePossessive(month, year, false));
1390  else
1391  buffer.append(calendar()->monthName(month, year, false));
1392  break;
1393  case 'd':
1394  buffer.append(calendar()->dayString(pDate, false));
1395  break;
1396  case 'a':
1397  buffer.append(calendar()->weekDayName(pDate, true));
1398  break;
1399  case 'A':
1400  buffer.append(calendar()->weekDayName(pDate, false));
1401  break;
1402  default:
1403  buffer.append(rst.at(format_index));
1404  break;
1405  }
1406  escape = false;
1407  }
1408  }
1409  return buffer;
1410 }
1411 
1412 void TDELocale::setMainCatalogue(const char *catalog)
1413 {
1414  maincatalogue = catalog;
1415 }
1416 
1417 double TDELocale::readNumber(const TQString &_str, bool * ok) const
1418 {
1419  TQString str = _str.stripWhiteSpace();
1420  bool neg = str.find(negativeSign()) == 0;
1421  if (neg)
1422  str.remove( 0, negativeSign().length() );
1423 
1424  /* will hold the scientific notation portion of the number.
1425  Example, with 2.34E+23, exponentialPart == "E+23"
1426  */
1427  TQString exponentialPart;
1428  int EPos;
1429 
1430  EPos = str.find('E', 0, false);
1431 
1432  if (EPos != -1)
1433  {
1434  exponentialPart = str.mid(EPos);
1435  str = str.left(EPos);
1436  }
1437 
1438  int pos = str.find(decimalSymbol());
1439  TQString major;
1440  TQString minor;
1441  if ( pos == -1 )
1442  major = str;
1443  else
1444  {
1445  major = str.left(pos);
1446  minor = str.mid(pos + decimalSymbol().length());
1447  }
1448 
1449  // Remove thousand separators
1450  int thlen = thousandsSeparator().length();
1451  int lastpos = 0;
1452  while ( ( pos = major.find( thousandsSeparator() ) ) > 0 )
1453  {
1454  // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N
1455  int fromEnd = major.length() - pos;
1456  if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error
1457  || pos - lastpos > 3 // More than 3 digits between two separators -> error
1458  || pos == 0 // Can't start with a separator
1459  || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators
1460  {
1461  if (ok) *ok = false;
1462  return 0.0;
1463  }
1464 
1465  lastpos = pos;
1466  major.remove( pos, thlen );
1467  }
1468  if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator
1469  {
1470  if (ok) *ok = false;
1471  return 0.0;
1472  }
1473 
1474  TQString tot;
1475  if (neg) tot = (QChar)'-';
1476 
1477  tot += major + '.' + minor + exponentialPart;
1478 
1479  return tot.toDouble(ok);
1480 }
1481 
1482 double TDELocale::readMoney(const TQString &_str, bool * ok) const
1483 {
1484  TQString str = _str.stripWhiteSpace();
1485  bool neg = false;
1486  bool currencyFound = false;
1487  TQString symbol = currencySymbol();
1488  // First try removing currency symbol from either end
1489  int pos = str.find(symbol);
1490  if ( pos == 0 || pos == (int) str.length()-symbol.length() )
1491  {
1492  str.remove(pos,symbol.length());
1493  str = str.stripWhiteSpace();
1494  currencyFound = true;
1495  }
1496  if (str.isEmpty())
1497  {
1498  if (ok) *ok = false;
1499  return 0;
1500  }
1501  // Then try removing negative sign from either end
1502  // (with a special case for parenthesis)
1503  if (negativeMonetarySignPosition() == ParensAround)
1504  {
1505  if (str[0] == (QChar)'(' && str[str.length()-1] == (QChar)')')
1506  {
1507  neg = true;
1508  str.remove(str.length()-1,1);
1509  str.remove(0,1);
1510  }
1511  }
1512  else
1513  {
1514  int i1 = str.find(negativeSign());
1515  if ( i1 == 0 || i1 == (int) str.length()-1 )
1516  {
1517  neg = true;
1518  str.remove(i1,negativeSign().length());
1519  }
1520  }
1521  if (neg) str = str.stripWhiteSpace();
1522 
1523  // Finally try again for the currency symbol, if we didn't find
1524  // it already (because of the negative sign being in the way).
1525  if ( !currencyFound )
1526  {
1527  pos = str.find(symbol);
1528  if ( pos == 0 || pos == (int) str.length()-symbol.length() )
1529  {
1530  str.remove(pos,symbol.length());
1531  str = str.stripWhiteSpace();
1532  }
1533  }
1534 
1535  // And parse the rest as a number
1536  pos = str.find(monetaryDecimalSymbol());
1537  TQString major;
1538  TQString minior;
1539  if (pos == -1)
1540  major = str;
1541  else
1542  {
1543  major = str.left(pos);
1544  minior = str.mid(pos + monetaryDecimalSymbol().length());
1545  }
1546 
1547  // Remove thousand separators
1548  int thlen = monetaryThousandsSeparator().length();
1549  int lastpos = 0;
1550  while ( ( pos = major.find( monetaryThousandsSeparator() ) ) > 0 )
1551  {
1552  // e.g. 12,,345,,678,,922 Acceptable positions (from the end) are 5, 10, 15... i.e. (3+thlen)*N
1553  int fromEnd = major.length() - pos;
1554  if ( fromEnd % (3+thlen) != 0 // Needs to be a multiple, otherwise it's an error
1555  || pos - lastpos > 3 // More than 3 digits between two separators -> error
1556  || pos == 0 // Can't start with a separator
1557  || (lastpos>0 && pos-lastpos!=3)) // Must have exactly 3 digits between two separators
1558  {
1559  if (ok) *ok = false;
1560  return 0.0;
1561  }
1562  lastpos = pos;
1563  major.remove( pos, thlen );
1564  }
1565  if (lastpos>0 && major.length()-lastpos!=3) // Must have exactly 3 digits after the last separator
1566  {
1567  if (ok) *ok = false;
1568  return 0.0;
1569  }
1570 
1571  TQString tot;
1572  if (neg) tot = (QChar)'-';
1573  tot += major + '.' + minior;
1574  return tot.toDouble(ok);
1575 }
1576 
1583 static int readInt(const TQString &str, uint &pos)
1584 {
1585  if (!str.at(pos).isDigit()) return -1;
1586  int result = 0;
1587  for (; str.length() > pos && str.at(pos).isDigit(); pos++)
1588  {
1589  result *= 10;
1590  result += str.at(pos).digitValue();
1591  }
1592 
1593  return result;
1594 }
1595 
1596 TQDate TDELocale::readDate(const TQString &intstr, bool* ok) const
1597 {
1598  TQDate date;
1599  date = readDate(intstr, ShortFormat, ok);
1600  if (date.isValid()) return date;
1601  return readDate(intstr, NormalFormat, ok);
1602 }
1603 
1604 TQDate TDELocale::readDate(const TQString &intstr, ReadDateFlags flags, bool* ok) const
1605 {
1606  TQString fmt = ((flags & ShortFormat) ? dateFormatShort() : dateFormat()).simplifyWhiteSpace();
1607  return readDate( intstr, fmt, ok );
1608 }
1609 
1610 TQDate TDELocale::readDate(const TQString &intstr, const TQString &fmt, bool* ok) const
1611 {
1612  //kdDebug() << "TDELocale::readDate intstr=" << intstr << " fmt=" << fmt << endl;
1613  TQString str = intstr.simplifyWhiteSpace().lower();
1614  int day = -1, month = -1;
1615  // allow the year to be omitted if not in the format
1616  int year = calendar()->year(TQDate::currentDate());
1617  uint strpos = 0;
1618  uint fmtpos = 0;
1619 
1620  int iLength; // Temporary variable used when reading input
1621 
1622  bool error = false;
1623 
1624  while (fmt.length() > fmtpos && str.length() > strpos && !error)
1625  {
1626 
1627  TQChar c = fmt.at(fmtpos++);
1628 
1629  if (c != (QChar)'%') {
1630  if (c.isSpace() && str.at(strpos).isSpace())
1631  strpos++;
1632  else if (c != str.at(strpos++))
1633  error = true;
1634  }
1635  else
1636  {
1637  int j;
1638  // remove space at the beginning
1639  if (str.length() > strpos && str.at(strpos).isSpace())
1640  strpos++;
1641 
1642  c = fmt.at(fmtpos++);
1643  switch (c)
1644  {
1645  case 'a':
1646  case 'A':
1647 
1648  error = true;
1649  j = 1;
1650  while (error && (j < 8)) {
1651  TQString s = calendar()->weekDayName(j, c == (QChar)'a').lower();
1652  int len = s.length();
1653  if (str.mid(strpos, len) == s)
1654  {
1655  strpos += len;
1656  error = false;
1657  }
1658  j++;
1659  }
1660  break;
1661  case 'b':
1662  case 'B':
1663 
1664  error = true;
1665  if (d->nounDeclension && d->dateMonthNamePossessive) {
1666  j = 1;
1667  while (error && (j < 13)) {
1668  TQString s = calendar()->monthNamePossessive(j, year, c == (QChar)'b').lower();
1669  int len = s.length();
1670  if (str.mid(strpos, len) == s) {
1671  month = j;
1672  strpos += len;
1673  error = false;
1674  }
1675  j++;
1676  }
1677  }
1678  j = 1;
1679  while (error && (j < 13)) {
1680  TQString s = calendar()->monthName(j, year, c == (QChar)'b').lower();
1681  int len = s.length();
1682  if (str.mid(strpos, len) == s) {
1683  month = j;
1684  strpos += len;
1685  error = false;
1686  }
1687  j++;
1688  }
1689  break;
1690  case 'd':
1691  case 'e':
1692  day = calendar()->dayStringToInteger(str.mid(strpos), iLength);
1693  strpos += iLength;
1694 
1695  error = iLength <= 0;
1696  break;
1697 
1698  case 'n':
1699  case 'm':
1700  month = calendar()->monthStringToInteger(str.mid(strpos), iLength);
1701  strpos += iLength;
1702 
1703  error = iLength <= 0;
1704  break;
1705 
1706  case 'Y':
1707  case 'y':
1708  year = calendar()->yearStringToInteger(str.mid(strpos), iLength);
1709  strpos += iLength;
1710 
1711  error = iLength <= 0;
1712  break;
1713  }
1714  }
1715  }
1716 
1717  /* for a match, we should reach the end of both strings, not just one of
1718  them */
1719  if ( fmt.length() > fmtpos || str.length() > strpos )
1720  {
1721  error = true;
1722  }
1723 
1724  //kdDebug(173) << "TDELocale::readDate day=" << day << " month=" << month << " year=" << year << endl;
1725  if ( year != -1 && month != -1 && day != -1 && !error)
1726  {
1727  if (ok) *ok = true;
1728 
1729  TQDate result;
1730  calendar()->setYMD(result, year, month, day);
1731 
1732  return result;
1733  }
1734  else
1735  {
1736  if (ok) *ok = false;
1737  return TQDate(); // invalid date
1738  }
1739 }
1740 
1741 TQTime TDELocale::readTime(const TQString &intstr, bool *ok) const
1742 {
1743  TQTime _time;
1744  _time = readTime(intstr, WithSeconds, ok);
1745  if (_time.isValid()) return _time;
1746  return readTime(intstr, WithoutSeconds, ok);
1747 }
1748 
1749 TQTime TDELocale::readTime(const TQString &intstr, ReadTimeFlags flags, bool *ok) const
1750 {
1751  TQString str = intstr.simplifyWhiteSpace().lower();
1752  TQString Format = timeFormat().simplifyWhiteSpace();
1753  if (flags & WithoutSeconds)
1754  Format.remove(TQRegExp(".%S"));
1755 
1756  int hour = -1, minute = -1;
1757  int second = ( (flags & WithoutSeconds) == 0 ) ? -1 : 0; // don't require seconds
1758  bool g_12h = false;
1759  bool pm = false;
1760  uint strpos = 0;
1761  uint Formatpos = 0;
1762 
1763  while (Format.length() > Formatpos || str.length() > strpos)
1764  {
1765  if ( !(Format.length() > Formatpos && str.length() > strpos) ) goto error;
1766 
1767  TQChar c = Format.at(Formatpos++);
1768 
1769  if (c != (QChar)'%')
1770  {
1771  if (c.isSpace())
1772  strpos++;
1773  else if (c != str.at(strpos++))
1774  goto error;
1775  continue;
1776  }
1777 
1778  // remove space at the beginning
1779  if (str.length() > strpos && str.at(strpos).isSpace())
1780  strpos++;
1781 
1782  c = Format.at(Formatpos++);
1783  switch (c)
1784  {
1785  case 'p':
1786  {
1787  TQString s;
1788  s = translate("pm").lower();
1789  int len = s.length();
1790  if (str.mid(strpos, len) == s)
1791  {
1792  pm = true;
1793  strpos += len;
1794  }
1795  else
1796  {
1797  s = translate("am").lower();
1798  len = s.length();
1799  if (str.mid(strpos, len) == s) {
1800  pm = false;
1801  strpos += len;
1802  }
1803  else
1804  goto error;
1805  }
1806  }
1807  break;
1808 
1809  case 'k':
1810  case 'H':
1811  g_12h = false;
1812  hour = readInt(str, strpos);
1813  if (hour < 0 || hour > 23)
1814  goto error;
1815 
1816  break;
1817 
1818  case 'l':
1819  case 'I':
1820  g_12h = true;
1821  hour = readInt(str, strpos);
1822  if (hour < 1 || hour > 12)
1823  goto error;
1824 
1825  break;
1826 
1827  case 'M':
1828  minute = readInt(str, strpos);
1829  if (minute < 0 || minute > 59)
1830  goto error;
1831 
1832  break;
1833 
1834  case 'S':
1835  second = readInt(str, strpos);
1836  if (second < 0 || second > 59)
1837  goto error;
1838 
1839  break;
1840  }
1841  }
1842  if (g_12h) {
1843  hour %= 12;
1844  if (pm) hour += 12;
1845  }
1846 
1847  if (ok) *ok = true;
1848  return TQTime(hour, minute, second);
1849 
1850  error:
1851  if (ok) *ok = false;
1852  // ######## KDE4: remove this
1853  return TQTime(-1, -1, -1); // return invalid date if it didn't work
1854 }
1855 
1856 //BIC: merge with below
1857 TQString TDELocale::formatTime(const TQTime &pTime, bool includeSecs) const
1858 {
1859  return formatTime( pTime, includeSecs, false );
1860 }
1861 
1862 TQString TDELocale::formatTime(const TQTime &pTime, bool includeSecs, bool isDuration) const
1863 {
1864  const TQString rst = timeFormat();
1865 
1866  // only "pm/am" here can grow, the rest shrinks, but
1867  // I'm rather safe than sorry
1868  TQChar *buffer = new TQChar[rst.length() * 3 / 2 + 30];
1869 
1870  uint index = 0;
1871  bool escape = false;
1872  int number = 0;
1873 
1874  for ( uint format_index = 0; format_index < rst.length(); format_index++ )
1875  {
1876  if ( !escape )
1877  {
1878  if ( (TQChar(rst.at( format_index )).unicode()) == '%' )
1879  escape = true;
1880  else
1881  buffer[index++] = rst.at( format_index );
1882  }
1883  else
1884  {
1885  switch ( TQChar(rst.at( format_index )).unicode() )
1886  {
1887  case '%':
1888  buffer[index++] = (QChar)'%';
1889  break;
1890  case 'H':
1891  put_it_in( buffer, index, pTime.hour() );
1892  break;
1893  case 'I':
1894  if ( isDuration )
1895  put_it_in( buffer, index, pTime.hour() );
1896  else
1897  put_it_in( buffer, index, ( pTime.hour() + 11) % 12 + 1 );
1898  break;
1899  case 'M':
1900  put_it_in( buffer, index, pTime.minute() );
1901  break;
1902  case 'S':
1903  if (includeSecs)
1904  put_it_in( buffer, index, pTime.second() );
1905  else if ( index > 0 )
1906  {
1907  // we remove the separator sign before the seconds and
1908  // assume that works everywhere
1909  --index;
1910  break;
1911  }
1912  break;
1913  case 'k':
1914  number = pTime.hour();
1915  case 'l':
1916  // to share the code
1917  if ( (TQChar(rst.at( format_index )).unicode()) == 'l' )
1918  number = isDuration ? pTime.hour() : (pTime.hour() + 11) % 12 + 1;
1919  if ( number / 10 )
1920  buffer[index++] = number / 10 + '0';
1921  buffer[index++] = number % 10 + '0';
1922  break;
1923  case 'p':
1924  if ( !isDuration )
1925  {
1926  TQString s;
1927  if ( pTime.hour() >= 12 )
1928  put_it_in( buffer, index, translate("pm") );
1929  else
1930  put_it_in( buffer, index, translate("am") );
1931  }
1932  break;
1933  default:
1934  buffer[index++] = rst.at( format_index );
1935  break;
1936  }
1937  escape = false;
1938  }
1939  }
1940  TQString ret( buffer, index );
1941  delete [] buffer;
1942  if ( isDuration ) // eliminate trailing-space due to " %p"
1943  return ret.stripWhiteSpace();
1944  else
1945  return ret;
1946 }
1947 
1948 bool TDELocale::use12Clock() const
1949 {
1950  if ((timeFormat().contains(TQString::fromLatin1("%I")) > 0) ||
1951  (timeFormat().contains(TQString::fromLatin1("%l")) > 0))
1952  return true;
1953  else
1954  return false;
1955 }
1956 
1957 TQString TDELocale::languages() const
1958 {
1959  return d->languageList.join( TQString::fromLatin1(":") );
1960 }
1961 
1962 TQStringList TDELocale::languageList() const
1963 {
1964  return d->languageList;
1965 }
1966 
1967 TQString TDELocale::formatDateTime(const TQDateTime &pDateTime,
1968  bool shortFormat,
1969  bool includeSeconds) const
1970 {
1971  return translate("concatenation of dates and time", "%1 %2")
1972  .arg( formatDate( TQT_TQDATE_OBJECT(pDateTime.date()), shortFormat ) )
1973  .arg( formatTime( TQT_TQTIME_OBJECT(pDateTime.time()), includeSeconds ) );
1974 }
1975 
1976 TQString i18n(const char* text)
1977 {
1978  TDELocale *instance = TDEGlobal::locale();
1979  if (instance)
1980  return instance->translate(text);
1981  return TQString::fromUtf8(text);
1982 }
1983 
1984 TQString i18n(const char* index, const char *text)
1985 {
1986  TDELocale *instance = TDEGlobal::locale();
1987  if (instance)
1988  return instance->translate(index, text);
1989  return TQString::fromUtf8(text);
1990 }
1991 
1992 TQString i18n(const char* singular, const char* plural, unsigned long n)
1993 {
1994  TDELocale *instance = TDEGlobal::locale();
1995  if (instance)
1996  return instance->translate(singular, plural, n);
1997  if (n == 1)
1998  return put_n_in(TQString::fromUtf8(singular), n);
1999  else
2000  return put_n_in(TQString::fromUtf8(plural), n);
2001 }
2002 
2003 void TDELocale::initInstance()
2004 {
2005  if (TDEGlobal::_locale)
2006  return;
2007 
2008  TDEInstance *app = TDEGlobal::instance();
2009  if (app) {
2010  TDEGlobal::_locale = new TDELocale(TQString::fromLatin1(app->instanceName()));
2011 
2012  // only do this for the global instance
2013  TQTextCodec::setCodecForLocale(TDEGlobal::_locale->codecForEncoding());
2014  }
2015  else
2016  kdDebug(173) << "no app name available using TDELocale - nothing to do\n";
2017 }
2018 
2019 TQString TDELocale::langLookup(const TQString &fname, const char *rtype)
2020 {
2021  TQStringList search;
2022 
2023  // assemble the local search paths
2024  const TQStringList localDoc = TDEGlobal::dirs()->resourceDirs(rtype);
2025 
2026  // look up the different languages
2027  for (int id=localDoc.count()-1; id >= 0; --id)
2028  {
2029  TQStringList langs = TDEGlobal::locale()->languageList();
2030  langs.append( "en" );
2031  langs.remove( defaultLanguage() );
2032  TQStringList::ConstIterator lang;
2033  for (lang = langs.begin(); lang != langs.end(); ++lang)
2034  search.append(TQString("%1%2/%3").arg(localDoc[id]).arg(*lang).arg(fname));
2035  }
2036 
2037  // try to locate the file
2038  TQStringList::Iterator it;
2039  for (it = search.begin(); it != search.end(); ++it)
2040  {
2041  kdDebug(173) << "Looking for help in: " << *it << endl;
2042 
2043  TQFileInfo info(*it);
2044  if (info.exists() && info.isFile() && info.isReadable())
2045  return *it;
2046  }
2047 
2048  return TQString::null;
2049 }
2050 
2051 bool TDELocale::useDefaultLanguage() const
2052 {
2053  return language() == defaultLanguage();
2054 }
2055 
2056 void TDELocale::initEncoding(TDEConfig *)
2057 {
2058  const int mibDefault = 4; // ISO 8859-1
2059 
2060  // This all made more sense when we still had the EncodingEnum config key.
2061  setEncoding( TQTextCodec::codecForLocale()->mibEnum() );
2062 
2063  if ( !d->codecForEncoding )
2064  {
2065  kdWarning(173) << " Defaulting to ISO 8859-1 encoding." << endl;
2066  setEncoding(mibDefault);
2067  }
2068 
2069  Q_ASSERT( d->codecForEncoding );
2070 }
2071 
2072 void TDELocale::initFileNameEncoding(TDEConfig *)
2073 {
2074  // If the following environment variable is set, assume all filenames
2075  // are in UTF-8 regardless of the current C locale.
2076  d->utf8FileEncoding = getenv("TDE_UTF8_FILENAMES") != 0;
2077  if (d->utf8FileEncoding)
2078  {
2079  TQFile::setEncodingFunction(TDELocale::encodeFileNameUTF8);
2080  TQFile::setDecodingFunction(TDELocale::decodeFileNameUTF8);
2081  }
2082  // Otherwise, stay with QFile's default filename encoding functions
2083  // which, on Unix platforms, use the locale's codec.
2084 }
2085 
2086 #ifdef USE_QT3
2087 TQCString TDELocale::encodeFileNameUTF8( const TQString & fileName )
2088 #endif // USE_QT3
2089 #ifdef USE_QT4
2090 QByteArray TDELocale::encodeFileNameUTF8( const QString & fileName )
2091 #endif // USE_QT4
2092 {
2093  return TQString(fileName).utf8();
2094 }
2095 
2096 #ifdef USE_QT3
2097 TQString TDELocale::decodeFileNameUTF8( const TQCString & localFileName )
2098 #endif // USE_QT3
2099 #ifdef USE_QT4
2100 QString TDELocale::decodeFileNameUTF8( const QByteArray & localFileName )
2101 #endif // USE_QT4
2102 {
2103  return TQString::fromUtf8(localFileName);
2104 }
2105 
2106 void TDELocale::setDateFormat(const TQString & format)
2107 {
2108  doFormatInit();
2109  m_dateFormat = format.stripWhiteSpace();
2110 }
2111 
2112 void TDELocale::setDateFormatShort(const TQString & format)
2113 {
2114  doFormatInit();
2115  m_dateFormatShort = format.stripWhiteSpace();
2116 }
2117 
2118 void TDELocale::setDateMonthNamePossessive(bool possessive)
2119 {
2120  doFormatInit();
2121  d->dateMonthNamePossessive = possessive;
2122 }
2123 
2124 void TDELocale::setTimeFormat(const TQString & format)
2125 {
2126  doFormatInit();
2127  m_timeFormat = format.stripWhiteSpace();
2128 }
2129 
2130 void TDELocale::setWeekStartsMonday(bool start) //deprecated
2131 {
2132  doFormatInit();
2133  if (start)
2134  d->weekStartDay = 1;
2135  else
2136  d->weekStartDay = 7;
2137 }
2138 
2139 void TDELocale::setWeekStartDay(int day)
2140 {
2141  doFormatInit();
2142  if (day>7 || day<1)
2143  d->weekStartDay = 1; //Monday is default
2144  else
2145  d->weekStartDay = day;
2146 }
2147 
2148 TQString TDELocale::dateFormat() const
2149 {
2150  doFormatInit();
2151  return m_dateFormat;
2152 }
2153 
2154 TQString TDELocale::dateFormatShort() const
2155 {
2156  doFormatInit();
2157  return m_dateFormatShort;
2158 }
2159 
2160 TQString TDELocale::timeFormat() const
2161 {
2162  doFormatInit();
2163  return m_timeFormat;
2164 }
2165 
2166 void TDELocale::setDecimalSymbol(const TQString & symbol)
2167 {
2168  doFormatInit();
2169  m_decimalSymbol = symbol.stripWhiteSpace();
2170 }
2171 
2172 void TDELocale::setThousandsSeparator(const TQString & separator)
2173 {
2174  doFormatInit();
2175  // allow spaces here
2176  m_thousandsSeparator = separator;
2177 }
2178 
2179 void TDELocale::setPositiveSign(const TQString & sign)
2180 {
2181  doFormatInit();
2182  m_positiveSign = sign.stripWhiteSpace();
2183 }
2184 
2185 void TDELocale::setNegativeSign(const TQString & sign)
2186 {
2187  doFormatInit();
2188  m_negativeSign = sign.stripWhiteSpace();
2189 }
2190 
2191 void TDELocale::setPositiveMonetarySignPosition(SignPosition signpos)
2192 {
2193  doFormatInit();
2194  m_positiveMonetarySignPosition = signpos;
2195 }
2196 
2197 void TDELocale::setNegativeMonetarySignPosition(SignPosition signpos)
2198 {
2199  doFormatInit();
2200  m_negativeMonetarySignPosition = signpos;
2201 }
2202 
2203 void TDELocale::setPositivePrefixCurrencySymbol(bool prefix)
2204 {
2205  doFormatInit();
2206  m_positivePrefixCurrencySymbol = prefix;
2207 }
2208 
2209 void TDELocale::setNegativePrefixCurrencySymbol(bool prefix)
2210 {
2211  doFormatInit();
2212  m_negativePrefixCurrencySymbol = prefix;
2213 }
2214 
2215 void TDELocale::setFracDigits(int digits)
2216 {
2217  doFormatInit();
2218  m_fracDigits = digits;
2219 }
2220 
2221 void TDELocale::setMonetaryThousandsSeparator(const TQString & separator)
2222 {
2223  doFormatInit();
2224  // allow spaces here
2225  m_monetaryThousandsSeparator = separator;
2226 }
2227 
2228 void TDELocale::setMonetaryDecimalSymbol(const TQString & symbol)
2229 {
2230  doFormatInit();
2231  m_monetaryDecimalSymbol = symbol.stripWhiteSpace();
2232 }
2233 
2234 void TDELocale::setCurrencySymbol(const TQString & symbol)
2235 {
2236  doFormatInit();
2237  m_currencySymbol = symbol.stripWhiteSpace();
2238 }
2239 
2240 int TDELocale::pageSize() const
2241 {
2242  doFormatInit();
2243  return d->pageSize;
2244 }
2245 
2246 void TDELocale::setPageSize(int pageSize)
2247 {
2248  // #### check if it's in range??
2249  doFormatInit();
2250  d->pageSize = pageSize;
2251 }
2252 
2253 TDELocale::MeasureSystem TDELocale::measureSystem() const
2254 {
2255  doFormatInit();
2256  return d->measureSystem;
2257 }
2258 
2259 void TDELocale::setMeasureSystem(MeasureSystem value)
2260 {
2261  doFormatInit();
2262  d->measureSystem = value;
2263 }
2264 
2265 TQString TDELocale::defaultLanguage()
2266 {
2267  return TQString::fromLatin1("en_US");
2268 }
2269 
2270 TQString TDELocale::defaultCountry()
2271 {
2272  return TQString::fromLatin1("C");
2273 }
2274 
2275 const char * TDELocale::encoding() const
2276 {
2277 #ifdef Q_WS_WIN
2278  if (0==qstrcmp("System", codecForEncoding()->name()))
2279  {
2280  //win32 returns "System" codec name here but KDE apps expect a real name:
2281  strcpy(d->win32SystemEncoding, "cp ");
2282  if (GetLocaleInfoA( MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT),
2283  LOCALE_IDEFAULTANSICODEPAGE, d->win32SystemEncoding+3, sizeof(d->win32SystemEncoding)-3-1 ))
2284  {
2285  return d->win32SystemEncoding;
2286  }
2287  }
2288 #endif
2289  return codecForEncoding()->name();
2290 }
2291 
2292 int TDELocale::encodingMib() const
2293 {
2294  return codecForEncoding()->mibEnum();
2295 }
2296 
2297 int TDELocale::fileEncodingMib() const
2298 {
2299  if (d->utf8FileEncoding)
2300  return 106;
2301  return codecForEncoding()->mibEnum();
2302 }
2303 
2304 TQTextCodec * TDELocale::codecForEncoding() const
2305 {
2306  return d->codecForEncoding;
2307 }
2308 
2309 bool TDELocale::setEncoding(int mibEnum)
2310 {
2311  TQTextCodec * codec = TQTextCodec::codecForMib(mibEnum);
2312  if (codec)
2313  d->codecForEncoding = codec;
2314 
2315  return codec != 0;
2316 }
2317 
2318 TQStringList TDELocale::languagesTwoAlpha() const
2319 {
2320  if (d->langTwoAlpha.count())
2321  return d->langTwoAlpha;
2322 
2323  const TQStringList &origList = languageList();
2324 
2325  TQStringList result;
2326 
2327  TDEConfig config(TQString::fromLatin1("language.codes"), true, false);
2328  config.setGroup("TwoLetterCodes");
2329 
2330  for ( TQStringList::ConstIterator it = origList.begin();
2331  it != origList.end();
2332  ++it )
2333  {
2334  TQString lang = *it;
2335  TQStringList langLst;
2336  if (config.hasKey( lang ))
2337  langLst = config.readListEntry( lang );
2338  else
2339  {
2340  int i = lang.find('_');
2341  if (i >= 0)
2342  lang.truncate(i);
2343  langLst << lang;
2344  }
2345 
2346  for ( TQStringList::ConstIterator langIt = langLst.begin();
2347  langIt != langLst.end();
2348  ++langIt )
2349  {
2350  if ( !(*langIt).isEmpty() && !result.contains( *langIt ) )
2351  result += *langIt;
2352  }
2353  }
2354  d->langTwoAlpha = result;
2355  return result;
2356 }
2357 
2358 TQStringList TDELocale::allLanguagesTwoAlpha() const
2359 {
2360  if (!d->languages)
2361  d->languages = new TDEConfig("all_languages", true, false, "locale");
2362 
2363  return d->languages->groupList();
2364 }
2365 
2366 TQString TDELocale::twoAlphaToLanguageName(const TQString &code) const
2367 {
2368  if (!d->languages)
2369  d->languages = new TDEConfig("all_languages", true, false, "locale");
2370 
2371  TQString groupName = code;
2372  const int i = groupName.find('_');
2373  groupName.replace(0, i, groupName.left(i).lower());
2374 
2375  d->languages->setGroup(groupName);
2376  return d->languages->readEntry("Name");
2377 }
2378 
2379 TQStringList TDELocale::allCountriesTwoAlpha() const
2380 {
2381  TQStringList countries;
2382  TQStringList paths = TDEGlobal::dirs()->findAllResources("locale", "l10n/*/entry.desktop");
2383  for(TQStringList::ConstIterator it = paths.begin();
2384  it != paths.end(); ++it)
2385  {
2386  TQString code = (*it).mid((*it).length()-16, 2);
2387  if (code != "/C")
2388  countries.append(code);
2389  }
2390  return countries;
2391 }
2392 
2393 TQString TDELocale::twoAlphaToCountryName(const TQString &code) const
2394 {
2395  TDEConfig cfg("l10n/"+code.lower()+"/entry.desktop", true, false, "locale");
2396  cfg.setGroup("KCM Locale");
2397  return cfg.readEntry("Name");
2398 }
2399 
2400 void TDELocale::setCalendar(const TQString & calType)
2401 {
2402  doFormatInit();
2403 
2404  d->calendarType = calType;
2405 
2406  delete d->calendar;
2407  d->calendar = 0;
2408 }
2409 
2410 TQString TDELocale::calendarType() const
2411 {
2412  doFormatInit();
2413 
2414  return d->calendarType;
2415 }
2416 
2417 const KCalendarSystem * TDELocale::calendar() const
2418 {
2419  doFormatInit();
2420 
2421  // Check if it's the correct calendar?!?
2422  if ( !d->calendar )
2423  d->calendar = KCalendarSystemFactory::create( d->calendarType, this );
2424 
2425  return d->calendar;
2426 }
2427 
2428 TDELocale::TDELocale(const TDELocale & rhs)
2429 {
2430  d = new TDELocalePrivate;
2431 
2432  *this = rhs;
2433 }
2434 
2435 TDELocale & TDELocale::operator=(const TDELocale & rhs)
2436 {
2437  // Numbers and money
2438  m_decimalSymbol = rhs.m_decimalSymbol;
2439  m_thousandsSeparator = rhs.m_thousandsSeparator;
2440  m_currencySymbol = rhs.m_currencySymbol;
2441  m_monetaryDecimalSymbol = rhs.m_monetaryDecimalSymbol;
2442  m_monetaryThousandsSeparator = rhs.m_monetaryThousandsSeparator;
2443  m_positiveSign = rhs.m_positiveSign;
2444  m_negativeSign = rhs.m_negativeSign;
2445  m_fracDigits = rhs.m_fracDigits;
2446  m_positivePrefixCurrencySymbol = rhs.m_positivePrefixCurrencySymbol;
2447  m_negativePrefixCurrencySymbol = rhs.m_negativePrefixCurrencySymbol;
2448  m_positiveMonetarySignPosition = rhs.m_positiveMonetarySignPosition;
2449  m_negativeMonetarySignPosition = rhs.m_negativeMonetarySignPosition;
2450 
2451  // Date and time
2452  m_timeFormat = rhs.m_timeFormat;
2453  m_dateFormat = rhs.m_dateFormat;
2454  m_dateFormatShort = rhs.m_dateFormatShort;
2455 
2456  m_language = rhs.m_language;
2457  m_country = rhs.m_country;
2458 
2459  // the assignment operator works here
2460  *d = *rhs.d;
2461  d->languages = 0; // Don't copy languages
2462  d->calendar = 0; // Don't copy the calendar
2463 
2464  return *this;
2465 }
2466 
2467 bool TDELocale::setCharset(const TQString & ) { return true; }
2468 TQString TDELocale::charset() const { return TQString::fromLatin1("UTF-8"); }
2469 
2470 // KDE4: remove
2471 #if 0
2472 void nothing() { i18n("&Next"); }
2473 #endif
TDELocale::twoAlphaToCountryName
TQString twoAlphaToCountryName(const TQString &code) const
Convert a country code to a human readable form.
Definition: tdelocale.cpp:2393
TDELocale::monetaryDecimalSymbol
TQString monetaryDecimalSymbol() const
Returns what a decimal point should look like ("." or "," etc.) for monetary values, according to the current locale or user settings.
Definition: tdelocale.cpp:1048
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:43
KCalendarSystem::monthName
virtual TQString monthName(int month, int year, bool shortName=false) const =0
Gets specific calendar type month name for a given month number If an invalid month is specified...
TDELocale::use12Clock
bool use12Clock() const
Use this to determine if the user wants a 12 hour clock.
Definition: tdelocale.cpp:1948
TDELocale::weekStartDay
int weekStartDay() const
Use this to determine which day is the first day of the week.
Definition: tdelocale.cpp:1018
TDELocale::positivePrefixCurrencySymbol
bool positivePrefixCurrencySymbol() const
If and only if the currency symbol precedes a positive value, this will be true.
Definition: tdelocale.cpp:1078
TDELocale::encodingMib
int encodingMib() const
Returns the user's preferred encoding.
Definition: tdelocale.cpp:2292
TDELocale::fileEncodingMib
int fileEncodingMib() const
Returns the file encoding.
Definition: tdelocale.cpp:2297
TDELocale::timeFormat
TQString timeFormat() const
Returns the currently selected time format.
Definition: tdelocale.cpp:2160
TDELocale::language
TQString language() const
Returns the language used by this object.
Definition: tdelocale.cpp:553
TDELocale::setMainCatalogue
static void setMainCatalogue(const char *catalog)
Use this as main catalog for all TDELocales, if not the appname will be used.
Definition: tdelocale.cpp:1412
TDELocale::dateFormat
TQString dateFormat() const
Returns the currently selected date format.
Definition: tdelocale.cpp:2148
TDEConfigBase::hasKey
bool hasKey(const TQString &key) const
Checks whether the key has an entry in the currently active group.
Definition: tdeconfigbase.cpp:109
TDELocale::setPositiveMonetarySignPosition
void setPositiveMonetarySignPosition(SignPosition signpos)
Changes the sign position used for positive monetary values.
Definition: tdelocale.cpp:2191
TDEConfigGroupSaver
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Definition: tdeconfigbase.h:2082
TDELocale::currencySymbol
TQString currencySymbol() const
Returns what the symbol denoting currency in the current locale as as defined by user settings should...
Definition: tdelocale.cpp:1042
TDEConfigBase::setGroup
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
Definition: tdeconfigbase.cpp:79
KCalendarSystem::year
virtual int year(const TQDate &date) const =0
Gets specific calendar type year for a given gregorian date.
TDELocale::setDateFormat
void setDateFormat(const TQString &format)
Changes the current date format.
Definition: tdelocale.cpp:2106
TDELocale::setFracDigits
void setFracDigits(int digits)
Changes the number of digits used when formating numbers.
Definition: tdelocale.cpp:2215
TDELocale::translate
TQString translate(const char *index) const
Translates the string into the corresponding string in the national language, if available.
Definition: tdelocale.cpp:768
KCatalogue::translate
const char * translate(const char *msgid) const
Retrieves a translation of the specified message id.
Definition: kcatalogue.cpp:144
TDEStandardDirs::resourceDirs
TQStringList 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:795
TDELocale::setWeekStartsMonday
void setWeekStartsMonday(bool start) KDE_DEPRECATED
Definition: tdelocale.cpp:2130
TDELocale::defaultLanguage
static TQString defaultLanguage()
Returns the name of the internal language.
Definition: tdelocale.cpp:2265
TDELocale::setNegativePrefixCurrencySymbol
void setNegativePrefixCurrencySymbol(bool prefix)
Changes the position where the currency symbol should be printed for negative monetary values...
Definition: tdelocale.cpp:2209
TDEConfigBase::readListEntry
int readListEntry(const TQString &pKey, TQStrList &list, char sep= ',') const
Reads a list of strings.
Definition: tdeconfigbase.cpp:491
TDELocale::monetaryThousandsSeparator
TQString monetaryThousandsSeparator() const
Returns what a thousands separator for monetary values should look like ("," or " " etc...
Definition: tdelocale.cpp:1054
TDELocale::languageList
TQStringList languageList() const
Returns the languages selected by user.
Definition: tdelocale.cpp:1962
TDELocale::i18n
TQString i18n(const char *text)
Definition: tdelocale.cpp:1976
TDELocale::country
TQString country() const
Returns the country code of the country where the user lives.
Definition: tdelocale.cpp:558
TDELocale::formatLong
TQString formatLong(long num) const
Given an integer, converts that to a numeric string containing the localized numeric equivalent...
Definition: tdelocale.cpp:1202
TDELocale::setLanguage
bool setLanguage(const TQString &language)
Changes the current language.
Definition: tdelocale.cpp:417
KCalendarSystem::yearStringToInteger
virtual int yearStringToInteger(const TQString &sNum, int &iLength) const
Converts a year literal of a part of a string into a integer starting at the beginning of the string...
Definition: kcalendarsystem.cpp:114
KCatalogue::name
TQString name() const
Returns the name of the catalog.
Definition: kcatalogue.cpp:100
TDELocale::setCalendar
void setCalendar(const TQString &calendarType)
Changes the current calendar system to the calendar specified.
Definition: tdelocale.cpp:2400
TDELocale::weekStartsMonday
bool weekStartsMonday() const KDE_DEPRECATED
Definition: tdelocale.cpp:1024
KCalendarSystem
CalendarSystem abstract class, default derived kde gregorian class and factory class.
Definition: kcalendarsystem.h:42
KCalendarSystem::dayStringToInteger
virtual int dayStringToInteger(const TQString &sNum, int &iLength) const
Converts a day literal of a part of a string into a integer starting at the beginning of the string...
Definition: kcalendarsystem.cpp:104
TDELocale::removeCatalogue
void removeCatalogue(const TQString &catalog)
Removes a catalog for translation lookup.
Definition: tdelocale.cpp:693
TDELocale::pageSize
int pageSize() const
Returns the preferred page size for printing.
Definition: tdelocale.cpp:2240
TDELocale::~TDELocale
~TDELocale()
Destructor.
Definition: tdelocale.cpp:711
TDELocale::I18N_NOOP
#define I18N_NOOP(x)
Definition: tdelocale.h:51
TDELocale::translateQt
TQString translateQt(const char *context, const char *sourceText, const char *message) const
Translates a message as a QTranslator is supposed to.
Definition: tdelocale.cpp:962
TDELocale::TDELocale
TDELocale(const TQString &catalog, TDEConfig *config=0)
Constructs a TDELocale with the given catalog name.
Definition: tdelocale.cpp:83
TDEConfigBase
KDE Configuration Management abstract base class.
Definition: tdeconfigbase.h:70
TDEGlobal::dirs
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Definition: tdeglobal.cpp:58
TDELocale::allLanguagesTwoAlpha
TQStringList allLanguagesTwoAlpha() const
Returns list of all known ISO 639-1 codes.
Definition: tdelocale.cpp:2358
tdelocale.h
TDELocale::setEncoding
bool setEncoding(int mibEnum)
Changes the current encoding.
Definition: tdelocale.cpp:2309
TDELocale::setMonetaryDecimalSymbol
void setMonetaryDecimalSymbol(const TQString &symbol)
Changes the symbol used to identify the decimal pointer for monetary values.
Definition: tdelocale.cpp:2228
TDELocale::MeasureSystem
MeasureSystem
The Metric system will give you information in mm, while the Imperial system will give you informatio...
Definition: tdelocale.h:1011
TDEStandardDirs::findAllResources
TQStringList findAllResources(const char *type, const TQString &filter=TQString::null, bool recursive=false, bool unique=false) const
Tries to find all resources with the specified type.
Definition: kstandarddirs.cpp:679
TDELocale::setCharset
bool setCharset(const TQString &charset) KDE_DEPRECATED
Definition: tdelocale.cpp:2467
TDEGlobal::instance
static TDEInstance * instance()
Returns the global instance.
Definition: tdeglobal.cpp:102
TDELocale::defaultCountry
static TQString defaultCountry()
Returns the name of the default country.
Definition: tdelocale.cpp:2270
TDELocale::setActiveCatalogue
void setActiveCatalogue(const TQString &catalog)
Sets the active catalog for translation lookup.
Definition: tdelocale.cpp:702
TDELocale::charset
TQString charset() const KDE_DEPRECATED
Definition: tdelocale.cpp:2468
TDELocale::insertCatalogue
void insertCatalogue(const TQString &catalog)
Adds another catalog to search for translation lookup.
Definition: tdelocale.cpp:644
TDELocale::setThousandsSeparator
void setThousandsSeparator(const TQString &separator)
Changes the separator used to group digits when formating numbers.
Definition: tdelocale.cpp:2172
TDELocale
TDELocale provides support for country specific stuff like the national language. ...
Definition: tdelocale.h:123
KCalendarSystem::monthStringToInteger
virtual int monthStringToInteger(const TQString &sNum, int &iLength) const
Converts a month literal of a part of a string into a integer starting at the beginning of the string...
Definition: kcalendarsystem.cpp:109
TDELocale::dateFormatShort
TQString dateFormatShort() const
Returns the currently selected short date format.
Definition: tdelocale.cpp:2154
TDELocale::negativeMonetarySignPosition
SignPosition negativeMonetarySignPosition() const
Denotes where to place a negative sign in relation to a monetary value.
Definition: tdelocale.cpp:1096
KCatalogue
This class abstracts a gettext message catalog.
Definition: kcatalogue.h:37
TDELocale::calendarType
TQString calendarType() const
Returns the name of the calendar system that is currently being used by the system.
Definition: tdelocale.cpp:2410
TDELocale::readMoney
double readMoney(const TQString &numStr, bool *ok=0) const
Converts a localized monetary string to a double.
Definition: tdelocale.cpp:1482
KCalendarSystem::month
virtual int month(const TQDate &date) const =0
Gets specific calendar type month for a given gregorian date.
KCalendarSystem::weekDayName
virtual TQString weekDayName(int weekDay, bool shortName=false) const =0
Gets specific calendar type week day name If an invalid week day is specified, TQString::null is retu...
Definition: kcalendarsystem.cpp:119
TDELocale::calendar
const KCalendarSystem * calendar() const
Returns a pointer to the calendar system object.
Definition: tdelocale.cpp:2417
TDELocale::negativePrefixCurrencySymbol
bool negativePrefixCurrencySymbol() const
If and only if the currency symbol precedes a negative value, this will be true.
Definition: tdelocale.cpp:1084
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:320
TDELocale::languagesTwoAlpha
TQStringList languagesTwoAlpha() const
Returns the preferred languages as ISO 639-1 codes.
Definition: tdelocale.cpp:2318
KCalendarSystem::monthNamePossessive
virtual TQString monthNamePossessive(int month, int year, bool shortName=false) const =0
Returns a string containing the possessive form of the month name.
TDELocale::SignPosition
SignPosition
Various positions for where to place the positive or negative sign when they are related to a monetar...
Definition: tdelocale.h:266
TDELocale::splitLocale
static void splitLocale(const TQString &str, TQString &language, TQString &country, TQString &charset)
Returns the parts of the parameter str understood as language setting the format is language_COUNTRY...
Definition: tdelocale.cpp:520
TDELocale::monthNamePossessive
TQString monthNamePossessive(int i, bool shortName=false) const KDE_DEPRECATED
Definition: tdelocale.cpp:601
TDELocale::nounDeclension
bool nounDeclension() const
Use this to determine whether nouns are declined in locale's language.
Definition: tdelocale.cpp:1006
TDELocale::dateMonthNamePossessive
bool dateMonthNamePossessive() const
Use this to determine whether in dates a possessive form of month name is preferred ("of January" rat...
Definition: tdelocale.cpp:1012
TDELocale::setPageSize
void setPageSize(int paperFormat)
Changes the preferred page size when printing.
Definition: tdelocale.cpp:2246
TDELocale::positiveMonetarySignPosition
SignPosition positiveMonetarySignPosition() const
Returns the position of a positive sign in relation to a monetary value.
Definition: tdelocale.cpp:1090
TDELocale::languages
TQString languages() const KDE_DEPRECATED
Definition: tdelocale.cpp:1957
TDELocale::readNumber
double readNumber(const TQString &numStr, bool *ok=0) const
Converts a localized numeric string to a double.
Definition: tdelocale.cpp:1417
TDELocale::thousandsSeparator
TQString thousandsSeparator() const
Returns what the thousands separator should look like ("," or "." etc.) according to the current loca...
Definition: tdelocale.cpp:1036
TDELocale::weekDayName
TQString weekDayName(int i, bool shortName=false) const KDE_DEPRECATED
Definition: tdelocale.cpp:639
TDEInstance::config
TDEConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:210
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
TDELocale::measureSystem
MeasureSystem measureSystem() const
Returns which measuring system we use.
Definition: tdelocale.cpp:2253
TDELocale::setDateFormatShort
void setDateFormatShort(const TQString &format)
Changes the current short date format.
Definition: tdelocale.cpp:2112
TDELocale::decimalSymbol
TQString decimalSymbol() const
Returns what a decimal point should look like ("." or "," etc.) according to the current locale or us...
Definition: tdelocale.cpp:1030
TDELocale::readTime
TQTime readTime(const TQString &str, bool *ok=0) const
Converts a localized time string to a TQTime.
Definition: tdelocale.cpp:1741
TDELocale::formatDate
TQString formatDate(const TQDate &pDate, bool shortFormat=false) const
Returns a string formatted to the current locale's conventions regarding dates.
Definition: tdelocale.cpp:1337
TDELocale::codecForEncoding
TQTextCodec * codecForEncoding() const
Returns the user's preferred encoding.
Definition: tdelocale.cpp:2304
TDELocale::formatTime
TQString formatTime(const TQTime &pTime, bool includeSecs, bool isDuration) const
Returns a string formatted to the current locale's conventions regarding times.
Definition: tdelocale.cpp:1862
TDELocale::setDateMonthNamePossessive
void setDateMonthNamePossessive(bool possessive)
Changes the form of month name used in dates.
Definition: tdelocale.cpp:2118
TDELocale::setNegativeSign
void setNegativeSign(const TQString &sign)
Changes the sign used to identify a negative number.
Definition: tdelocale.cpp:2185
TDELocale::monthName
TQString monthName(int i, bool shortName=false) const KDE_DEPRECATED
Definition: tdelocale.cpp:563
TDELocale::formatDateTime
TQString formatDateTime(const TQDateTime &pDateTime, bool shortFormat=true, bool includeSecs=false) const
Returns a string formated to the current locale's conventions regarding both date and time...
Definition: tdelocale.cpp:1967
TDELocale::negativeSign
TQString negativeSign() const
Returns what a negative sign should look like ("-", etc.) according to the current locale or user set...
Definition: tdelocale.cpp:1066
TDELocale::formatMoney
TQString formatMoney(double num, const TQString &currency=TQString::null, int digits=-1) const
Given a double, converts that to a numeric string containing the localized monetary equivalent...
Definition: tdelocale.cpp:1129
TDELocale::positiveSign
TQString positiveSign() const
Returns what a positive sign should look like ("+", " ", etc.) according to the current locale or use...
Definition: tdelocale.cpp:1060
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KSimpleConfig
KDE Configuration entries.
Definition: ksimpleconfig.h:41
TDELocale::setMonetaryThousandsSeparator
void setMonetaryThousandsSeparator(const TQString &separator)
Changes the separator used to group digits when formating monetary values.
Definition: tdelocale.cpp:2221
TDELocale::encoding
const char * encoding() const
Returns the user's preferred encoding.
Definition: tdelocale.cpp:2275
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
Definition: tdeconfigbase.cpp:221
KCalendarSystemFactory::create
static KCalendarSystem * create(const TQString &calType=TQString::fromLatin1("gregorian"), const TDELocale *locale=0)
Gets specific calendar type number of days in previous month for a given date.
Definition: kcalendarsystemfactory.cpp:44
TDELocale::allCountriesTwoAlpha
TQStringList allCountriesTwoAlpha() const
Returns list of all known country codes.
Definition: tdelocale.cpp:2379
TDELocale::setCurrencySymbol
void setCurrencySymbol(const TQString &symbol)
Changes the current currency symbol.
Definition: tdelocale.cpp:2234
TDELocale::setNegativeMonetarySignPosition
void setNegativeMonetarySignPosition(SignPosition signpos)
Changes the sign position used for negative monetary values.
Definition: tdelocale.cpp:2197
TDELocale::operator=
TDELocale & operator=(const TDELocale &rhs)
Assignment operator.
Definition: tdelocale.cpp:2435
TDELocale::setWeekStartDay
void setWeekStartDay(int day)
Changes how TDELocale defines the first day in week.
Definition: tdelocale.cpp:2139
TDELocale::setTimeFormat
void setTimeFormat(const TQString &format)
Changes the current time format.
Definition: tdelocale.cpp:2124
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:47
TDELocale::setDecimalSymbol
void setDecimalSymbol(const TQString &symbol)
Changes the symbol used to identify the decimal pointer.
Definition: tdelocale.cpp:2166
TDELocale::fracDigits
int fracDigits() const
The number of fractional digits to include in numeric/monetary values (usually 2).
Definition: tdelocale.cpp:1072
TDELocale::readDate
TQDate readDate(const TQString &str, bool *ok=0) const
Converts a localized date string to a TQDate.
Definition: tdelocale.cpp:1596
TDELocale::setPositivePrefixCurrencySymbol
void setPositivePrefixCurrencySymbol(bool prefix)
Changes the position where the currency symbol should be printed for positive monetary values...
Definition: tdelocale.cpp:2203
TDELocale::twoAlphaToLanguageName
TQString twoAlphaToLanguageName(const TQString &code) const
Convert a ISO 639-1 code to a human readable form.
Definition: tdelocale.cpp:2366
TDELocale::setPositiveSign
void setPositiveSign(const TQString &sign)
Changes the sign used to identify a positive number.
Definition: tdelocale.cpp:2179
TDELocale::langLookup
static TQString langLookup(const TQString &fname, const char *rtype="html")
Finds localized resource in resourceDir( rtype ) + + fname.
Definition: tdelocale.cpp:2019
TDELocale::setCountry
bool setCountry(const TQString &country)
Changes the current country.
Definition: tdelocale.cpp:390
KCalendarSystem::setYMD
virtual bool setYMD(TQDate &date, int y, int m, int d) const =0
Changes the date's year, month and day.
TDELocale::setMeasureSystem
void setMeasureSystem(MeasureSystem value)
Changes the preferred measuring system.
Definition: tdelocale.cpp:2259
TDELocale::formatNumber
TQString formatNumber(double num, int precision=-1) const
Given a double, converts that to a numeric string containing the localized numeric equivalent...
Definition: tdelocale.cpp:1195

tdecore

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

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.8
This website is maintained by Timothy Pearson.