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

tdecore

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

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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.8.13
This website is maintained by Timothy Pearson.