fix logic
[personal-kdelibs.git] / kdecore / localization / klocale.h
blob76f640f0073dd2c9af96355665acd7aebcb9563e
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>
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.
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.
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.
22 #ifndef KLOCALE_H
23 #define KLOCALE_H
25 #include <kdecore_export.h>
26 #include <klocalizedstring.h>
27 #include <ksharedconfig.h>
29 #include <QtCore/QString>
31 class QStringList;
32 class QTextCodec;
33 class QDate;
34 class QTime;
35 class QDateTime;
37 class KDateTime;
38 class KCalendarSystem;
40 class KLocalePrivate;
42 /**
43 * \file klocale.h
46 /**
48 * KLocale provides support for country specific stuff like
49 * the national language.
51 * KLocale supports translating, as well as specifying the format
52 * for numbers, currency, time, and date.
54 * Use KGlobal::locale() to get pointer to the global KLocale object,
55 * containing the applications current locale settings.
57 * For example, to format the date May 17, 1995 in the current locale, use:
59 * \code
60 * QString date = KGlobal::locale()->formatDate(QDate(1995,5,17));
61 * \endcode
63 * @author Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>,
64 * Hans Petter Bieker <bieker@kde.org>, Lukas Tinkl <lukas.tinkl@suse.cz>
65 * @short class for supporting locale settings and national language
67 class KDECORE_EXPORT KLocale
69 public:
70 /**
71 * Constructs a KLocale with the given catalog name
73 * The constructor looks for an entry Language in the group Locale in the
74 * configuration file.
76 * If no configuration file is specified, it will also look for languages
77 * using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG),
78 * as well as the global configuration file. If KLocale is not able to use
79 * any of the specified languages, the default language (en_US) will be
80 * used.
82 * If you specify a configuration file, it has to be valid until
83 * the KLocale object is destroyed.
85 * @param catalog the name of the main language file
86 * @param config a configuration file with a Locale group detailing
87 * locale-related preferences (such as language and
88 * formatting options)
90 explicit KLocale(const QString& catalog, KSharedConfig::Ptr config = KSharedConfig::Ptr());
92 /**
93 * Constructs a KLocale with the given catalog name
95 * Allows you to override the language and, optionally, the
96 * country of this locale.
98 * @param catalog the name of the main language file
99 * @param language the language for the locale
100 * @param country the country for the locale
101 * @param config a configuration file with a Locale group detailing
102 * locale-related preferences (such as date and time
103 * formatting options)
105 KLocale(const QString& catalog, const QString &language, const QString &country = QString(), KConfig *config = 0);
108 * Copy constructor
110 KLocale( const KLocale & rhs );
113 * Assignment operator
115 KLocale& operator= ( const KLocale & rhs );
118 * Destructor
120 virtual ~KLocale();
123 * Raw translation from message catalogs.
125 * Never use this directly to get message translations. See the i18n and ki18n
126 * family of calls related to KLocalizedString.
128 * @param msg the message. Must not be null. Must be UTF-8 encoded.
129 * @param lang language in which the translation was found. If no translation
130 * was found, KLocale::defaultLanguage() is reported. If null,
131 * the language is not reported.
132 * @param trans raw translation, or original if not found. If no translation
133 * was found, original message is reported. If null, the
134 * translation is not reported.
136 * @see KLocalizedString
138 void translateRaw(const char* msg,
139 QString *lang, QString *trans) const;
142 * Raw translation from message catalogs, with given context.
143 * Context + message are used as the lookup key in catalogs.
145 * Never use this directly to get message translations. See i18n* and ki18n*
146 * calls related to KLocalizedString.
148 * @param ctxt the context. Must not be null. Must be UTF-8 encoded.
149 * @param msg the message. Must not be null. Must be UTF-8 encoded.
150 * @param lang language in which the translation was found. If no translation
151 * was found, KLocale::defaultLanguage() is reported. If null,
152 * the language is not reported.
153 * @param trans raw translation, or original if not found. If no translation
154 * was found, original message is reported. If null, the
155 * translation is not reported.
157 * @see KLocalizedString
159 void translateRaw(const char *ctxt, const char *msg,
160 QString *lang, QString *trans) const;
163 * Raw translation from message catalogs, with given singular/plural form.
164 * Singular form is used as the lookup key in catalogs.
166 * Never use this directly to get message translations. See i18n* and ki18n*
167 * calls related to KLocalizedString.
169 * @param singular the singular form. Must not be null. Must be UTF-8 encoded.
170 * @param plural the plural form. Must not be null. Must be UTF-8 encoded.
171 * @param n number on which the forms are decided.
172 * @param lang language in which the translation was found. If no translation
173 * was found, KLocale::defaultLanguage() is reported. If null,
174 * the language is not reported.
175 * @param trans raw translation, or original if not found. If no translation
176 * was found, original message is reported (either plural or
177 * singular, as determined by @p n ). If null, the
178 * translation is not reported.
180 * @see KLocalizedString
182 void translateRaw(const char *singular, const char *plural, unsigned long n,
183 QString *lang, QString *trans) const;
186 * Raw translation from message catalogs, with given context and
187 * singular/plural form.
188 * Context + singular form is used as the lookup key in catalogs.
190 * Never use this directly to get message translations. See i18n* and ki18n*
191 * calls related to KLocalizedString.
193 * @param ctxt the context. Must not be null. Must be UTF-8 encoded.
194 * @param singular the singular form. Must not be null. Must be UTF-8 encoded.
195 * @param plural the plural form. Must not be null. Must be UTF-8 encoded.
196 * @param n number on which the forms are decided.
197 * @param lang language in which the translation was found. If no translation
198 * was found, KLocale::defaultLanguage() is reported. If null,
199 * the language is not reported.
200 * @param trans raw translation, or original if not found. If no translation
201 * was found, original message is reported (either plural or
202 * singular, as determined by @p n ). If null, the
203 * translation is not reported.
205 * @see KLocalizedString
207 void translateRaw(const char *ctxt, const char *singular, const char *plural,
208 unsigned long n, QString *lang, QString *trans) const;
211 * Changes the current encoding.
213 * @param mibEnum The mib of the preferred codec
215 * @return True on success.
217 bool setEncoding(int mibEnum);
220 * Various positions for where to place the positive or negative
221 * sign when they are related to a monetary value.
223 enum SignPosition {
225 * Put parantheses around the quantity, e.g. "$ (217)"
227 ParensAround = 0,
229 * Prefix the quantity with the sign, e.g. "$ -217"
231 BeforeQuantityMoney = 1,
233 * Suffix the quanitity with the sign, e.g. "$ 217-"
235 AfterQuantityMoney = 2,
237 * Prefix the currency symbol with the sign, e.g. "-$ 217"
239 BeforeMoney = 3,
241 * Suffix the currency symbol with the sign, e.g. "$- 217"
243 AfterMoney = 4
247 * Returns what a decimal point should look like ("." or "," etc.)
248 * according to the current locale or user settings.
250 * @return The decimal symbol used by locale.
252 QString decimalSymbol() const;
255 * Returns what the thousands separator should look
256 * like ("," or "." etc.)
257 * according to the current locale or user settings.
259 * @return The thousands separator used by locale.
261 QString thousandsSeparator() const;
264 * Returns what the symbol denoting currency in the current locale
265 * as as defined by user settings should look like.
267 * @return The default currency symbol used by locale.
269 QString currencySymbol() const;
272 * Returns what a decimal point should look like ("." or "," etc.)
273 * for monetary values, according to the current locale or user
274 * settings.
276 * @return The monetary decimal symbol used by locale.
278 QString monetaryDecimalSymbol() const;
281 * Returns what a thousands separator for monetary values should
282 * look like ("," or " " etc.) according to the current locale or
283 * user settings.
285 * @return The monetary thousands separator used by locale.
287 QString monetaryThousandsSeparator() const;
290 * Returns what a positive sign should look like ("+", " ", etc.)
291 * according to the current locale or user settings.
293 * @return The positive sign used by locale.
295 QString positiveSign() const;
298 * Returns what a negative sign should look like ("-", etc.)
299 * according to the current locale or user settings.
301 * @return The negative sign used by locale.
303 QString negativeSign() const;
306 * The number of fractional digits to include in numeric/monetary
307 * values (usually 2).
309 * @return Default number of fractional digits used by locale.
311 int fracDigits() const;
314 * If and only if the currency symbol precedes a positive value,
315 * this will be true.
317 * @return Where to print the currency symbol for positive numbers.
319 bool positivePrefixCurrencySymbol() const;
322 * If and only if the currency symbol precedes a negative value,
323 * this will be true.
325 * @return True if the currency symbol precedes negative numbers.
327 bool negativePrefixCurrencySymbol() const;
330 * Returns the position of a positive sign in relation to a
331 * monetary value.
333 * @return Where/how to print the positive sign.
334 * @see SignPosition
336 SignPosition positiveMonetarySignPosition() const;
339 * Denotes where to place a negative sign in relation to a
340 * monetary value.
342 * @return Where/how to print the negative sign.
343 * @see SignPosition
345 SignPosition negativeMonetarySignPosition() const;
348 * Given a double, converts that to a numeric string containing
349 * the localized monetary equivalent.
351 * e.g. given 123456, return "$ 123,456.00".
353 * @param num The number we want to format
354 * @param currency The currency symbol you want.
355 * @param digits Number of fractional digits, or -1 for the default
356 * value
358 * @return The number of money as a localized string
359 * @see fracDigits()
361 QString formatMoney(double num,
362 const QString & currency = QString(),
363 int digits = -1) const;
366 * Given a double, converts that to a numeric string containing
367 * the localized numeric equivalent.
369 * e.g. given 123456.78F, return "123,456.78" (for some European country).
370 * If precision isn't specified, 2 is used.
372 * This function is a wrapper that is provided for convenience.
374 * @param num The number to convert
375 * @param precision Number of fractional digits used.
377 * @return The number as a localized string
378 * @see formatNumber(const QString, bool, int)
380 QString formatNumber(double num, int precision = -1) const;
383 * Given a string representing a number, converts that to a numeric
384 * string containing the localized numeric equivalent.
386 * e.g. given 123456.78F, return "123,456.78" (for some European country).
388 * @param numStr The number to format, as a string.
389 * @param round Round fractional digits. (default true)
390 * @param precision Number of fractional digits used for rounding. Unused if round=false. (default 2)
392 * @return The number as a localized string
394 QString formatNumber(const QString &numStr, bool round=true, int precision=2) const;
397 * Given an integer, converts that to a numeric string containing
398 * the localized numeric equivalent.
400 * e.g. given 123456L, return "123,456" (for some European country).
402 * @param num The number to convert
404 * @return The number as a localized string
406 QString formatLong(long num) const;
409 * Converts @p size from bytes to the string representation using the
410 * IEC 60027-2 standard
412 * Example:
413 * formatByteSize(1024) returns "1.0 KiB"
415 * @param size size in bytes
416 * @return converted size as a string - e.g. 123.4 KiB , 12.0 MiB
418 QString formatByteSize( double size ) const;
421 * Given a number of milliseconds, converts that to a string containing
422 * the localized equivalent
424 * e.g. given formatDuration(60000), returns "1.0 minutes"
426 * @param mSec Time duration in milliseconds
427 * @return converted duration as a string - e.g. "5.5 seconds" "23.0 minutes"
429 QString formatDuration( unsigned long mSec) const;
432 * Given a number of milliseconds, converts that to a pretty string containing
433 * the localized equivalent.
435 * e.g. given prettyFormatDuration(60001) returns "1 minute"
436 * given prettyFormatDuration(62005) returns "1 minute and 2 seconds"
437 * given prettyFormatDuration(90060000) returns "1 day and 1 hour"
439 * @param mSec Time duration in milliseconds
440 * @return converted duration as a string.
441 * Units not interesting to the user, for example seconds or minutes when the first
442 * unit is day, are not returned because they are irrelevant. The same applies for seconds
443 * when the first unit is hour.
444 * @since 4.2
446 QString prettyFormatDuration( unsigned long mSec ) const;
449 * @deprecated
451 * Use this to determine whether nouns are declined in
452 * locale's language. This property should remain
453 * read-only (no setter function)
455 * @return If nouns are declined
457 bool nounDeclension() const;
460 * Format for date string.
462 enum DateFormat {
463 ShortDate, /**< Short (numeric) date format, e.g. 08-04-2007 */
464 LongDate, /**< Long (text) date format, e.g. Sunday 08 April 2007 */
465 FancyShortDate, /**< Same as ShortDate for dates a week or more ago. For more
466 recent dates, it is represented as Today, Yesterday, or
467 the weekday name. */
468 FancyLongDate /**< Same as LongDate for dates a week or more ago. For more
469 recent dates, it is represented as Today, Yesterday, or
470 the weekday name. */
474 * Returns a string formatted to the current locale's conventions
475 * regarding dates.
477 * @param date the date to be formatted
478 * @param format category of date format to use
480 * @return the date as a string
482 QString formatDate(const QDate &date, DateFormat format = LongDate) const;
485 * Returns a string formatted to the current locale's conventions
486 * regarding both date and time.
488 * @param dateTime the date and time to be formatted
489 * @param format category of date format to use
490 * @param includeSecs if @c true, the string will include the seconds part
491 * of the time; otherwise, the seconds will be omitted
493 * @return the date and time as a string
495 QString formatDateTime(const QDateTime &dateTime, DateFormat format = ShortDate,
496 bool includeSecs = false) const;
499 * Options for formatting date-time values.
501 enum DateTimeFormatOption {
502 TimeZone = 0x01, /**< Include a time zone string */
503 Seconds = 0x02 /**< Include the seconds value */
505 Q_DECLARE_FLAGS(DateTimeFormatOptions, DateTimeFormatOption)
508 * Returns a string formatted to the current locale's conventions
509 * regarding both date and time.
511 * @param dateTime the date and time to be formatted
512 * @param format category of date format to use
513 * @param options additional output options
515 * @return The date and time as a string
517 QString formatDateTime(const KDateTime &dateTime, DateFormat format = ShortDate,
518 DateTimeFormatOptions options = 0) const;
521 * Use this to determine whether in dates a possessive form of month
522 * name is preferred ("of January" rather than "January")
524 * @return If possessive form should be used
526 bool dateMonthNamePossessive() const;
529 * Returns a string formatted to the current locale's conventions
530 * regarding times.
532 * @param pTime The time to be formatted.
533 * @param includeSecs if true, seconds are included in the output,
534 * otherwise only hours and minutes are formatted.
535 * @param isDuration if true, the given time is a duration, not a clock time.
536 * This means "am/pm" shouldn't be displayed.
538 * @return The time as a string
540 QString formatTime(const QTime &pTime, bool includeSecs = false,
541 bool isDuration = false) const;
544 * Use this to determine if the user wants a 12 hour clock.
546 * @return If the user wants 12h clock
548 bool use12Clock() const;
551 * Use this to determine which day is the first day of the week.
553 * @return an integer (Monday=1..Sunday=7)
555 int weekStartDay() const;
558 * Use this to determine which day is the first working day of the week.
560 * @since 4.2
561 * @return an integer (Monday=1..Sunday=7)
563 int workingWeekStartDay() const;
566 * Use this to determine which day is the last working day of the week.
568 * @since 4.2
569 * @return an integer (Monday=1..Sunday=7)
571 int workingWeekEndDay() const;
574 * Use this to determine which day is reserved for religious observance
576 * @since 4.2
577 * @return day number (None = 0, Monday = 1, ..., Sunday = 7)
579 int weekDayOfPray() const;
582 * Returns a pointer to the calendar system object.
584 * @return the current calendar system instance
586 const KCalendarSystem * calendar() const;
589 * Returns the name of the calendar system that is currently being
590 * used by the system.
592 * @return the name of the calendar system
594 QString calendarType() const;
597 * Changes the current calendar system to the calendar specified.
598 * Currently "gregorian" and "hijri" are supported. If the calendar
599 * system specified is not found, gregorian will be used.
601 * @param calendarType the name of the calendar type
603 void setCalendar(const QString & calendarType);
606 * Converts a localized monetary string to a double.
608 * @param numStr the string we want to convert.
609 * @param ok the boolean that is set to false if it's not a number.
610 * If @p ok is 0, it will be ignored
612 * @return The string converted to a double
614 double readMoney(const QString &numStr, bool * ok = 0) const;
617 * Converts a localized numeric string to a double.
619 * @param numStr the string we want to convert.
620 * @param ok the boolean that is set to false if it's not a number.
621 * If @p ok is 0, it will be ignored
623 * @return The string converted to a double
625 double readNumber(const QString &numStr, bool * ok = 0) const;
628 * Converts a localized date string to a QDate.
629 * The bool pointed by ok will be invalid if the date entered was not valid.
631 * @param str the string we want to convert.
632 * @param ok the boolean that is set to false if it's not a valid date.
633 * If @p ok is 0, it will be ignored
635 * @return The string converted to a QDate
637 QDate readDate(const QString &str, bool* ok = 0) const;
640 * Converts a localized date string to a QDate, using the specified format.
641 * You will usually not want to use this method.
643 QDate readDate( const QString &intstr, const QString &fmt, bool* ok = 0) const;
646 * Flags for readDate()
648 enum ReadDateFlags {
649 NormalFormat = 1, ///< Only accept a date string in normal (long) format
650 ShortFormat = 2 ///< Only accept a date string in short format
654 * Converts a localized date string to a QDate.
655 * This method is stricter than readDate(str,&ok): it will either accept
656 * a date in full format or a date in short format, depending on @p flags.
658 * @param str the string we want to convert.
659 * @param flags whether the date string is to be in full format or in short format.
660 * @param ok the boolean that is set to false if it's not a valid date.
661 * If @p ok is 0, it will be ignored
663 * @return The string converted to a QDate
665 QDate readDate(const QString &str, ReadDateFlags flags, bool *ok = 0) const;
668 * Converts a localized time string to a QTime.
669 * This method will try to parse it with seconds, then without seconds.
670 * The bool pointed to by @p ok will be set to false if the time entered was
671 * not valid.
673 * @param str the string we want to convert.
674 * @param ok the boolean that is set to false if it's not a valid time.
675 * If @p ok is 0, it will be ignored
677 * @return The string converted to a QTime
679 QTime readTime(const QString &str, bool* ok = 0) const;
682 * Flags for readTime()
684 enum ReadTimeFlags {
685 WithSeconds = 0, ///< Only accept a time string with seconds. Default (no flag set)
686 WithoutSeconds = 1 ///< Only accept a time string without seconds.
687 }; // (maybe use this enum as a bitfield, if adding independent features?)
689 * Converts a localized time string to a QTime.
690 * This method is stricter than readTime(str,&ok): it will either accept
691 * a time with seconds or a time without seconds.
692 * Use this method when the format is known by the application.
694 * @param str the string we want to convert.
695 * @param flags whether the time string is expected to contain seconds or not.
696 * @param ok the boolean that is set to false if it's not a valid time.
697 * If @p ok is 0, it will be ignored
699 * @return The string converted to a QTime
701 QTime readTime(const QString &str, ReadTimeFlags flags, bool *ok = 0) const;
704 * Returns the language code used by this object. The domain AND the
705 * library translation must be available in this language.
706 * defaultLanguage() is returned by default, if no other available.
708 * Use languageCodeToName(language) to get human readable, localized
709 * language name.
711 * @return the currently used language code
713 * @see languageCodeToName
715 QString language() const;
718 * Returns the country code of the country where the user lives.
719 * defaultCountry() is returned by default, if no other available.
721 * Use countryCodeToName(country) to get human readable, localized
722 * country names.
724 * @return the country code for the user
726 * @see countryCodeToName
728 QString country() const;
731 * Returns the language codes selected by user, ordered by decreasing
732 * priority.
734 * Use languageCodeToName(language) to get human readable, localized
735 * language name.
737 * @return list of language codes
739 * @see languageCodeToName
741 QStringList languageList() const;
744 * Returns the user's preferred encoding.
746 * @return The name of the preferred encoding
748 * @see codecForEncoding
749 * @see encodingMib
751 const QByteArray encoding() const;
754 * Returns the user's preferred encoding.
756 * @return The Mib of the preferred encoding
758 * @see encoding
759 * @see codecForEncoding
761 int encodingMib() const;
763 * Returns the user's preferred encoding. Should never be NULL.
765 * @return The codec for the preferred encoding
767 * @see encoding
768 * @see encodingMib
770 QTextCodec * codecForEncoding() const;
773 * Returns the file encoding.
775 * @return The Mib of the file encoding
777 * @see QFile::encodeName
778 * @see QFile::decodeName
780 int fileEncodingMib() const;
783 * Changes the current date format.
785 * The format of the date is a string which contains variables that will
786 * be replaced:
787 * @li %Y with the whole year (e.g. "1984" for "1984")
788 * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
789 * @li %n with the month (January="1", December="12")
790 * @li %m with the month with two digits (January="01", December="12")
791 * @li %e with the day of the month (e.g. "1" on the first of march)
792 * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
793 * @li %b with the short form of the month (e.g. "Jan" for January)
794 * @li %B with the long form of the month (e.g. "January")
795 * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
796 * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
798 * Everything else in the format string will be taken as is.
799 * For example, March 20th 1989 with the format "%y:%m:%d" results
800 * in "89:03:20".
802 * @param format The new date format
804 void setDateFormat(const QString & format);
806 * Changes the current short date format.
808 * The format of the date is a string which contains variables that will
809 * be replaced:
810 * @li %Y with the whole year (e.g. "1984" for "1984")
811 * @li %y with the lower 2 digits of the year (e.g. "84" for "1984")
812 * @li %n with the month (January="1", December="12")
813 * @li %m with the month with two digits (January="01", December="12")
814 * @li %e with the day of the month (e.g. "1" on the first of march)
815 * @li %d with the day of the month with two digits(e.g. "01" on the first of march)
816 * @li %b with the short form of the month (e.g. "Jan" for January)
817 * @li %B with the long form of the month (e.g. "January")
818 * @li %a with the short form of the weekday (e.g. "Wed" for Wednesday)
819 * @li %A with the long form of the weekday (e.g. "Wednesday" for Wednesday)
821 * Everything else in the format string will be taken as is.
822 * For example, March 20th 1989 with the format "%y:%m:%d" results
823 * in "89:03:20".
825 * @param format The new short date format
827 void setDateFormatShort(const QString & format);
829 * Changes the form of month name used in dates.
831 * @param possessive True if possessive forms should be used
833 void setDateMonthNamePossessive(bool possessive);
835 * Changes the current time format.
837 * The format of the time is string a which contains variables that will
838 * be replaced:
839 * @li %H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05")
840 * @li %k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5")
841 * @li %I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05")
842 * @li %l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5")
843 * @li %M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02")
844 * @li %S with the seconds with 2 digits (e.g. the minute of 07:02:09 is "09")
845 * @li %p with pm or am (e.g. 17.00 is "pm", 05.00 is "am")
847 * Everything else in the format string will be taken as is.
848 * For example, 5.23pm with the format "%H:%M" results
849 * in "17:23".
851 * @param format The new time format
853 void setTimeFormat(const QString & format);
857 * Changes how KLocale defines the first day in week.
859 * @param day first day of the week (Monday=1..Sunday=7) as integer
861 void setWeekStartDay(int day);
864 * Changes how KLocale defines the first working day in week.
866 * @since 4.2
867 * @param day first working day of the week (Monday=1..Sunday=7) as integer
869 void setWorkingWeekStartDay(int day);
872 * Changes how KLocale defines the last working day in week.
874 * @since 4.2
875 * @param day last working day of the week (Monday=1..Sunday=7) as integer
877 void setWorkingWeekEndDay(int day);
880 * Changes how KLocale defines the day reserved for religious observance.
882 * @since 4.2
883 * @param day day of the week for religious observance (None=0,Monday=1..Sunday=7) as integer
885 void setWeekDayOfPray(int day);
888 * Returns the currently selected date format.
890 * @return Current date format.
891 * @see setDateFormat()
893 QString dateFormat() const;
895 * Returns the currently selected short date format.
897 * @return Current short date format.
898 * @see setDateFormatShort()
900 QString dateFormatShort() const;
902 * Returns the currently selected time format.
904 * @return Current time format.
905 * @see setTimeFormat()
907 QString timeFormat() const;
910 * Changes the symbol used to identify the decimal pointer.
912 * @param symbol The new decimal symbol.
914 void setDecimalSymbol(const QString & symbol);
916 * Changes the separator used to group digits when formating numbers.
918 * @param separator The new thousands separator.
920 void setThousandsSeparator(const QString & separator);
922 * Changes the sign used to identify a positive number. Normally this is
923 * left blank.
925 * @param sign Sign used for positive numbers.
927 void setPositiveSign(const QString & sign);
929 * Changes the sign used to identify a negative number.
931 * @param sign Sign used for negative numbers.
933 void setNegativeSign(const QString & sign);
935 * Changes the sign position used for positive monetary values.
937 * @param signpos The new sign position
939 void setPositiveMonetarySignPosition(SignPosition signpos);
941 * Changes the sign position used for negative monetary values.
943 * @param signpos The new sign position
945 void setNegativeMonetarySignPosition(SignPosition signpos);
947 * Changes the position where the currency symbol should be printed for
948 * positive monetary values.
950 * @param prefix True if the currency symbol should be prefixed instead of
951 * postfixed
953 void setPositivePrefixCurrencySymbol(bool prefix);
955 * Changes the position where the currency symbol should be printed for
956 * negative monetary values.
958 * @param prefix True if the currency symbol should be prefixed instead of
959 * postfixed
961 void setNegativePrefixCurrencySymbol(bool prefix);
963 * Changes the number of digits used when formating numbers.
965 * @param digits The default number of digits to use.
967 void setFracDigits(int digits);
969 * Changes the separator used to group digits when formating monetary values.
971 * @param separator The new thousands separator.
973 void setMonetaryThousandsSeparator(const QString & separator);
975 * Changes the symbol used to identify the decimal pointer for monetary
976 * values.
978 * @param symbol The new decimal symbol.
980 void setMonetaryDecimalSymbol(const QString & symbol);
982 * Changes the current currency symbol.
984 * @param symbol The new currency symbol
986 void setCurrencySymbol(const QString & symbol);
989 * Returns the preferred page size for printing.
991 * @return The preferred page size, cast it to QPrinter::PageSize
993 int pageSize() const;
996 * Changes the preferred page size when printing.
998 * @param paperFormat the new preferred page size in the format QPrinter::PageSize
1000 void setPageSize(int paperFormat);
1003 * The Metric system will give you information in mm, while the
1004 * Imperial system will give you information in inches.
1006 enum MeasureSystem {
1007 Metric, ///< Metric system (used e.g. in Europe)
1008 Imperial ///< Imperial system (used e.g. in the United States)
1012 * Returns which measuring system we use.
1014 * @return The preferred measuring system
1016 MeasureSystem measureSystem() const;
1019 * Changes the preferred measuring system.
1021 * @return value The preferred measuring system
1023 void setMeasureSystem(MeasureSystem value);
1026 * Adds another catalog to search for translation lookup.
1027 * This function is useful for extern libraries and/or code,
1028 * that provide there own messages.
1030 * If the catalog does not exist for the chosen language,
1031 * it will be ignored and en_US will be used.
1033 * @param catalog The catalog to add.
1035 void insertCatalog(const QString& catalog);
1038 * Removes a catalog for translation lookup.
1039 * @param catalog The catalog to remove.
1040 * @see insertCatalog()
1042 void removeCatalog(const QString &catalog);
1045 * Sets the active catalog for translation lookup.
1046 * @param catalog The catalog to activate.
1048 void setActiveCatalog(const QString &catalog);
1051 * Translates a message as a QTranslator is supposed to.
1052 * The parameters are similar to i18n(), but the result
1053 * value has other semantics (it can be QString())
1055 QString translateQt(const char *context,
1056 const char *sourceText,
1057 const char *comment) const;
1060 * Provides list of all known language codes.
1062 * Use languageCodeToName(language) to get human readable, localized
1063 * language names.
1065 * @return list of all language codes
1067 * @see languageCodeToName
1069 QStringList allLanguagesList() const;
1072 * Convert a known language code to a human readable, localized form.
1073 * If an unknown language code is supplied, empty string is returned;
1074 * this will never happen if the code has been obtained by one of the
1075 * KLocale methods.
1077 * @param language the language code
1079 * @return the human readable and localized form if the code is known,
1080 * empty otherwise
1082 * @see language
1083 * @see languageList
1084 * @see allLanguagesList
1086 QString languageCodeToName(const QString &language) const;
1089 * Provides list of all known country codes.
1091 * Use countryCodeToName(country) to get human readable, localized
1092 * country names.
1094 * @return a list of all country codes
1096 * @see countryCodeToName
1098 QStringList allCountriesList() const;
1101 * Convert a known country code to a human readable, localized form.
1103 * If an unknown country code is supplied, empty string is returned;
1104 * this will never happen if the code has been obtained by one of the
1105 * KLocale methods.
1107 * @param country the country code
1109 * @return the human readable and localized form of the country name
1111 * @see country
1112 * @see allCountriesList
1114 QString countryCodeToName(const QString &country) const;
1117 * Parses locale string into distinct parts.
1118 * The format of locale is language_COUNTRY@modifier.CHARSET
1120 * @param locale the locale string to split
1121 * @param language set to the language part of the locale
1122 * @param country set to the country part of the locale
1123 * @param modifier set to the modifer part of the locale
1124 * @param charset set to the charset part of the locale
1126 static void splitLocale(const QString &locale,
1127 QString &language,
1128 QString &country,
1129 QString &modifier,
1130 QString &charset);
1133 * Use this as main catalog for *all* KLocales, if not the appname
1134 * will be used. This function is best to be the very first instruction
1135 * in your program's main function as it only has an effect before the
1136 * first KLocale object is created.
1138 * @param catalog Catalog to override all other main Catalogs.
1140 static void setMainCatalog(const char *catalog);
1143 * @deprecated
1145 * Finds localized resource in resourceDir( rtype ) + \<lang> + fname.
1147 * Since KDE 4.1, this service is provided in a slightly different form,
1148 * automatically by e.g. KStandardDirs::locate() and other KDE core classes
1149 * dealing with paths. For manual use, it is replaced by localizedFilePath().
1151 * @param fname relative path to find
1152 * @param rtype resource type to use
1154 * @return path to localized resource
1156 * @see localizedFilePath
1158 static QString langLookup(const QString &fname, const char *rtype = "html");
1161 * Returns the name of the internal language.
1163 * @return Name of the default language
1165 static QString defaultLanguage();
1168 * Returns the name of the default country.
1170 * @return Name of the default country
1172 static QString defaultCountry();
1175 * Reports whether evaluation of translation scripts is enabled.
1177 * @return true if script evaluation is enabled, false otherwise.
1179 bool useTranscript() const;
1182 * Checks whether or not the active catalog is found for the given language.
1184 * @param language language to check
1186 bool isApplicationTranslatedInto( const QString & language);
1189 * Copies the catalogs of this object to an other KLocale object.
1191 * @param locale the destination KLocale object
1193 void copyCatalogsTo(KLocale *locale);
1196 * Changes the current country. The current country will be left
1197 * unchanged if failed. It will force a reload of the country specific
1198 * configuration.
1200 * @param country the ISO 3166 country code
1201 * @param config a configuration file with a Locale group detailing
1202 * locale-related preferences (such as date and time
1203 * formatting)
1205 * @return @c true on success, @c false on failure
1207 bool setCountry(const QString & country, KConfig *config);
1210 * Changes the current language. The current language will be left
1211 * unchanged if failed. It will force a reload of the country specific
1212 * configuration as well.
1214 * @param language the language code
1215 * @param config a configuration file with a Locale group detailing
1216 * locale-related preferences (such as date and time
1217 * formatting)
1219 * @return true on success
1221 bool setLanguage(const QString &language, KConfig *config);
1224 * Changes the list of preferred languages for the locale. The first valid
1225 * language in the list will be used, or the default language (en_US)
1226 * if none of the specified languages were available.
1228 * @param languages the list of language codes
1230 * @return true if one of the specified languages were used
1232 bool setLanguage(const QStringList &languages);
1235 * @since 4.1
1237 * Tries to find a path to the localized file for the given original path.
1238 * This is intended mainly for non-text resources (images, sounds, etc.),
1239 * whereas text resources should be handled in more specific ways.
1241 * The possible localized paths are checked in turn by priority of set
1242 * languages, in form of dirname/l10n/ll/basename, where dirname and
1243 * basename are those of the original path, and ll is the language code.
1245 * KDE core classes which resolve paths internally (e.g. KStandardDirs)
1246 * will usually perform this lookup behind the scene.
1247 * In general, you should pipe resource paths through this method only
1248 * on explicit translators' request, or when a resource is an obvious
1249 * candidate for localization (e.g. a splash screen or a custom icon
1250 * with some text drawn on it).
1252 * @param filePath path to the original file
1254 * @return path to the localized file if found, original path otherwise
1256 QString localizedFilePath(const QString &filePath) const;
1259 * @since 4.2
1261 * Removes accelerator marker from a UI text label.
1263 * Accelerator marker is not always a plain ampersand (&),
1264 * so it is not enough to just remove it by @c QString::remove().
1265 * The label may contain escaped markers ("&&") which must be resolved
1266 * and skipped, as well as CJK-style markers ("Foo (&F)") where
1267 * the whole parenthesis construct should be removed.
1268 * Therefore always use this function to remove accelerator marker
1269 * from UI labels.
1271 * @param label UI label which may contain an accelerator marker
1272 * @return label without the accelerator marker
1274 QString removeAcceleratorMarker(const QString &label) const;
1276 private:
1277 KLocalePrivate * const d;
1280 Q_DECLARE_OPERATORS_FOR_FLAGS(KLocale::DateTimeFormatOptions)
1282 #endif