summaryrefslogtreecommitdiffabout
path: root/microkde/kdecore/klocale_new.h
Unidiff
Diffstat (limited to 'microkde/kdecore/klocale_new.h') (more/less context) (ignore whitespace changes)
-rw-r--r--microkde/kdecore/klocale_new.h1224
1 files changed, 1224 insertions, 0 deletions
diff --git a/microkde/kdecore/klocale_new.h b/microkde/kdecore/klocale_new.h
new file mode 100644
index 0000000..777c0bd
--- a/dev/null
+++ b/microkde/kdecore/klocale_new.h
@@ -0,0 +1,1224 @@
1#ifndef MINIKDE_KLOCALE_H
2#define MINIKDE_KLOCALE_H
3
4#include <qstring.h>
5#include <qstringlist.h>
6#include <qdict.h>
7
8class QStringList;
9class QTextCodec;
10class QDate;
11class QTime;
12class QDateTime;
13
14class KGlobal;
15class KConfig;
16class KConfigBase;
17class KLocalePrivate;
18class KCatalogue;
19class KCalendarSystem;
20
21#ifndef I18N_NOOP
22#define I18N_NOOP(x) (x)
23#endif
24
25void setLocaleDict( QDict<char> * dict );
26
27/**
28 * i18n is the function that does everything you need to translate
29 * a string. You just wrap around every user visible string a i18n
30 * call to get a QString with the string in the user's preferred
31 * language.
32 *
33 * The argument must be an UTF-8 encoded string (If you only use
34 * characters that are in US-ASCII, you're on the safe side. But
35 * for e.g. german umlauts or french accents should be recoded to
36 * UTF-8)
37 **/
38QString i18n(const char *text);
39
40/**
41 * If the string is too ambiguous to be translated well to a non-english
42 * language, use this form of i18n to separate lookup string and english
43 * text.
44 * @see translate
45 **/
46QString i18n(const char *index, const char *text);
47
48/**
49 * If you want to handle plural forms, use this form of i18n.
50 * The plural has to contain a %n where n fits into.
51 * @see translate
52 **/
53QString i18n(const char *singular, const char *plural, unsigned long n);
54
55/**
56 * Qt3's uic generates i18n( "msg", "comment" ) calls which conflict
57 * with our i18n method. We use uic -tr tr2i18n to redirect
58 * to the right i18n() function
59**/
60inline QString tr2i18n(const char* message, const char* =0) {
61 return i18n(message);
62}
63
64/**
65 *
66 * KLocale provides support for country specific stuff like
67 * the national language.
68 *
69 * KLocale supports translating, as well as specifying the format
70 * for numbers, currency, time, and date.
71 *
72 * @author Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>,
73 * Hans Petter Bieker <bieker@kde.org>, Lukas Tinkl <lukas.tinkl@suse.cz>
74 * @short class for supporting locale settings and national language
75 */
76class KLocale
77{
78 friend class KGlobal; // for initInstance()
79public:
80 /**
81 * Constructs a KLocale with the given catalogue name.
82 * The constructor looks for an entry Locale/Language in the
83 * configuration file.
84 * If no config file is specified, it will also look for languages
85 * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG),
86 * as well as the global configuration fie. If we were not able to use
87 * non of the specified languages, the default language (en_US) will be
88 * used.
89 *
90 * If you specify a configuration file, it has to be valid until
91 * the KLocale object is destroyed.
92 *
93 * @param catalogue The name of the main language file
94 * @param config The configuration file to use.
95 */
96 KLocale( const QString& catalogue, KConfig *config = 0 );
97
98 /**
99 * Copy constructor.
100 */
101 KLocale( const KLocale & rhs );
102
103 /**
104 * Assignment operator.
105 */
106 KLocale& operator= ( const KLocale & rhs );
107
108 /**
109 * Destructor.
110 */
111 ~KLocale();
112
113 /**
114 * Translates the string into the corresponding string in
115 * the national language, if available. If not, returns
116 * the string itself.
117 * There is a KDE wide message file that contains the most
118 * often used phrases, so we can avoid duplicating the
119 * translation of these phrases. If a phrase is not found
120 * in the catalogue given to the constructor, it will search
121 * in the system catalog. This makes it possible to override
122 * some phrases for your needs.
123 *
124 * The argument must be an UTF-8 encoded string (If you only use
125 * characters that are in US-ASCII you're on the safe side. But
126 * for e.g. german umlauts or french accents should be recoded to
127 * UTF-8)
128 *
129 * @param index The lookup text and default text, if not found.
130 */
131 QString translate( const char *index ) const;
132
133 /**
134 * Translates the string into the corresponding string in the
135 * national language, if available.
136 *
137 * The real contents of the string is in the argument fallback,
138 * but the meaning of it is coded into the argument index.
139 * In some cases you'll need this function, when english is
140 * too ambiguous to express it.
141 *
142 * Most of the times the translators will tell you if it can't
143 * be translated as it, but think of cases as "New", where the
144 * translations differs depending on what is New.
145 * Or simple cases as "Open", that can be used to express something
146 * is open or it can be used to express that you want something to
147 * open... There are tons of such examples.
148 *
149 * If translate("Open") is not enough to translate it well, use
150 * translate("To Open", "Open") or translate("Is Open", "Open").
151 * The english user will see "Open" in both cases, but the translated
152 * version may vary. Of course you can also use i18n()
153 *
154 * @param index The lookup text
155 * @param fallback the default text, if not found
156 * @return translation
157 */
158 QString translate( const char *index, const char *fallback) const;
159
160 /**
161 * Used to get the correct, translated singular or plural of a
162 * word.
163 * @param singular the singular form of the word, for example "file".
164 * @param plural the plural form of the word. Must contain a "%n" that will
165 * be replaced by the number @n, for example "%n files"
166 * @param n the number
167 * @return the correct singular or plural for the selected language,
168 * depending on n
169 */
170 QString translate( const char *singular, const char *plural,
171 unsigned long n) const;
172
173 /**
174 * Changes the current encoding.
175 *
176 * @param mibEnum The mib of the preferred codec
177 *
178 * @return True on success.
179 */
180 bool setEncoding(int mibEnum);
181
182 /**
183 * Changes the current language. The current language will be left
184 * unchanged if failed. It will force a reload of the country specific
185 * configuration as well.
186 *
187 * @param language The language code.
188 *
189 * @return True on success.
190 */
191 bool setLanguage(const QString & language);
192
193 /**
194 * Changes the list of prefed languages for the locale. The first valid
195 * language in the list will be used, or the default (en_US) language
196 * will be used if non of the specified languages were available.
197 *
198 * @param languages The list of language codes.
199 *
200 * @return True if one of the specified languages were used.
201 */
202 bool setLanguage(const QStringList & languages);
203
204 /**
205 * Changes the current country. The current country will be left
206 * unchanged if failed. It will force a reload of the country specific
207 * configuration.
208 *
209 * @param country The ISO 3166 country code.
210 *
211 * @return True on success.
212 */
213 bool setCountry(const QString & country);
214
215 /**
216 * Various positions for where to place the positive or negative
217 * sign when they are related to a monetary value.
218 */
219 enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1,
220 AfterQuantityMoney = 2,
221 BeforeMoney = 3, AfterMoney = 4 };
222
223 /**
224 * Returns what a decimal point should look like ("." or "," etc.)
225 * according to the current locale or user settings.
226 *
227 * @return The decimal symbol used by locale.
228 */
229 QString decimalSymbol() const;
230
231 /**
232 * Returns what the thousands separator should look
233 * like ("," or "." etc.)
234 * according to the current locale or user settings.
235 *
236 * @return The thousands separator used by locale.
237 */
238 QString thousandsSeparator() const;
239
240 /**
241 * Returns what the symbol denoting currency in the current locale
242 * as as defined by user settings should look like.
243 *
244 * @return The default currency symbol used by locale.
245 */
246 QString currencySymbol() const;
247
248 /**
249 * Returns what a decimal point should look like ("." or "," etc.)
250 * for monetary values, according to the current locale or user
251 * settings.
252 *
253 * @return The monetary decimal symbol used by locale.
254 */
255 QString monetaryDecimalSymbol() const;
256
257 /**
258 * Returns what a thousands separator for monetary values should
259 * look like ("," or " " etc.) according to the current locale or
260 * user settings.
261 *
262 * @return The monetary thousands separator used by locale.
263 */
264 QString monetaryThousandsSeparator() const;
265
266 /**
267 * Returns what a positive sign should look like ("+", " ", etc.)
268 * according to the current locale or user settings.
269 *
270 * @return The positive sign used by locale.
271 */
272 QString positiveSign() const;
273
274 /**
275 * Returns what a negative sign should look like ("-", etc.)
276 * according to the current locale or user settings.
277 *
278 * @return The negative sign used by locale.
279 */
280 QString negativeSign() const;
281
282 /**
283 * The number of fractional digits to include in numeric/monetary
284 * values (usually 2).
285 *
286 * @return Default number of fractional digits used by locale.
287 */
288 int fracDigits() const;
289
290 /**
291 * If and only if the currency symbol precedes a positive value,
292 * this will be true.
293 *
294 * @return Where to print the currency symbol for positive numbers.
295 */
296 bool positivePrefixCurrencySymbol() const;
297
298 /**
299 * If and only if the currency symbol precedes a negative value,
300 * this will be true.
301 *
302 * @return True if the currency symbol precedes negative numbers.
303 */
304 bool negativePrefixCurrencySymbol() const;
305
306 /**
307 * Returns the position of a positive sign in relation to a
308 * monetary value.
309 *
310 * @return Where/how to print the positive sign.
311 * @see SignPosition
312 */
313 SignPosition positiveMonetarySignPosition() const;
314
315 /**
316 * Denotes where to place a negative sign in relation to a
317 * monetary value.
318 *
319 * @return Where/how to print the negative sign.
320 * @see SignPosition
321 */
322 SignPosition negativeMonetarySignPosition() const;
323
324 /**
325 * Given a double, converts that to a numeric string containing
326 * the localized monetary equivalent.
327 *
328 * e.g. given 123456, return "$ 123,456.00".
329 *
330 * @param num The number we want to format
331 * @param currency The currency symbol you want.
332 * @param digits Number of fractional digits, or -1 for the default
333 * value
334 *
335 * @return The number of money as a localized string
336 * @see fracDigits()
337 */
338 QString formatMoney(double num,
339 const QString & currency = QString::null,
340 int digits = -1) const;
341
342 /**
343 * Given a double, converts that to a numeric string containing
344 * the localized numeric equivalent.
345 *
346 * e.g. given 123456.78F, return "123,456.78" (for some European country).
347 * If precision isn't specified, 2 is used.
348 *
349 * @param num The number to convert
350 * @param precision Number of fractional digits used.
351 *
352 * @return The number as a localized string
353 */
354 QString formatNumber(double num, int precision = -1) const;
355
356 /**
357 * Given an integer, converts that to a numeric string containing
358 * the localized numeric equivalent.
359 *
360 * e.g. given 123456L, return "123,456" (for some European country).
361 *
362 * @param num The number to convert
363 *
364 * @return The number as a localized string
365 * @since 3.2
366 */
367 QString formatLong(long num) const;
368
369 /**
370 * Use this to determine whether nouns are declined in
371 * locale's language. This property should remain
372 * read-only (no setter function)
373 *
374 * @return If nouns are declined
375 * @since 3.1
376 */
377 bool nounDeclension() const;
378
379 /**
380 * Returns a string formatted to the current locale's conventions
381 * regarding dates.
382 *
383 * @param pDate The date to be formated.
384 * @param shortFormat True for non text dates.
385 *
386 * @return The date as a string
387 */
388 QString formatDate(const QDate &pDate, bool shortFormat = false) const;
389
390 /**
391 * Use this to determine whether in dates a possessive form of month
392 * name is preferred ("of January" rather than "January")
393 *
394 * @return If possessive form should be used
395 * @since 3.1
396 */
397 bool dateMonthNamePossessive() const;
398
399 /**
400 * Returns a string formatted to the current locale's conventions
401 * regarding times.
402 *
403 * @param pTime The time to be formated.
404 * @param includeSecs if true, seconds are included in the output,
405 * otherwise only hours and minutes are formatted.
406 *
407 * @return The time as a string
408 */
409 QString formatTime(const QTime &pTime, bool includeSecs = false) const;
410
411 /**
412 * Use this to determine if the user wants a 12 hour clock.
413 *
414 * @return If the user wants 12h clock
415 */
416 bool use12Clock() const;
417
418 /**
419 * @deprecated
420 *
421 * Please use the @ref weekStartDay method instead.
422 *
423 * Use this to determine if the user wants the week to start on Monday.
424 *
425 * @return true if the week starts on Monday
426 */
427 bool weekStartsMonday() const; //### remove for KDE 4.0
428
429 /**
430 * Use this to determine which day is the first day of the week.
431 *
432 * @return an integer (Monday=1..Sunday=7)
433 * @since 3.1
434 */
435 int weekStartDay() const;
436
437 /**
438 * @deprecated
439 *
440 * Returns a string containing the name of the month name used in the Gregorian calendar.
441 *
442 * @param i the month number of the year starting at 1/January.
443 * @param shortName we will return the short version of the string.
444 *
445 * @return The name of the month
446 */
447 QString monthName(int i, bool shortName = false) const;
448
449 /**
450 * @deprecated
451 *
452 * Returns a string containing the possessive form of the month name used in the Gregorian calendar.
453 * ("of January", "of February", etc.)
454 * It's needed in long format dates in some languages.
455 *
456 * @param i the month number of the year starting at 1/January.
457 * @param shortName we will return the short version of the string.
458 *
459 * @return The possessive form of the name of the month
460 * @since 3.1
461 */
462 QString monthNamePossessive(int i, bool shortName = false) const;
463
464 /**
465 * @deprecated
466 *
467 * Returns a string containing the name of the week day used in the Gregorian calendar.
468 *
469 * @param i the day number of the week starting at 1/Monday.
470 * @param shortName we will return the short version of the string.
471 *
472 * @return The name of the day
473 */
474 QString weekDayName(int i, bool shortName = false) const;
475
476 /**
477 * Returns a pointer to the calendar system object.
478 *
479 * @return the current calendar system instance
480 * @since 3.2
481 */
482 const KCalendarSystem * calendar() const;
483
484 /**
485 * Returns the name of the calendar system that is currently being
486 * used by the system.
487 *
488 * @return the name of the calendar system
489 * @since 3.2
490 */
491 QString calendarType() const;
492
493 /**
494 * Changes the current calendar system to the calendar specified.
495 * Currently is "gregorian" and "hijri" supported. If the calendar
496 * system specified is not found, gregorian will be used.
497 *
498 * @param calendarType the name of the calendar type
499 * @since 3.2
500 */
501 void setCalendar(const QString & calendarType);
502
503 /**
504 * Returns a string formated to the current locale's conventions
505 * regarding both date and time.
506 *
507 * @param pDateTime The date and time to be formated.
508 * @param shortFormat using the short date format.
509 * @param includeSecs using the short date format.
510 *
511 * @return The date and time as a string
512 */
513 QString formatDateTime(const QDateTime &pDateTime,
514 bool shortFormat = true,
515 bool includeSecs = false) const;
516
517 /**
518 * Converts a localized monetary string to a double.
519 *
520 * @param numStr the string we want to convert.
521 * @param ok the boolean that is set to false if it's not a number.
522 * If @p ok is 0, it will be ignored
523 *
524 * @return The string converted to a double
525 */
526 double readMoney(const QString &numStr, bool * ok = 0) const;
527
528 /**
529 * Converts a localized numeric string to a double.
530 *
531 * @param numStr the string we want to convert.
532 * @param ok the boolean that is set to false if it's not a number.
533 * If @p ok is 0, it will be ignored
534 *
535 * @return The string converted to a double
536 */
537 double readNumber(const QString &numStr, bool * ok = 0) const;
538
539 /**
540 * Converts a localized date string to a QDate.
541 * The bool pointed by ok will be invalid if the date entered was not valid.
542 *
543 * @param str the string we want to convert.
544 * @param ok the boolean that is set to false if it's not a valid date.
545 * If @p ok is 0, it will be ignored
546 *
547 * @return The string converted to a QDate
548 */
549 QDate readDate(const QString &str, bool* ok = 0) const;
550
551 /**
552 * Converts a localized date string to a QDate, using the specified format.
553 * You will usually not want to use this method.
554 */
555 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
556
557 enum ReadDateFlags {
558 NormalFormat = 1,
559 ShortFormat = 2
560 };
561
562 /**
563 * Converts a localized date string to a QDate.
564 * This method is stricter than readDate(str,&ok): it will either accept
565 * a date in full format or a date in short format, depending on @p flags.
566 *
567 * @param str the string we want to convert.
568 * @param flags whether the date string is to be in full format or in short format.
569 * @param ok the boolean that is set to false if it's not a valid date.
570 * If @p ok is 0, it will be ignored
571 *
572 * @return The string converted to a QDate
573 * @since 3.2
574 */
575 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const;
576
577 /**
578 * Converts a localized time string to a QTime.
579 * This method will try to parse it with seconds, then without seconds.
580 * The bool pointed by ok will be false if the time entered was not valid.
581 *
582 * @param str the string we want to convert.
583 * @param ok the boolean that is set to false if it's not a valid time.
584 * If @p ok is 0, it will be ignored
585 *
586 * @return The string converted to a QTime
587 */
588 QTime readTime(const QString &str, bool* ok = 0) const;
589
590 enum ReadTimeFlags {
591 WithSeconds = 0, // default (no flag set)
592 WithoutSeconds = 1
593 }; // (maybe use this enum as a bitfield, if adding independent features?)
594 /**
595 * Converts a localized time string to a QTime.
596 * This method is stricter than readTime(str,&ok): it will either accept
597 * a time with seconds or a time without seconds.
598 * Use this method when the format is known by the application.
599 *
600 * @param str the string we want to convert.
601 * @param flags whether the time string is expected to contain seconds or not.
602 * @param ok the boolean that is set to false if it's not a valid time.
603 * If @p ok is 0, it will be ignored
604 *
605 * @return The string converted to a QTime
606 * @since 3.2
607 */
608 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const;
609
610 /**
611 * Returns the language used by this object. The domain AND the
612 * library translation must be available in this language.
613 * @ref defaultLanguage() is returned by default, if no other available.
614 *
615 * @return The currently used language.
616 */
617 QString language() const;
618
619 /**
620 * Returns the country code of the country where the user lives.
621 * @ref defaultCountry() is returned by default, if no other available.
622 *
623 * @return The country code for the user.
624 */
625 QString country() const;
626
627 /**
628 * Returns the preferred languages as ISO 639-1 codes. This means
629 * that information about country is removed. If the internal language
630 * code might be represented by more than one 639-1 code, they will all be
631 * listed (but only once).
632 *
633 * If the selected languages are "nn, nb, pt_BR", you will get:
634 * "nn, no, nb, pt".
635 *
636 * @return List of language codes
637 *
638 * @see languageList
639 */
640 QStringList languagesTwoAlpha() const;
641
642 /**
643 * Returns the languages selected by user. The codes returned here is the
644 * internal language codes.
645 *
646 * @return List of language codes
647 *
648 * @see languagesTwoAlpha
649 */
650 QStringList languageList() const;
651
652 /**
653 * Returns the user's preferred encoding.
654 *
655 * @return The name of the preferred encoding
656 *
657 * @see codecForEncoding
658 * @see encodingMib
659 */
660 const char * encoding() const;
661
662 /**
663 * Returns the user's preferred encoding.
664 *
665 * @return The Mib of the preferred encoding
666 *
667 * @see encoding
668 * @see codecForEncoding
669 */
670 int encodingMib() const;
671 /**
672 * Returns the user's preferred encoding. Should never be NULL.
673 *
674 * @return The codec for the preferred encoding
675 *
676 * @see encoding
677 * @see encodingMib
678 */
679 QTextCodec * codecForEncoding() const;
680
681 /**
682 * Returns the file encoding.
683 *
684 * @return The Mib of the file encoding
685 *
686 * @see QFile::encodeName
687 * @see QFile::decodeName
688 */
689 int fileEncodingMib() const;
690
691 /**
692 * Changes the current date format.
693 *
694 * The format of the date is a string which contains variables that will
695 * be replaced:
696 * @li %Y with the century (e.g. "19" for "1984")
697 * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
698 * @li %n with the month (January="1", December="12")
699 * @li %m with the month with two digits (January="01", December="12")
700 * @li %e with the day of the month (e.g. "1" on the first of march)
701 * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
702 * @li %b with the short form of the month (e.g. "Jan" for January)
703 * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
704 * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
705 * Everything else in the format string will be taken as is.
706 * For example, March 20th 1989 with the format "%y:%m:%d" results
707 * in "89:03:20".
708 *
709 * @param format The new date format
710 */
711 void setDateFormat(const QString & format);
712 /**
713 * Changes the current short date format.
714 *
715 * The format of the date is a string which contains variables that will
716 * be replaced:
717 * @li %Y with the century (e.g. "19" for "1984")
718 * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
719 * @li %n with the month (January="1", December="12")
720 * @li %m with the month with two digits (January="01", December="12")
721 * @li %e with the day of the month (e.g. "1" on the first of march)
722 * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
723 * @li %b with the short form of the month (e.g. "Jan" for January)
724 * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
725 * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
726 * Everything else in the format string will be taken as is.
727 * For example, March 20th 1989 with the format "%y:%m:%d" results
728 * in "89:03:20".
729 *
730 * @param format The new short date format
731 */
732 void setDateFormatShort(const QString & format);
733 /**
734 * Changes the form of month name used in dates.
735 *
736 * @param possessive True if possessive forms should be used
737 * @since 3.1
738 */
739 void setDateMonthNamePossessive(bool possessive);
740 /**
741 * Changes the current time format.
742 *
743 * The format of the time is string a which contains variables that will
744 * be replaced:
745 * @li %H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05")
746 * @li %k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5")
747 * @li %I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05")
748 * @li %l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5")
749 * @li %M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02")
750 * @li %S with the seconds with 2 digits (e.g. the minute of 07:02:09 is "09")
751 * @li %p with pm or am (e.g. 17.00 is "pm", 05.00 is "am")
752 * Everything else in the format string will be taken as is.
753 * For example, 5.23pm with the format "%H:%M" results
754 * in "17:23".
755 *
756 * @param format The new time format
757 */
758 void setTimeFormat(const QString & format);
759
760 /**
761 * @deprecated
762 *
763 * Please use @ref setWeekStartDay instead.
764 *
765 * Changes how KLocale defines the first day in week.
766 *
767 * @param start True if Monday is the first day in the week
768 */
769 void setWeekStartsMonday(bool start); //### remove for KDE 4.0
770
771 /**
772 * Changes how KLocale defines the first day in week.
773 *
774 * @param day first day of the week (Monday=1..Sunday=7) as integer
775 * @since 3.1
776 */
777 void setWeekStartDay(int day);
778 /**
779 * Returns the currently selected date format.
780 *
781 * @return Current date format.
782 * @see setDateFormat()
783 */
784 QString dateFormat() const;
785 /**
786 * Returns the currently selected short date format.
787 *
788 * @return Current short date format.
789 * @see setDateFormatShort()
790 */
791 QString dateFormatShort() const;
792 /**
793 * Returns the currently selected time format.
794 *
795 * @return Current time format.
796 * @see setTimeFormat()
797 */
798 QString timeFormat() const;
799
800 /**
801 * Changes the symbol used to identify the decimal pointer.
802 *
803 * @param symbol The new decimal symbol.
804 */
805 void setDecimalSymbol(const QString & symbol);
806 /**
807 * Changes the separator used to group digits when formating numbers.
808 *
809 * @param separator The new thousands separator.
810 */
811 void setThousandsSeparator(const QString & separator);
812 /**
813 * Changes the sign used to identify a positive number. Normally this is
814 * left blank.
815 *
816 * @param sign Sign used for positive numbers.
817 */
818 void setPositiveSign(const QString & sign);
819 /**
820 * Changes the sign used to identify a negative number.
821 *
822 * @param sign Sign used for negative numbers.
823 */
824 void setNegativeSign(const QString & sign);
825 /**
826 * Changes the sign position used for positive monetary values.
827 *
828 * @param signpos The new sign position
829 */
830 void setPositiveMonetarySignPosition(SignPosition signpos);
831 /**
832 * Changes the sign position used for negative monetary values.
833 *
834 * @param signpos The new sign position
835 */
836 void setNegativeMonetarySignPosition(SignPosition signpos);
837 /**
838 * Changes the position where the currency symbol should be printed for
839 * positive monetary values.
840 *
841 * @param prefix True if the currency symbol should be prefixed instead of
842 * postfixed
843 */
844 void setPositivePrefixCurrencySymbol(bool prefix);
845 /**
846 * Changes the position where the currency symbol should be printed for
847 * negative monetary values.
848 *
849 * @param prefix True if the currency symbol should be prefixed instead of
850 * postfixed
851 */
852 void setNegativePrefixCurrencySymbol(bool prefix);
853 /**
854 * Changes the number of digits used when formating numbers.
855 *
856 * @param digits The default number of digits to use.
857 */
858 void setFracDigits(int digits);
859 /**
860 * Changes the separator used to group digits when formating monetary values.
861 *
862 * @param separator The new thousands separator.
863 */
864 void setMonetaryThousandsSeparator(const QString & separator);
865 /**
866 * Changes the symbol used to identify the decimal pointer for monetary
867 * values.
868 *
869 * @param symbol The new decimal symbol.
870 */
871 void setMonetaryDecimalSymbol(const QString & symbol);
872 /**
873 * Changes the current currency symbol.
874 *
875 * @param symbol The new currency symbol
876 */
877 void setCurrencySymbol(const QString & symbol);
878
879 /**
880 * Returns the preferred page size for printing.
881 *
882 * @return The preferred page size, cast it to QPrinter::PageSize
883 */
884 int pageSize() const;
885
886 /**
887 * Changes the preferred page size when printing.
888 *
889 * @param paperFormat the new preferred page size in the format QPrinter::PageSize
890 */
891 void setPageSize(int paperFormat);
892
893 /**
894 * The Metric system will give you information in mm, while the
895 * Imperial system will give you information in inches.
896 */
897 enum MeasureSystem { Metric, Imperial };
898
899 /**
900 * Returns which measuring system we use.
901 *
902 * @return The preferred measuring system
903 */
904 MeasureSystem measureSystem() const;
905
906 /**
907 * Changes the preferred measuring system.
908 *
909 * @return value The preferred measuring system
910 */
911 void setMeasureSystem(MeasureSystem value);
912
913 /**
914 * Adds another catalogue to search for translation lookup.
915 * This function is useful for extern libraries and/or code,
916 * that provides its own messages.
917 *
918 * If the catalogue does not exist for the chosen language,
919 * it will be ignored and en_US will be used.
920 *
921 * @param catalogue The catalogue to add.
922 */
923 void insertCatalogue(const QString& catalogue);
924
925 /**
926 * Removes a catalog for translation lookup.
927 * @param catalogue The catalogue to remove.
928 * @see insertCatalogue()
929 */
930 void removeCatalogue(const QString &catalogue);
931
932 /**
933 * Sets the active catalog for translation lookup.
934 * @param catalogue The catalogue to activate.
935 */
936 void setActiveCatalogue(const QString &catalogue);
937
938 /**
939 * Translates a message as a QTranslator is supposed to.
940 * The parameters are similar to i18n(), but the result
941 * value has other semantics (it can be QString::null)
942 * @since 3.1
943 **/
944 QString translateQt(const char *context,
945 const char *sourceText,
946 const char *message) const;
947
948 /**
949 * Returns list of all known ISO 639-1 codes.
950 * @return a list of all language codes
951 * @since 3.1
952 */
953 QStringList allLanguagesTwoAlpha() const;
954
955 /**
956 * Convert a ISO 639-1 code to a human readable form.
957 * @param code the language ISO 639-1 code
958 * @return the human readable form
959 * @since 3.1
960 */
961 QString twoAlphaToLanguageName(const QString &code) const;
962
963 /**
964 * Returns list of all known country codes.
965 * @return a list of all country codes
966 * @since 3.1
967 */
968 QStringList allCountriesTwoAlpha() const;
969
970 /**
971 * Convert a country code to a human readable form.
972 * @param code the country code
973 * @return the human readable form of the country name
974 * @since 3.1
975 */
976 QString twoAlphaToCountryName(const QString &code) const;
977
978
979
980 int timezoneOffset( QString );
981 QStringList timeZoneList() const;
982 void setDaylightSaving( bool, int , int );
983 int localTimeOffset(const QDateTime &);
984 void setTimezone( const QString &timeZone );
985
986 void setHore24Format ( bool );
987 void setWeekStartMonday( bool );
988 void setIntDateFormat( int );
989 void setLanguage( int );
990
991
992
993 /**
994 * Returns the parts of the parameter str understood as language setting
995 * the format is language_COUNTRY.charset
996 *
997 * @param str The string to split.
998 * @param language This will be set to the language part of the string.
999 * @param country This will be set to the country part of the string.
1000 * @param charset This will be set to the charset part of the string.
1001 */
1002 static void splitLocale(const QString & str,
1003 QString & language,
1004 QString & country,
1005 QString & charset);
1006
1007 /**
1008 * Use this to as main catalogue for *all* KLocales, if not the appname
1009 * will be used. This function is best to be the very first instruction
1010 * in your program's main function as it only has an effect before the
1011 * first KLocale object is created (and this is in common KDE applications
1012 * quite early).
1013 *
1014 * @param catalogue Catalogue to override all other main catalogues.
1015 */
1016 static void setMainCatalogue(const char *catalogue);
1017
1018 /**
1019 * Finds localized resource in resourceDir( rtype ) + \<lang> + fname.
1020 *
1021 * @param fname relative path to find
1022 * @param rtype resource type to use
1023 */
1024 static QString langLookup(const QString &fname, const char *rtype = "html");
1025
1026 /**
1027 * Returns the name of the internal language.
1028 *
1029 * @return Name of the default language
1030 */
1031 static QString defaultLanguage();
1032
1033 /**
1034 * Returns the name of the default country.
1035 *
1036 * @return Name of the default country
1037 */
1038 static QString defaultCountry();
1039
1040
1041 /**
1042 * @internal Called from KConfigBackend to initialize language.
1043 */
1044 static QString _initLanguage(KConfigBase *config);
1045
1046#ifdef KDE_NO_COMPAT
1047private:
1048#endif
1049 /**
1050 * @deprecated
1051 * use formatMoney(double)
1052 */
1053 QString formatMoney(const QString &numStr) const;
1054
1055 /**
1056 * @deprecated
1057 * use formatNumber(double)
1058 */
1059 QString formatNumber(const QString &numStr) const;
1060
1061 /**
1062 * @deprecated
1063 * Use languageList()
1064 *
1065 * @return String containing language codes separated by colons
1066 */
1067 QString languages() const;
1068
1069 /**
1070 * @deprecated
1071 * @return True
1072 */
1073 bool setCharset(const QString & charset);
1074
1075 /**
1076 * @deprecated
1077 * @see encoding
1078 */
1079 QString charset() const;
1080
1081protected:
1082 /**
1083 * @internal Creates a KLocale object for KGlobal and inits the locale
1084 * pointer.
1085 */
1086 static void initInstance();
1087
1088private:
1089 /**
1090 * @internal Inits the localization part of the instance with the config
1091 * object.
1092 *
1093 * @param config The configuration object used for init.
1094 */
1095 void initFormat(KConfig *config);
1096
1097 /**
1098 * @internal Inits the language part of the instance with the given config
1099 * object. It should be valid and contain the global entries.
1100 *
1101 * @param config The configuration object used for init
1102 * @param useEnv True if we should use environment variables
1103 */
1104 void initLanguage(KConfig * config, bool useEnv);
1105
1106 /**
1107 * @internal Figures out which encoding the user prefers.
1108 *
1109 * @param config The configuration object used for init
1110 */
1111 void initEncoding(KConfig * config);
1112
1113 /**
1114 * @internal Figures out which catalogues to use.
1115 *
1116 * @param catalogue The name of the main catalogue
1117 */
1118 void initCatalogue(const QString & catalogue);
1119
1120 /**
1121 * @internal Figures out which encoding the user prefers for filenames
1122 * and sets up the appropriate QFile encoding and decoding functions.
1123 */
1124 void initFileNameEncoding(KConfig *config);
1125
1126 /**
1127 * @internal A QFile filename encoding function (QFile::encodeFn).
1128 */
1129 static QCString encodeFileNameUTF8( const QString & fileName );
1130
1131 /**
1132 * @internal QFile filename decoding function (QFile::decodeFn).
1133 */
1134 static QString decodeFileNameUTF8( const QCString & localFileName );
1135
1136 /**
1137 * @internal Changes the file name of the catalogue to the correct
1138 * one.
1139 */
1140 void initCatalogue( KCatalogue & catalogue );
1141
1142 /**
1143 * @internal Reads the language and format configuration form disk.
1144 */
1145 void doBindInit();
1146
1147 /**
1148 * @internal Ensures that the format configuration is read.
1149 */
1150 void doFormatInit() const;
1151
1152 /**
1153 * @internal Reads the format configuration from disk.
1154 */
1155 void initFormat();
1156
1157 /**
1158 * @internal function used by the two translate versions
1159 */
1160 QString translate_priv(const char *index,
1161 const char *text,
1162 const char ** original = 0) const;
1163
1164 /**
1165 * @internal function used to determine if we are using the en_US translation
1166 */
1167 bool useDefaultLanguage() const;
1168
1169 /**
1170 * @internal Checks if the specified language is installed
1171 */
1172 bool isLanguageInstalled(const QString & language) const;
1173
1174 /**
1175 * @internal Retrieves the file name of the catalogue, or QString::null
1176 * if not found.
1177 */
1178 static QString catalogueFileName(const QString & language,
1179 const KCatalogue & catalogue);
1180
1181
1182private:
1183 // Numbers and money
1184 QString m_decimalSymbol;
1185 QString m_thousandsSeparator;
1186 QString m_currencySymbol;
1187 QString m_monetaryDecimalSymbol;
1188 QString m_monetaryThousandsSeparator;
1189 QString m_positiveSign;
1190 QString m_negativeSign;
1191 int m_fracDigits;
1192 SignPosition m_positiveMonetarySignPosition;
1193 SignPosition m_negativeMonetarySignPosition;
1194
1195 // Date and time
1196 QString m_timeFormat;
1197 QString m_dateFormat;
1198 QString m_dateFormatShort;
1199
1200 QString m_language;
1201 QString m_country;
1202
1203 QStringList mTimeZoneList;
1204 bool daylightEnabled;
1205 int mDaylightTZoffset;
1206 int mNondaylightTZoffset;
1207 bool mSouthDaylight;
1208 int daylightStart, daylightEnd, mTimeZoneOffset;
1209 bool mWeekStartsMonday;
1210 bool mHourF24Format;
1211 int mIntDateFormat;
1212 int mLanguage;
1213
1214
1215
1216
1217 bool m_weekStartsMonday; //### remove for KDE 4.0
1218 bool m_positivePrefixCurrencySymbol;
1219 bool m_negativePrefixCurrencySymbol;
1220
1221 KLocalePrivate *d;
1222};
1223
1224#endif