KLocale Class Reference
#include <klocale.h>
Detailed Description
KLocale provides support for country specific stuff like the national language.class for supporting locale settings and national language.KLocale supports translating, as well as specifying the format for numbers, currency, time, and date.
- Author:
- Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>, Hans Petter Bieker <bieker@kde.org>, Lukas Tinkl <lukas.tinkl@suse.cz>
Definition at line 124 of file klocale.h.
Public Types | |
enum | SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, AfterQuantityMoney = 2, BeforeMoney = 3, AfterMoney = 4 } |
enum | ReadDateFlags { NormalFormat = 1, ShortFormat = 2 } |
enum | ReadTimeFlags { WithSeconds = 0, WithoutSeconds = 1 } |
enum | MeasureSystem { Metric, Imperial } |
Public Member Functions | |
KLocale (const QString &catalog, KConfig *config=0) | |
KLocale (const KLocale &rhs) | |
KLocale & | operator= (const KLocale &rhs) |
~KLocale () | |
QString | translate (const char *index) const |
QString | translate (const char *comment, const char *fallback) const |
QString | translate (const char *singular, const char *plural, unsigned long n) const |
bool | setEncoding (int mibEnum) |
bool | setLanguage (const QString &language) |
bool | setLanguage (const QStringList &languages) |
bool | setCountry (const QString &country) |
QString | decimalSymbol () const |
QString | thousandsSeparator () const |
QString | currencySymbol () const |
QString | monetaryDecimalSymbol () const |
QString | monetaryThousandsSeparator () const |
QString | positiveSign () const |
QString | negativeSign () const |
int | fracDigits () const |
bool | positivePrefixCurrencySymbol () const |
bool | negativePrefixCurrencySymbol () const |
SignPosition | positiveMonetarySignPosition () const |
SignPosition | negativeMonetarySignPosition () const |
QString | formatMoney (double num, const QString ¤cy=QString::null, int digits=-1) const |
QString | formatNumber (double num, int precision=-1) const |
QString | formatNumber (const QString &numStr) const KDE_DEPRECATED |
QString | formatNumber (const QString &numStr, bool round, int precision) const |
QString | formatLong (long num) const |
bool | nounDeclension () const |
QString | formatDate (const QDate &pDate, bool shortFormat=false) const |
bool | dateMonthNamePossessive () const |
QString | formatTime (const QTime &pTime, bool includeSecs, bool isDuration) const |
QString | formatTime (const QTime &pTime, bool includeSecs=false) const |
bool | use12Clock () const |
bool | weekStartsMonday () const KDE_DEPRECATED |
int | weekStartDay () const |
QString | monthName (int i, bool shortName=false) const KDE_DEPRECATED |
QString | monthNamePossessive (int i, bool shortName=false) const KDE_DEPRECATED |
QString | weekDayName (int i, bool shortName=false) const KDE_DEPRECATED |
const KCalendarSystem * | calendar () const |
QString | calendarType () const |
void | setCalendar (const QString &calendarType) |
QString | formatDateTime (const QDateTime &pDateTime, bool shortFormat=true, bool includeSecs=false) const |
double | readMoney (const QString &numStr, bool *ok=0) const |
double | readNumber (const QString &numStr, bool *ok=0) const |
QDate | readDate (const QString &str, bool *ok=0) const |
QDate | readDate (const QString &intstr, const QString &fmt, bool *ok=0) const |
QDate | readDate (const QString &str, ReadDateFlags flags, bool *ok=0) const |
QTime | readTime (const QString &str, bool *ok=0) const |
QTime | readTime (const QString &str, ReadTimeFlags flags, bool *ok=0) const |
QString | language () const |
QString | country () const |
QStringList | languagesTwoAlpha () const |
QStringList | languageList () const |
const char * | encoding () const |
int | encodingMib () const |
QTextCodec * | codecForEncoding () const |
int | fileEncodingMib () const |
void | setDateFormat (const QString &format) |
void | setDateFormatShort (const QString &format) |
void | setDateMonthNamePossessive (bool possessive) |
void | setTimeFormat (const QString &format) |
void | setWeekStartsMonday (bool start) KDE_DEPRECATED |
void | setWeekStartDay (int day) |
QString | dateFormat () const |
QString | dateFormatShort () const |
QString | timeFormat () const |
void | setDecimalSymbol (const QString &symbol) |
void | setThousandsSeparator (const QString &separator) |
void | setPositiveSign (const QString &sign) |
void | setNegativeSign (const QString &sign) |
void | setPositiveMonetarySignPosition (SignPosition signpos) |
void | setNegativeMonetarySignPosition (SignPosition signpos) |
void | setPositivePrefixCurrencySymbol (bool prefix) |
void | setNegativePrefixCurrencySymbol (bool prefix) |
void | setFracDigits (int digits) |
void | setMonetaryThousandsSeparator (const QString &separator) |
void | setMonetaryDecimalSymbol (const QString &symbol) |
void | setCurrencySymbol (const QString &symbol) |
int | pageSize () const |
void | setPageSize (int paperFormat) |
MeasureSystem | measureSystem () const |
void | setMeasureSystem (MeasureSystem value) |
void | insertCatalogue (const QString &catalog) |
void | removeCatalogue (const QString &catalog) |
void | setActiveCatalogue (const QString &catalog) |
QString | translateQt (const char *context, const char *sourceText, const char *message) const |
QStringList | allLanguagesTwoAlpha () const |
QString | twoAlphaToLanguageName (const QString &code) const |
QStringList | allCountriesTwoAlpha () const |
QString | twoAlphaToCountryName (const QString &code) const |
QString | formatMoney (const QString &numStr) const KDE_DEPRECATED |
QString | languages () const KDE_DEPRECATED |
bool | setCharset (const QString &charset) KDE_DEPRECATED |
QString | charset () const KDE_DEPRECATED |
bool | isApplicationTranslatedInto (const QString &language) |
Static Public Member Functions | |
static void | splitLocale (const QString &str, QString &language, QString &country, QString &charset) |
static void | setMainCatalogue (const char *catalog) |
static QString | langLookup (const QString &fname, const char *rtype="html") |
static QString | defaultLanguage () |
static QString | defaultCountry () |
static QString | _initLanguage (KConfigBase *config) |
Static Protected Member Functions | |
static void | initInstance () |
Friends | |
class | KGlobal |
Related Functions | |
(Note that these are not member functions.) | |
I18N_NOOP(x) | |
I18N_NOOP2(comment, x) | |
QString | i18n (const char *text) |
QString | i18n (const char *comment, const char *text) |
QString | i18n (const char *singular, const char *plural, unsigned long n) |
QString | tr2i18n (const char *message, const char *=0) |
Member Enumeration Documentation
|
The Metric system will give you information in mm, while the Imperial system will give you information in inches.
|
|
Various positions for where to place the positive or negative sign when they are related to a monetary value.
|
Constructor & Destructor Documentation
|
Constructs a KLocale with the given catalog name. The constructor looks for an entry Locale/Language in the configuration file. If no config file is specified, it will also look for languages using the environment variables (KDE_LANG, LC_MESSAGES, LC_ALL, LANG), as well as the global configuration file. If KLocale is not able to use any of the specified languages, the default language (en_US) will be used. If you specify a configuration file, it has to be valid until the KLocale object is destroyed.
Definition at line 84 of file klocale.cpp. |
|
Copy constructor.
Definition at line 2412 of file klocale.cpp. |
|
Destructor.
Definition at line 705 of file klocale.cpp. |
Member Function Documentation
|
Returns list of all known country codes.
Definition at line 2363 of file klocale.cpp. |
|
Returns list of all known ISO 639-1 codes.
Definition at line 2342 of file klocale.cpp. |
|
Returns a pointer to the calendar system object.
Definition at line 2401 of file klocale.cpp. |
|
Returns the name of the calendar system that is currently being used by the system.
Definition at line 2394 of file klocale.cpp. |
|
Definition at line 2452 of file klocale.cpp. |
|
Returns the user's preferred encoding. Should never be NULL.
Definition at line 2288 of file klocale.cpp. |
|
Returns the country code of the country where the user lives. defaultCountry() is returned by default, if no other available.
Definition at line 552 of file klocale.cpp. |
|
Returns what the symbol denoting currency in the current locale as as defined by user settings should look like.
Definition at line 1036 of file klocale.cpp. |
|
Returns the currently selected date format.
Definition at line 2132 of file klocale.cpp. |
|
Returns the currently selected short date format.
Definition at line 2138 of file klocale.cpp. |
|
Use this to determine whether in dates a possessive form of month name is preferred ("of January" rather than "January").
Definition at line 1006 of file klocale.cpp. |
|
Returns what a decimal point should look like ("." or "," etc. ) according to the current locale or user settings.
Definition at line 1024 of file klocale.cpp. |
|
Returns the name of the default country.
Definition at line 2254 of file klocale.cpp. |
|
Returns the name of the internal language.
Definition at line 2249 of file klocale.cpp. |
|
Returns the user's preferred encoding.
Definition at line 2259 of file klocale.cpp. |
|
Returns the user's preferred encoding.
Definition at line 2276 of file klocale.cpp. |
|
Returns the file encoding.
Definition at line 2281 of file klocale.cpp. |
|
Returns a string formatted to the current locale's conventions regarding dates.
Definition at line 1331 of file klocale.cpp. |
|
Returns a string formated to the current locale's conventions regarding both date and time.
Definition at line 1961 of file klocale.cpp. |
|
Given an integer, converts that to a numeric string containing the localized numeric equivalent. e.g. given 123456L, return "123,456" (for some European country).
Definition at line 1196 of file klocale.cpp. |
|
Definition at line 1184 of file klocale.cpp. |
|
Given a double, converts that to a numeric string containing the localized monetary equivalent. e.g. given 123456, return "$ 123,456.00".
Definition at line 1123 of file klocale.cpp. |
|
Given a string representing a number, converts that to a numeric string containing the localized numeric equivalent. e.g. given 123456.78F, return "123,456.78" (for some European country).
Definition at line 1297 of file klocale.cpp. |
|
KDE 4.0: merge with formatNumber(const QString int) calls formatNumber(numStr, 2) Definition at line 1201 of file klocale.cpp. |
|
Given a double, converts that to a numeric string containing the localized numeric equivalent. e.g. given 123456.78F, return "123,456.78" (for some European country). If precision isn't specified, 2 is used. This function is a wrapper that is provided for convenience.
Definition at line 1189 of file klocale.cpp. |
|
Returns a string formatted to the current locale's conventions regarding times.
Definition at line 1851 of file klocale.cpp. |
|
Returns a string formatted to the current locale's conventions regarding times.
Definition at line 1856 of file klocale.cpp. |
|
The number of fractional digits to include in numeric/monetary values (usually 2).
Definition at line 1066 of file klocale.cpp. |
|
Adds another catalog to search for translation lookup. This function is useful for extern libraries and/or code, that provide there own messages. If the catalog does not exist for the chosen language, it will be ignored and en_US will be used.
Definition at line 638 of file klocale.cpp. |
|
Finds localized resource in resourceDir( rtype ) + <lang> + fname.
Definition at line 2013 of file klocale.cpp. |
|
Returns the language used by this object. The domain AND the library translation must be available in this language. defaultLanguage() is returned by default, if no other available.
Definition at line 547 of file klocale.cpp. |
|
Returns the languages selected by user. The codes returned here is the internal language codes.
Definition at line 1956 of file klocale.cpp. |
|
Definition at line 1951 of file klocale.cpp. |
|
Returns the preferred languages as ISO 639-1 codes. This means that information about country is removed. If the internal language code might be represented by more than one 639-1 code, they will all be listed (but only once). If the selected languages are "nn, nb, pt_BR", you will get: "nn, nb, pt".
Definition at line 2302 of file klocale.cpp. |
|
Returns which measuring system we use.
Definition at line 2237 of file klocale.cpp. |
|
Returns what a decimal point should look like ("." or "," etc. ) for monetary values, according to the current locale or user settings.
Definition at line 1042 of file klocale.cpp. |
|
Returns what a thousands separator for monetary values should look like ("," or " " etc. ) according to the current locale or user settings.
Definition at line 1048 of file klocale.cpp. |
|
Returns a string containing the name of the month name used in the Gregorian calendar.
#include <kcalendarsystem.h>
Definition at line 557 of file klocale.cpp. |
|
Returns a string containing the possessive form of the month name used in the Gregorian calendar. ("of January", "of February", etc.) It's needed in long format dates in some languages.
#include <kcalendarsystem.h>
Definition at line 595 of file klocale.cpp. |
|
Denotes where to place a negative sign in relation to a monetary value.
Definition at line 1090 of file klocale.cpp. |
|
If and only if the currency symbol precedes a negative value, this will be true.
Definition at line 1078 of file klocale.cpp. |
|
Returns what a negative sign should look like ("-", etc. ) according to the current locale or user settings.
Definition at line 1060 of file klocale.cpp. |
|
Use this to determine whether nouns are declined in locale's language. This property should remain read-only (no setter function)
Definition at line 1000 of file klocale.cpp. |
|
Assignment operator.
Definition at line 2419 of file klocale.cpp. |
|
Returns the preferred page size for printing.
Definition at line 2224 of file klocale.cpp. |
|
Returns the position of a positive sign in relation to a monetary value.
Definition at line 1084 of file klocale.cpp. |
|
If and only if the currency symbol precedes a positive value, this will be true.
Definition at line 1072 of file klocale.cpp. |
|
Returns what a positive sign should look like ("+", " ", etc. ) according to the current locale or user settings.
Definition at line 1054 of file klocale.cpp. |
|
Converts a localized date string to a QDate.
This method is stricter than readDate(str,&ok): it will either accept a date in full format or a date in short format, depending on
Definition at line 1598 of file klocale.cpp. |
|
Converts a localized date string to a QDate, using the specified format. You will usually not want to use this method. Definition at line 1604 of file klocale.cpp. |
|
Converts a localized date string to a QDate. The bool pointed by ok will be invalid if the date entered was not valid.
Definition at line 1590 of file klocale.cpp. |
|
Converts a localized monetary string to a double.
Definition at line 1476 of file klocale.cpp. |
|
Converts a localized numeric string to a double.
Definition at line 1411 of file klocale.cpp. |
|
Converts a localized time string to a QTime. This method is stricter than readTime(str,&ok): it will either accept a time with seconds or a time without seconds. Use this method when the format is known by the application.
Definition at line 1743 of file klocale.cpp. |
|
Converts a localized time string to a QTime.
This method will try to parse it with seconds, then without seconds. The bool pointed to by
Definition at line 1735 of file klocale.cpp. |
|
Removes a catalog for translation lookup.
Definition at line 687 of file klocale.cpp. |
|
Sets the active catalog for translation lookup.
Definition at line 696 of file klocale.cpp. |
|
Changes the current calendar system to the calendar specified. Currently "gregorian" and "hijri" are supported. If the calendar system specified is not found, gregorian will be used.
Definition at line 2384 of file klocale.cpp. |
|
Definition at line 2451 of file klocale.cpp. |
|
Changes the current country. The current country will be left unchanged if failed. It will force a reload of the country specific configuration.
Definition at line 391 of file klocale.cpp. |
|
Changes the current currency symbol.
Definition at line 2218 of file klocale.cpp. |
|
Changes the current date format. The format of the date is a string which contains variables that will be replaced:
Definition at line 2090 of file klocale.cpp. |
|
Changes the current short date format. The format of the date is a string which contains variables that will be replaced:
Definition at line 2096 of file klocale.cpp. |
|
Changes the form of month name used in dates.
Definition at line 2102 of file klocale.cpp. |
|
Changes the symbol used to identify the decimal pointer.
Definition at line 2150 of file klocale.cpp. |
|
Changes the current encoding.
Definition at line 2293 of file klocale.cpp. |
|
Changes the number of digits used when formating numbers.
Definition at line 2199 of file klocale.cpp. |
|
Changes the list of prefed languages for the locale. The first valid language in the list will be used, or the default (en_US) language will be used if non of the specified languages were available.
Definition at line 432 of file klocale.cpp. |
|
Changes the current language. The current language will be left unchanged if failed. It will force a reload of the country specific configuration as well.
Definition at line 414 of file klocale.cpp. |
|
Use this as main catalog for *all* KLocales, if not the appname will be used. This function is best to be the very first instruction in your program's main function as it only has an effect before the first KLocale object is created.
Definition at line 1406 of file klocale.cpp. |
|
Changes the preferred measuring system.
Definition at line 2243 of file klocale.cpp. |
|
Changes the symbol used to identify the decimal pointer for monetary values.
Definition at line 2212 of file klocale.cpp. |
|
Changes the separator used to group digits when formating monetary values.
Definition at line 2205 of file klocale.cpp. |
|
Changes the sign position used for negative monetary values.
Definition at line 2181 of file klocale.cpp. |
|
Changes the position where the currency symbol should be printed for negative monetary values.
Definition at line 2193 of file klocale.cpp. |
|
Changes the sign used to identify a negative number.
Definition at line 2169 of file klocale.cpp. |
|
Changes the preferred page size when printing.
Definition at line 2230 of file klocale.cpp. |
|
Changes the sign position used for positive monetary values.
Definition at line 2175 of file klocale.cpp. |
|
Changes the position where the currency symbol should be printed for positive monetary values.
Definition at line 2187 of file klocale.cpp. |
|
Changes the sign used to identify a positive number. Normally this is left blank.
Definition at line 2163 of file klocale.cpp. |
|
Changes the separator used to group digits when formating numbers.
Definition at line 2156 of file klocale.cpp. |
|
Changes the current time format. The format of the time is string a which contains variables that will be replaced:
Definition at line 2108 of file klocale.cpp. |
|
Changes how KLocale defines the first day in week.
Definition at line 2123 of file klocale.cpp. |
|
Please use setWeekStartDay instead. Changes how KLocale defines the first day in week.
Definition at line 2114 of file klocale.cpp. |
|
Returns the parts of the parameter str understood as language setting the format is language_COUNTRY.charset.
Definition at line 514 of file klocale.cpp. |
|
Returns what the thousands separator should look like ("," or "." etc. ) according to the current locale or user settings.
Definition at line 1030 of file klocale.cpp. |
|
Returns the currently selected time format.
Definition at line 2144 of file klocale.cpp. |
|
Used to get the correct, translated singular or plural of a word.
Definition at line 803 of file klocale.cpp. |
|
Translates the string into the corresponding string in the national language, if available. The real contents of the string is in the argument fallback, but the meaning of it is coded into the argument index. In some cases you'll need this function, when english is too ambiguous to express it. Most of the times the translators will tell you if it can't be translated as it, but think of cases as "New", where the translations differs depending on what is New. Or simple cases as "Open", that can be used to express something is open or it can be used to express that you want something to open... There are tons of such examples. If translate("Open") is not enough to translate it well, use translate("To Open", "Open") or translate("Is Open", "Open"). The english user will see "Open" in both cases, but the translated version may vary. Of course you can also use i18n()
Definition at line 767 of file klocale.cpp. |
|
Translates the string into the corresponding string in the national language, if available. If not, returns the string itself. There is a KDE wide message file that contains the most often used phrases, so we can avoid duplicating the translation of these phrases. If a phrase is not found in the catalog given to the constructor, it will search in the system catalog. This makes it possible to override some phrases for your needs. The argument must be an UTF-8 encoded string (If you only use characters that are in US-ASCII you're on the safe side. But for e.g. german umlauts or french accents should be recoded to UTF-8)
Definition at line 762 of file klocale.cpp. |
|
Translates a message as a QTranslator is supposed to. The parameters are similar to i18n(), but the result value has other semantics (it can be QString::null)
Definition at line 956 of file klocale.cpp. |
|
Convert a country code to a human readable form.
Definition at line 2377 of file klocale.cpp. |
|
Convert a ISO 639-1 code to a human readable form.
Definition at line 2350 of file klocale.cpp. |
|
Use this to determine if the user wants a 12 hour clock.
Definition at line 1942 of file klocale.cpp. |
|
Definition at line 633 of file klocale.cpp. |
|
Use this to determine which day is the first day of the week.
Definition at line 1012 of file klocale.cpp. |
|
Please use the weekStartDay method instead. Use this to determine if the user wants the week to start on Monday.
Definition at line 1018 of file klocale.cpp. |
Friends And Related Function Documentation
|
If you want to handle plural forms, use this form of i18n.
Definition at line 1986 of file klocale.cpp. |
|
If the string is too ambiguous to be translated well to a non-english language, use this form of i18n to separate lookup string and english text.
Definition at line 1978 of file klocale.cpp. |
|
i18n is the function that does everything you need to translate a string. You just wrap around every user visible string a i18n call to get a QString with the string in the user's preferred language. The argument must be an UTF-8 encoded string (If you only use characters that are in US-ASCII, you're on the safe side. But for e.g. German umlauts or French accents should be recoded to UTF-8) Definition at line 1970 of file klocale.cpp. |
|
I18N_NOOP marks a string to be translated without translating it. Do not use this unless you know you need it. http://developer.kde.org/documentation/other/developer-faq.html#q2.11.2 |
|
If the string is too ambiguous to be translated well to a non-english language, use this instead of I18N_NOOP to separate lookup string and english.
|
|
Qt3's uic generates i18n( "msg", "comment" ) calls which conflict with our i18n method. We use uic -tr tr2i18n to redirect to the right i18n() function |
The documentation for this class was generated from the following files: