~ubuntu-branches/ubuntu/gutsy/kde4libs/gutsy

« back to all changes in this revision

Viewing changes to kdecore/localization/klocale.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-02-21 11:00:12 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070221110012-6kw8khr9knv6lmg1
Tags: 3.80.3-0ubuntu1
New upstream unstable release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- c-basic-offset: 2 -*-
 
2
/* This file is part of the KDE libraries
 
3
    Copyright (C) 1997 Stephan Kulow <coolo@kde.org>
 
4
    Copyright (C) 1999-2003 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
#ifndef KLOCALE_H
 
23
#define KLOCALE_H
 
24
 
 
25
#include <qstring.h>
 
26
#include <kdelibs_export.h>
 
27
#include <klocalizedstring.h>
 
28
#include <kconfig.h>
 
29
 
 
30
class QStringList;
 
31
class QTextCodec;
 
32
class QDate;
 
33
class QTime;
 
34
class QDateTime;
 
35
 
 
36
class KDateTime;
 
37
class KGlobal;
 
38
class KCatalog;
 
39
class KCalendarSystem;
 
40
class KLocalePrivate;
 
41
 
 
42
/**
 
43
 * \file klocale.h
 
44
 */
 
45
 
 
46
/**
 
47
  *
 
48
  * KLocale provides support for country specific stuff like
 
49
  * the national language.
 
50
  *
 
51
  * KLocale supports translating, as well as specifying the format
 
52
  * for numbers, currency, time, and date.
 
53
  *
 
54
  * @author Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>,
 
55
  * Hans Petter Bieker <bieker@kde.org>, Lukas Tinkl <lukas.tinkl@suse.cz>
 
56
  * @short class for supporting locale settings and national language
 
57
  */
 
58
class KDECORE_EXPORT KLocale
 
59
{
 
60
  friend class KGlobal; // for initInstance()
 
61
public:
 
62
  /**
 
63
   * Constructs a KLocale with the given catalog name.
 
64
   * The constructor looks for an entry Locale/Language in the
 
65
   * configuration file.
 
66
   * If no config file is specified, it will also look for languages
 
67
   * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG),
 
68
   * as well as the global configuration file. If KLocale is not able to use
 
69
   * any of the specified languages, the default language (en_US) will be
 
70
   * used.
 
71
   *
 
72
   * If you specify a configuration file, it has to be valid until
 
73
   * the KLocale object is destroyed.
 
74
   *
 
75
   * @param catalog The name of the main language file
 
76
   * @param config The configuration file to use.
 
77
   */
 
78
  explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = KSharedConfig::Ptr());
 
79
 
 
80
  /**
 
81
   * Copy constructor.
 
82
   */
 
83
  KLocale( const KLocale & rhs );
 
84
 
 
85
  /**
 
86
   * Assignment operator.
 
87
   */
 
88
  KLocale& operator= ( const KLocale & rhs );
 
89
 
 
90
  /**
 
91
   * Destructor.
 
92
   */
 
93
  ~KLocale();
 
94
 
 
95
  /**
 
96
   * Raw translation from message catalogs.
 
97
   *
 
98
   * Never use this directly to get message translations. See i18n* and ki18n*
 
99
   * calls related to KLocalizedString.
 
100
   *
 
101
   * @param msg the message. Must not be null. Must be UTF-8 encoded.
 
102
   * @param lang language in which the translation was found. If no translation
 
103
   *             was found, KLocale::defaultLanguage() is reported. If null,
 
104
   *             the language is not reported.
 
105
   * @param trans raw translation, or original if not found. If no translation
 
106
   *              was found, original message is reported. If null, the
 
107
   *              translation is not reported.
 
108
   *
 
109
   * @see KLocalizedString
 
110
   */
 
111
  void translateRaw(const char* msg,
 
112
                    QString *lang, QString *trans) const;
 
113
 
 
114
  /**
 
115
   * Raw translation from message catalogs, with given context.
 
116
   * Context + message are used as the lookup key in catalogs.
 
117
   *
 
118
   * Never use this directly to get message translations. See i18n* and ki18n*
 
119
   * calls related to KLocalizedString.
 
120
   *
 
121
   * @param ctxt the context. Must not be null. Must be UTF-8 encoded.
 
122
   * @param msg the message. Must not be null. Must be UTF-8 encoded.
 
123
   * @param lang language in which the translation was found. If no translation
 
124
   *             was found, KLocale::defaultLanguage() is reported. If null,
 
125
   *             the language is not reported.
 
126
   * @param trans raw translation, or original if not found. If no translation
 
127
   *              was found, original message is reported. If null, the
 
128
   *              translation is not reported.
 
129
   *
 
130
   * @see KLocalizedString
 
131
   */
 
132
  void translateRaw(const char *ctxt, const char *msg,
 
133
                    QString *lang, QString *trans) const;
 
134
 
 
135
  /**
 
136
   * Raw translation from message catalogs, with given singular/plural form.
 
137
   * Singular form is used as the lookup key in catalogs.
 
138
   *
 
139
   * Never use this directly to get message translations. See i18n* and ki18n*
 
140
   * calls related to KLocalizedString.
 
141
   *
 
142
   * @param singular the singular form. Must not be null. Must be UTF-8 encoded.
 
143
   * @param plural the plural form. Must not be null. Must be UTF-8 encoded.
 
144
   * @param n number on which the forms are decided.
 
145
   * @param lang language in which the translation was found. If no translation
 
146
   *             was found, KLocale::defaultLanguage() is reported. If null,
 
147
   *             the language is not reported.
 
148
   * @param trans raw translation, or original if not found. If no translation
 
149
   *              was found, original message is reported (either plural or
 
150
   *              singular, as determined by @p n ). If null, the
 
151
   *              translation is not reported.
 
152
   *
 
153
   * @see KLocalizedString
 
154
   */
 
155
  void translateRaw(const char *singular, const char *plural,  unsigned long n,
 
156
                    QString *lang, QString *trans) const;
 
157
 
 
158
  /**
 
159
   * Raw translation from message catalogs, with given context and
 
160
   * singular/plural form.
 
161
   * Context + singular form is used as the lookup key in catalogs.
 
162
   *
 
163
   * Never use this directly to get message translations. See i18n* and ki18n*
 
164
   * calls related to KLocalizedString.
 
165
   *
 
166
   * @param ctxt the context. Must not be null. Must be UTF-8 encoded.
 
167
   * @param singular the singular form. Must not be null. Must be UTF-8 encoded.
 
168
   * @param plural the plural form. Must not be null. Must be UTF-8 encoded.
 
169
   * @param n number on which the forms are decided.
 
170
   * @param lang language in which the translation was found. If no translation
 
171
   *             was found, KLocale::defaultLanguage() is reported. If null,
 
172
   *             the language is not reported.
 
173
   * @param trans raw translation, or original if not found. If no translation
 
174
   *              was found, original message is reported (either plural or
 
175
   *              singular, as determined by @p n ). If null, the
 
176
   *              translation is not reported.
 
177
   *
 
178
   * @see KLocalizedString
 
179
   */
 
180
  void translateRaw(const char *ctxt, const char *singular, const char *plural,
 
181
                    unsigned long n, QString *lang, QString *trans) const;
 
182
 
 
183
  /**
 
184
   * Changes the current encoding.
 
185
   *
 
186
   * @param mibEnum The mib of the preferred codec
 
187
   *
 
188
   * @return True on success.
 
189
   */
 
190
  bool setEncoding(int mibEnum);
 
191
 
 
192
  /**
 
193
   * Changes the current language. The current language will be left
 
194
   * unchanged if failed. It will force a reload of the country specific
 
195
   * configuration as well.
 
196
   *
 
197
   * @param language The language code.
 
198
   *
 
199
   * @return True on success.
 
200
   */
 
201
  bool setLanguage(const QString & language);
 
202
 
 
203
  /**
 
204
   * Changes the list of prefed languages for the locale. The first valid
 
205
   * language in the list will be used, or the default (en_US) language
 
206
   * will be used if non of the specified languages were available.
 
207
   *
 
208
   * @param languages The list of language codes.
 
209
   *
 
210
   * @return True if one of the specified languages were used.
 
211
   */
 
212
  bool setLanguage(const QStringList & languages);
 
213
 
 
214
  /**
 
215
   * Changes the current country. The current country will be left
 
216
   * unchanged if failed. It will force a reload of the country specific
 
217
   * configuration.
 
218
   *
 
219
   * @param country The ISO 3166 country code.
 
220
   *
 
221
   * @return True on success.
 
222
   */
 
223
  bool setCountry(const QString & country);
 
224
 
 
225
  /**
 
226
   * Various positions for where to place the positive or negative
 
227
   * sign when they are related to a monetary value.
 
228
   */
 
229
  enum SignPosition {
 
230
    /**
 
231
     * Put parantheses around the quantity, e.g. "$ (217)"
 
232
     */
 
233
    ParensAround = 0,
 
234
    /**
 
235
     * Prefix the quantity with the sign, e.g. "$ -217"
 
236
     */
 
237
    BeforeQuantityMoney = 1,
 
238
    /**
 
239
     * Suffix the quanitity with the sign, e.g. "$ 217-"
 
240
     */
 
241
    AfterQuantityMoney = 2,
 
242
    /**
 
243
     * Prefix the currency symbol with the sign, e.g. "-$ 217"
 
244
     */
 
245
    BeforeMoney = 3,
 
246
    /**
 
247
     * Suffix the currency symbol with the sign, e.g. "$- 217"
 
248
     */
 
249
    AfterMoney = 4
 
250
  };
 
251
 
 
252
  /**
 
253
   * Returns what a decimal point should look like ("." or "," etc.)
 
254
   * according to the current locale or user settings.
 
255
   *
 
256
   * @return The decimal symbol used by locale.
 
257
   */
 
258
  QString decimalSymbol() const;
 
259
 
 
260
  /**
 
261
   * Returns what the thousands separator should look
 
262
   * like ("," or "." etc.)
 
263
   * according to the current locale or user settings.
 
264
   *
 
265
   * @return The thousands separator used by locale.
 
266
   */
 
267
  QString thousandsSeparator() const;
 
268
 
 
269
  /**
 
270
   * Returns what the symbol denoting currency in the current locale
 
271
   * as as defined by user settings should look like.
 
272
   *
 
273
   * @return The default currency symbol used by locale.
 
274
   */
 
275
  QString currencySymbol() const;
 
276
 
 
277
  /**
 
278
   * Returns what a decimal point should look like ("." or "," etc.)
 
279
   * for monetary values, according to the current locale or user
 
280
   * settings.
 
281
   *
 
282
   * @return The monetary decimal symbol used by locale.
 
283
   */
 
284
  QString monetaryDecimalSymbol() const;
 
285
 
 
286
  /**
 
287
   * Returns what a thousands separator for monetary values should
 
288
   * look like ("," or " " etc.) according to the current locale or
 
289
   * user settings.
 
290
   *
 
291
   * @return The monetary thousands separator used by locale.
 
292
   */
 
293
  QString monetaryThousandsSeparator() const;
 
294
 
 
295
  /**
 
296
   * Returns what a positive sign should look like ("+", " ", etc.)
 
297
   * according to the current locale or user settings.
 
298
   *
 
299
   * @return The positive sign used by locale.
 
300
   */
 
301
  QString positiveSign() const;
 
302
 
 
303
  /**
 
304
   * Returns what a negative sign should look like ("-", etc.)
 
305
   * according to the current locale or user settings.
 
306
   *
 
307
   * @return The negative sign used by locale.
 
308
   */
 
309
  QString negativeSign() const;
 
310
 
 
311
  /**
 
312
   * The number of fractional digits to include in numeric/monetary
 
313
   * values (usually 2).
 
314
   *
 
315
   * @return Default number of fractional digits used by locale.
 
316
   */
 
317
  int fracDigits() const;
 
318
 
 
319
  /**
 
320
   * If and only if the currency symbol precedes a positive value,
 
321
   * this will be true.
 
322
   *
 
323
   * @return Where to print the currency symbol for positive numbers.
 
324
   */
 
325
  bool positivePrefixCurrencySymbol() const;
 
326
 
 
327
  /**
 
328
   * If and only if the currency symbol precedes a negative value,
 
329
   * this will be true.
 
330
   *
 
331
   * @return True if the currency symbol precedes negative numbers.
 
332
   */
 
333
  bool negativePrefixCurrencySymbol() const;
 
334
 
 
335
  /**
 
336
   * Returns the position of a positive sign in relation to a
 
337
   * monetary value.
 
338
   *
 
339
   * @return Where/how to print the positive sign.
 
340
   * @see SignPosition
 
341
   */
 
342
  SignPosition positiveMonetarySignPosition() const;
 
343
 
 
344
  /**
 
345
   * Denotes where to place a negative sign in relation to a
 
346
   * monetary value.
 
347
   *
 
348
   * @return Where/how to print the negative sign.
 
349
   * @see SignPosition
 
350
   */
 
351
  SignPosition negativeMonetarySignPosition() const;
 
352
 
 
353
  /**
 
354
   * Given a double, converts that to a numeric string containing
 
355
   * the localized monetary equivalent.
 
356
   *
 
357
   * e.g. given 123456, return "$ 123,456.00".
 
358
   *
 
359
   * @param num The number we want to format
 
360
   * @param currency The currency symbol you want.
 
361
   * @param digits Number of fractional digits, or -1 for the default
 
362
   *               value
 
363
   *
 
364
   * @return The number of money as a localized string
 
365
   * @see fracDigits()
 
366
   */
 
367
  QString formatMoney(double num,
 
368
                      const QString & currency = QString(),
 
369
                      int digits = -1) const;
 
370
 
 
371
  /**
 
372
   * Given a double, converts that to a numeric string containing
 
373
   * the localized numeric equivalent.
 
374
   *
 
375
   * e.g. given 123456.78F, return "123,456.78" (for some European country).
 
376
   * If precision isn't specified, 2 is used.
 
377
   *
 
378
   * This function is a wrapper that is provided for convenience.
 
379
   *
 
380
   * @param num The number to convert
 
381
   * @param precision Number of fractional digits used.
 
382
   *
 
383
   * @return The number as a localized string
 
384
   * @see formatNumber(const QString, bool, int)
 
385
   */
 
386
  QString formatNumber(double num, int precision = -1) const;
 
387
 
 
388
  /**
 
389
   * Given a string representing a number, converts that to a numeric
 
390
   * string containing the localized numeric equivalent.
 
391
   *
 
392
   * e.g. given 123456.78F, return "123,456.78" (for some European country).
 
393
   *
 
394
   * @param numStr The number to format, as a string.
 
395
   * @param round Round fractional digits. (default true)
 
396
   * @param precision Number of fractional digits used for rounding. Unused if round=false. (default 2)
 
397
   *
 
398
   * @return The number as a localized string
 
399
   */
 
400
  QString formatNumber(const QString &numStr, bool round=true, int precision=2) const;
 
401
 
 
402
  /**
 
403
   * Given an integer, converts that to a numeric string containing
 
404
   * the localized numeric equivalent.
 
405
   *
 
406
   * e.g. given 123456L, return "123,456" (for some European country).
 
407
   *
 
408
   * @param num The number to convert
 
409
   *
 
410
   * @return The number as a localized string
 
411
   */
 
412
  QString formatLong(long num) const;
 
413
 
 
414
  /**
 
415
   * Converts @p size from bytes to the string representation using the
 
416
   * IEC 60027-2 standard
 
417
   *
 
418
   * Example:
 
419
   * formatByteSize(1024) returns "1.0 KiB"
 
420
   *
 
421
   * @param  size  size in bytes
 
422
   * @return converted size as a string - e.g. 123.4 KiB , 12.0 MiB
 
423
   */
 
424
  QString formatByteSize( double size ) const;
 
425
 
 
426
  /**
 
427
   * Given a number of milliseconds, converts that to a string containing
 
428
   * the localized equivalent
 
429
   *
 
430
   * e.g. given formatDuration(60000), returns "1.0 minutes"
 
431
   *
 
432
   * @param mSec Time duration in milliseconds
 
433
   * @return converted duration as a string - e.g. "5.5 seconds" "23.0 minutes"
 
434
   */
 
435
  QString formatDuration( unsigned long mSec) const;
 
436
  /**
 
437
   * Use this to determine whether nouns are declined in
 
438
   * locale's language. This property should remain
 
439
   * read-only (no setter function)
 
440
   *
 
441
   * @return If nouns are declined
 
442
   */
 
443
   bool nounDeclension() const;
 
444
 
 
445
  /**
 
446
   * Returns a string formatted to the current locale's conventions
 
447
   * regarding dates.
 
448
   *
 
449
   * @param pDate The date to be formatted.
 
450
   * @param shortFormat True for non text dates.
 
451
   *
 
452
   * @return The date as a string
 
453
   */
 
454
  QString formatDate(const QDate &pDate, bool shortFormat = false) const;
 
455
 
 
456
  /**
 
457
   * Use this to determine whether in dates a possessive form of month
 
458
   * name is preferred ("of January" rather than "January")
 
459
   *
 
460
   * @return If possessive form should be used
 
461
  */
 
462
  bool dateMonthNamePossessive() const;
 
463
 
 
464
  /**
 
465
   * Returns a string formatted to the current locale's conventions
 
466
   * regarding times.
 
467
   *
 
468
   * @param pTime The time to be formatted.
 
469
   * @param includeSecs if true, seconds are included in the output,
 
470
   *        otherwise only hours and minutes are formatted.
 
471
   * @param isDuration if true, the given time is a duration, not a clock time.
 
472
   * This means "am/pm" shouldn't be displayed.
 
473
   *
 
474
   * @return The time as a string
 
475
   */
 
476
  QString formatTime(const QTime &pTime, bool includeSecs = false,
 
477
                     bool isDuration = false) const;
 
478
 
 
479
  /**
 
480
   * Use this to determine if the user wants a 12 hour clock.
 
481
   *
 
482
   * @return If the user wants 12h clock
 
483
   */
 
484
  bool use12Clock() const;
 
485
 
 
486
  /**
 
487
   * Use this to determine which day is the first day of the week.
 
488
   *
 
489
   * @return an integer (Monday=1..Sunday=7)
 
490
   */
 
491
  int weekStartDay() const;
 
492
 
 
493
  /**
 
494
   * Returns a pointer to the calendar system object.
 
495
   *
 
496
   * @return the current calendar system instance
 
497
   */
 
498
  const KCalendarSystem * calendar() const;
 
499
 
 
500
  /**
 
501
   * Returns the name of the calendar system that is currently being
 
502
   * used by the system.
 
503
   *
 
504
   * @return the name of the calendar system
 
505
   */
 
506
  QString calendarType() const;
 
507
 
 
508
  /**
 
509
   * Changes the current calendar system to the calendar specified.
 
510
   * Currently "gregorian" and "hijri" are supported. If the calendar
 
511
   * system specified is not found, gregorian will be used.
 
512
   *
 
513
   * @param calendarType the name of the calendar type
 
514
   */
 
515
  void setCalendar(const QString & calendarType);
 
516
 
 
517
  /**
 
518
   * Returns a string formatted to the current locale's conventions
 
519
   * regarding both date and time.
 
520
   *
 
521
   * @param pDateTime the date and time to be formatted
 
522
   * @param shortFormat using the short date format
 
523
   * @param includeSecs include the seconds value
 
524
   *
 
525
   * @return The date and time as a string
 
526
   */
 
527
  QString formatDateTime(const QDateTime &pDateTime,
 
528
                         bool shortFormat = true,
 
529
                         bool includeSecs = false) const;
 
530
 
 
531
  /**
 
532
   * Returns a string formatted to the current locale's conventions
 
533
   * regarding both date and time.
 
534
   *
 
535
   * @param pDateTime the date and time to be formatted
 
536
   * @param shortFormat using the short date format
 
537
   * @param includeSecs include the seconds value
 
538
   * @param includeTimeZone include a time zone string
 
539
   *
 
540
   * @return The date and time as a string
 
541
   */
 
542
  QString formatDateTime(const KDateTime &pDateTime,
 
543
                         bool shortFormat = true,
 
544
                         bool includeSecs = false,
 
545
                         bool includeTimeZone = false) const;
 
546
 
 
547
  /**
 
548
   * Converts a localized monetary string to a double.
 
549
   *
 
550
   * @param numStr the string we want to convert.
 
551
   * @param ok the boolean that is set to false if it's not a number.
 
552
   *           If @p ok is 0, it will be ignored
 
553
   *
 
554
   * @return The string converted to a double
 
555
   */
 
556
  double readMoney(const QString &numStr, bool * ok = 0) const;
 
557
 
 
558
  /**
 
559
   * Converts a localized numeric string to a double.
 
560
   *
 
561
   * @param numStr the string we want to convert.
 
562
   * @param ok the boolean that is set to false if it's not a number.
 
563
   *           If @p ok is 0, it will be ignored
 
564
   *
 
565
   * @return The string converted to a double
 
566
   */
 
567
  double readNumber(const QString &numStr, bool * ok = 0) const;
 
568
 
 
569
  /**
 
570
   * Converts a localized date string to a QDate.
 
571
   * The bool pointed by ok will be invalid if the date entered was not valid.
 
572
   *
 
573
   * @param str the string we want to convert.
 
574
   * @param ok the boolean that is set to false if it's not a valid date.
 
575
   *           If @p ok is 0, it will be ignored
 
576
   *
 
577
   * @return The string converted to a QDate
 
578
   */
 
579
  QDate readDate(const QString &str, bool* ok = 0) const;
 
580
 
 
581
  /**
 
582
   * Converts a localized date string to a QDate, using the specified format.
 
583
   * You will usually not want to use this method.
 
584
   */
 
585
  QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
 
586
 
 
587
  /**
 
588
   * Flags for readDate()
 
589
   */
 
590
  enum ReadDateFlags {
 
591
      NormalFormat = 1,  ///< Only accept a date string in normal (long) format
 
592
      ShortFormat = 2    ///< Only accept a date string in short format
 
593
  };
 
594
 
 
595
  /**
 
596
   * Converts a localized date string to a QDate.
 
597
   * This method is stricter than readDate(str,&ok): it will either accept
 
598
   * a date in full format or a date in short format, depending on @p flags.
 
599
   *
 
600
   * @param str the string we want to convert.
 
601
   * @param flags whether the date string is to be in full format or in short format.
 
602
   * @param ok the boolean that is set to false if it's not a valid date.
 
603
   *           If @p ok is 0, it will be ignored
 
604
   *
 
605
   * @return The string converted to a QDate
 
606
   */
 
607
  QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const;
 
608
 
 
609
  /**
 
610
   * Converts a localized time string to a QTime.
 
611
   * This method will try to parse it with seconds, then without seconds.
 
612
   * The bool pointed to by @p ok will be set to false if the time entered was
 
613
   * not valid.
 
614
   *
 
615
   * @param str the string we want to convert.
 
616
   * @param ok the boolean that is set to false if it's not a valid time.
 
617
   *           If @p ok is 0, it will be ignored
 
618
   *
 
619
   * @return The string converted to a QTime
 
620
   */
 
621
  QTime readTime(const QString &str, bool* ok = 0) const;
 
622
 
 
623
  /**
 
624
   * Flags for readTime()
 
625
   */
 
626
  enum ReadTimeFlags {
 
627
      WithSeconds = 0,    ///< Only accept a time string with seconds. Default (no flag set)
 
628
      WithoutSeconds = 1  ///< Only accept a time string without seconds.
 
629
  }; // (maybe use this enum as a bitfield, if adding independent features?)
 
630
  /**
 
631
   * Converts a localized time string to a QTime.
 
632
   * This method is stricter than readTime(str,&ok): it will either accept
 
633
   * a time with seconds or a time without seconds.
 
634
   * Use this method when the format is known by the application.
 
635
   *
 
636
   * @param str the string we want to convert.
 
637
   * @param flags whether the time string is expected to contain seconds or not.
 
638
   * @param ok the boolean that is set to false if it's not a valid time.
 
639
   *           If @p ok is 0, it will be ignored
 
640
   *
 
641
   * @return The string converted to a QTime
 
642
   */
 
643
  QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const;
 
644
 
 
645
  /**
 
646
   * Returns the language used by this object. The domain AND the
 
647
   * library translation must be available in this language.
 
648
   * defaultLanguage() is returned by default, if no other available.
 
649
   *
 
650
   * @return The currently used language.
 
651
   */
 
652
  QString language() const;
 
653
 
 
654
  /**
 
655
   * Returns the country code of the country where the user lives.
 
656
   * defaultCountry() is returned by default, if no other available.
 
657
   *
 
658
   * @return The country code for the user.
 
659
   */
 
660
  QString country() const;
 
661
 
 
662
  /**
 
663
   * Returns the preferred languages as ISO 639-1 codes. This means
 
664
   * that information about country is removed. If the internal language
 
665
   * code might be represented by more than one 639-1 code, they will all be
 
666
   * listed (but only once).
 
667
   *
 
668
   * If the selected languages are "nn, nb, pt_BR", you will get:
 
669
   * "nn, no, nb, pt".
 
670
   *
 
671
   * @return List of language codes
 
672
   *
 
673
   * @see languageList
 
674
   */
 
675
  QStringList languagesTwoAlpha() const;
 
676
 
 
677
  /**
 
678
   * Returns the languages selected by user. The codes returned here is the
 
679
   * internal language codes.
 
680
   *
 
681
   * @return List of language codes
 
682
   *
 
683
   * @see languagesTwoAlpha
 
684
   */
 
685
  QStringList languageList() const;
 
686
 
 
687
  /**
 
688
   * Returns the user's preferred encoding.
 
689
   *
 
690
   * @return The name of the preferred encoding
 
691
   *
 
692
   * @see codecForEncoding
 
693
   * @see encodingMib
 
694
   */
 
695
  const QByteArray encoding() const;
 
696
 
 
697
  /**
 
698
   * Returns the user's preferred encoding.
 
699
   *
 
700
   * @return The Mib of the preferred encoding
 
701
   *
 
702
   * @see encoding
 
703
   * @see codecForEncoding
 
704
   */
 
705
  int encodingMib() const;
 
706
  /**
 
707
   * Returns the user's preferred encoding. Should never be NULL.
 
708
   *
 
709
   * @return The codec for the preferred encoding
 
710
   *
 
711
   * @see encoding
 
712
   * @see encodingMib
 
713
   */
 
714
  QTextCodec * codecForEncoding() const;
 
715
 
 
716
  /**
 
717
   * Returns the file encoding.
 
718
   *
 
719
   * @return The Mib of the file encoding
 
720
   *
 
721
   * @see QFile::encodeName
 
722
   * @see QFile::decodeName
 
723
   */
 
724
  int fileEncodingMib() const;
 
725
 
 
726
  /**
 
727
   * Changes the current date format.
 
728
   *
 
729
   * The format of the date is a string which contains variables that will
 
730
   * be replaced:
 
731
   * @li %Y with the century (e.g. "19" for "1984")
 
732
   * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
 
733
   * @li %n with the month (January="1", December="12")
 
734
   * @li %m with the month with two digits (January="01", December="12")
 
735
   * @li %e with the day of the month (e.g. "1" on the first of march)
 
736
   * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
 
737
   * @li %b with the short form of the month (e.g. "Jan" for January)
 
738
   * @li %B with the long form of the month (e.g. "January")
 
739
   * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
 
740
   * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
 
741
   *
 
742
   * Everything else in the format string will be taken as is.
 
743
   * For example, March 20th 1989 with the format "%y:%m:%d" results
 
744
   * in "89:03:20".
 
745
   *
 
746
   * @param format The new date format
 
747
   */
 
748
  void setDateFormat(const QString & format);
 
749
  /**
 
750
   * Changes the current short date format.
 
751
   *
 
752
   * The format of the date is a string which contains variables that will
 
753
   * be replaced:
 
754
   * @li %Y with the century (e.g. "19" for "1984")
 
755
   * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
 
756
   * @li %n with the month (January="1", December="12")
 
757
   * @li %m with the month with two digits (January="01", December="12")
 
758
   * @li %e with the day of the month (e.g. "1" on the first of march)
 
759
   * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
 
760
   * @li %b with the short form of the month (e.g. "Jan" for January)
 
761
   * @li %B with the long form of the month (e.g. "January")
 
762
   * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
 
763
   * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
 
764
   *
 
765
   * Everything else in the format string will be taken as is.
 
766
   * For example, March 20th 1989 with the format "%y:%m:%d" results
 
767
   * in "89:03:20".
 
768
   *
 
769
   * @param format The new short date format
 
770
   */
 
771
  void setDateFormatShort(const QString & format);
 
772
  /**
 
773
   * Changes the form of month name used in dates.
 
774
   *
 
775
   * @param possessive True if possessive forms should be used
 
776
   */
 
777
  void setDateMonthNamePossessive(bool possessive);
 
778
  /**
 
779
   * Changes the current time format.
 
780
   *
 
781
   * The format of the time is string a which contains variables that will
 
782
   * be replaced:
 
783
   * @li %H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05")
 
784
   * @li %k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5")
 
785
   * @li %I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05")
 
786
   * @li %l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5")
 
787
   * @li %M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02")
 
788
   * @li %S with the seconds with 2 digits  (e.g. the minute of 07:02:09 is "09")
 
789
   * @li %p with pm or am (e.g. 17.00 is "pm", 05.00 is "am")
 
790
   *
 
791
   * Everything else in the format string will be taken as is.
 
792
   * For example, 5.23pm with the format "%H:%M" results
 
793
   * in "17:23".
 
794
   *
 
795
   * @param format The new time format
 
796
   */
 
797
  void setTimeFormat(const QString & format);
 
798
 
 
799
 
 
800
  /**
 
801
   * Changes how KLocale defines the first day in week.
 
802
   *
 
803
   * @param day first day of the week (Monday=1..Sunday=7) as integer
 
804
   */
 
805
  void setWeekStartDay(int day);
 
806
  /**
 
807
   * Returns the currently selected date format.
 
808
   *
 
809
   * @return Current date format.
 
810
   * @see setDateFormat()
 
811
   */
 
812
  QString dateFormat() const;
 
813
  /**
 
814
   * Returns the currently selected short date format.
 
815
   *
 
816
   * @return Current short date format.
 
817
   * @see setDateFormatShort()
 
818
   */
 
819
  QString dateFormatShort() const;
 
820
  /**
 
821
   * Returns the currently selected time format.
 
822
   *
 
823
   * @return Current time format.
 
824
   * @see setTimeFormat()
 
825
   */
 
826
  QString timeFormat() const;
 
827
 
 
828
  /**
 
829
   * Changes the symbol used to identify the decimal pointer.
 
830
   *
 
831
   * @param symbol The new decimal symbol.
 
832
   */
 
833
  void setDecimalSymbol(const QString & symbol);
 
834
  /**
 
835
   * Changes the separator used to group digits when formating numbers.
 
836
   *
 
837
   * @param separator The new thousands separator.
 
838
   */
 
839
  void setThousandsSeparator(const QString & separator);
 
840
  /**
 
841
   * Changes the sign used to identify a positive number. Normally this is
 
842
   * left blank.
 
843
   *
 
844
   * @param sign Sign used for positive numbers.
 
845
   */
 
846
  void setPositiveSign(const QString & sign);
 
847
  /**
 
848
   * Changes the sign used to identify a negative number.
 
849
   *
 
850
   * @param sign Sign used for negative numbers.
 
851
   */
 
852
  void setNegativeSign(const QString & sign);
 
853
  /**
 
854
   * Changes the sign position used for positive monetary values.
 
855
   *
 
856
   * @param signpos The new sign position
 
857
   */
 
858
  void setPositiveMonetarySignPosition(SignPosition signpos);
 
859
  /**
 
860
   * Changes the sign position used for negative monetary values.
 
861
   *
 
862
   * @param signpos The new sign position
 
863
   */
 
864
  void setNegativeMonetarySignPosition(SignPosition signpos);
 
865
  /**
 
866
   * Changes the position where the currency symbol should be printed for
 
867
   * positive monetary values.
 
868
   *
 
869
   * @param prefix True if the currency symbol should be prefixed instead of
 
870
   * postfixed
 
871
   */
 
872
  void setPositivePrefixCurrencySymbol(bool prefix);
 
873
  /**
 
874
   * Changes the position where the currency symbol should be printed for
 
875
   * negative monetary values.
 
876
   *
 
877
   * @param prefix True if the currency symbol should be prefixed instead of
 
878
   * postfixed
 
879
   */
 
880
  void setNegativePrefixCurrencySymbol(bool prefix);
 
881
  /**
 
882
   * Changes the number of digits used when formating numbers.
 
883
   *
 
884
   * @param digits The default number of digits to use.
 
885
   */
 
886
  void setFracDigits(int digits);
 
887
  /**
 
888
   * Changes the separator used to group digits when formating monetary values.
 
889
   *
 
890
   * @param separator The new thousands separator.
 
891
   */
 
892
  void setMonetaryThousandsSeparator(const QString & separator);
 
893
  /**
 
894
   * Changes the symbol used to identify the decimal pointer for monetary
 
895
   * values.
 
896
   *
 
897
   * @param symbol The new decimal symbol.
 
898
   */
 
899
  void setMonetaryDecimalSymbol(const QString & symbol);
 
900
  /**
 
901
   * Changes the current currency symbol.
 
902
   *
 
903
   * @param symbol The new currency symbol
 
904
   */
 
905
  void setCurrencySymbol(const QString & symbol);
 
906
 
 
907
  /**
 
908
   * Returns the preferred page size for printing.
 
909
   *
 
910
   * @return The preferred page size, cast it to QPrinter::PageSize
 
911
   */
 
912
  int pageSize() const;
 
913
 
 
914
  /**
 
915
   * Changes the preferred page size when printing.
 
916
   *
 
917
   * @param paperFormat the new preferred page size in the format QPrinter::PageSize
 
918
   */
 
919
  void setPageSize(int paperFormat);
 
920
 
 
921
  /**
 
922
   * The Metric system will give you information in mm, while the
 
923
   * Imperial system will give you information in inches.
 
924
   */
 
925
  enum MeasureSystem {
 
926
    Metric,    ///< Metric system (used e.g. in Europe)
 
927
    Imperial   ///< Imperial system (used e.g. in the United States)
 
928
  };
 
929
 
 
930
  /**
 
931
   * Returns which measuring system we use.
 
932
   *
 
933
   * @return The preferred measuring system
 
934
   */
 
935
  MeasureSystem measureSystem() const;
 
936
 
 
937
  /**
 
938
   * Changes the preferred measuring system.
 
939
   *
 
940
   * @return value The preferred measuring system
 
941
   */
 
942
  void setMeasureSystem(MeasureSystem value);
 
943
 
 
944
  /**
 
945
   * Adds another catalog to search for translation lookup.
 
946
   * This function is useful for extern libraries and/or code,
 
947
   * that provide there own messages.
 
948
   *
 
949
   * If the catalog does not exist for the chosen language,
 
950
   * it will be ignored and en_US will be used.
 
951
   *
 
952
   * @param catalog The catalog to add.
 
953
   */
 
954
  void insertCatalog(const QString& catalog);
 
955
 
 
956
  /**
 
957
   * Removes a catalog for translation lookup.
 
958
   * @param catalog The catalog to remove.
 
959
   * @see insertCatalog()
 
960
   */
 
961
  void removeCatalog(const QString &catalog);
 
962
 
 
963
  /**
 
964
   * Sets the active catalog for translation lookup.
 
965
   * @param catalog The catalog to activate.
 
966
   */
 
967
  void setActiveCatalog(const QString &catalog);
 
968
 
 
969
  /**
 
970
   * Translates a message as a QTranslator is supposed to.
 
971
   * The parameters are similar to i18n(), but the result
 
972
   * value has other semantics (it can be QString())
 
973
   **/
 
974
  QString translateQt(const char *context,
 
975
                      const char *sourceText,
 
976
                      const char *message) const;
 
977
 
 
978
  /**
 
979
   * Returns list of all known ISO 639-1 codes.
 
980
   * @return a list of all language codes
 
981
   */
 
982
  QStringList allLanguagesTwoAlpha() const;
 
983
 
 
984
  /**
 
985
   * Convert a ISO 639-1 code to a human readable form.
 
986
   * @param code the language ISO 639-1 code
 
987
   * @return the human readable form
 
988
   */
 
989
  QString twoAlphaToLanguageName(const QString &code) const;
 
990
 
 
991
  /**
 
992
   * Returns list of all known country codes.
 
993
   * @return a list of all country codes
 
994
   */
 
995
  QStringList allCountriesTwoAlpha() const;
 
996
 
 
997
  /**
 
998
   * Convert a country code to a human readable form.
 
999
   * @param code the country code
 
1000
   * @return the human readable form of the country name
 
1001
   */
 
1002
  QString twoAlphaToCountryName(const QString &code) const;
 
1003
 
 
1004
  /**
 
1005
   * Returns the parts of the parameter str understood as language setting
 
1006
   * the format is language_COUNTRY.charset
 
1007
   *
 
1008
   * @param str The string to split.
 
1009
   * @param language This will be set to the language part of the string.
 
1010
   * @param country This will be set to the country part of the string.
 
1011
   * @param charset This will be set to the charset part of the string.
 
1012
   */
 
1013
  static void splitLocale(const QString & str,
 
1014
                          QString & language,
 
1015
                          QString & country,
 
1016
                          QString & charset);
 
1017
 
 
1018
  /**
 
1019
   * Use this as main catalog for *all* KLocales, if not the appname
 
1020
   * will be used. This function is best to be the very first instruction
 
1021
   * in your program's main function as it only has an effect before the
 
1022
   * first KLocale object is created.
 
1023
   *
 
1024
   * @param catalog Catalog to override all other main Catalogs.
 
1025
   */
 
1026
  static void setMainCatalog(const char *catalog);
 
1027
 
 
1028
  /**
 
1029
   * Finds localized resource in resourceDir( rtype ) + \<lang> + fname.
 
1030
   *
 
1031
   * @param fname relative path to find
 
1032
   * @param rtype resource type to use
 
1033
   */
 
1034
  static QString langLookup(const QString &fname, const char *rtype = "html");
 
1035
 
 
1036
  /**
 
1037
   * Returns the name of the internal language.
 
1038
   *
 
1039
   * @return Name of the default language
 
1040
   */
 
1041
  static QString defaultLanguage();
 
1042
 
 
1043
  /**
 
1044
   * Returns the name of the default country.
 
1045
   *
 
1046
   * @return Name of the default country
 
1047
   */
 
1048
  static QString defaultCountry();
 
1049
 
 
1050
 
 
1051
  /**
 
1052
   * @internal Called from KConfigBackend to initialize language.
 
1053
   */
 
1054
  static QString _initLanguage(KConfigBase *config);
 
1055
 
 
1056
 
 
1057
protected:
 
1058
  /**
 
1059
   * @internal Creates a KLocale object for KGlobal and inits the locale
 
1060
   * pointer.
 
1061
   */
 
1062
  static void initInstance();
 
1063
 
 
1064
private:
 
1065
  KLocalePrivate * const d;
 
1066
};
 
1067
 
 
1068
#endif