KLocale Class Reference

`#include <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 &currency=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.)
#define | I18N_NOOP(x) x
#define | I18N_NOOP2(comment, x) 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)

## Detailed Description

KLocale provides support for country specific stuff like the national language.

KLocale supports translating, as well as specifying the format for numbers, currency, time, and date.

Author
  Stephan Kulow coolo.nosp@m.@kde.nosp@m..org, Preston Brown pbrow.nosp@m.n@kd.nosp@m.e.org, Hans Petter Bieker bieke.nosp@m.r@kd.nosp@m.e.org, Lukas Tinkl lukas.nosp@m..tin.nosp@m.kl@su.nosp@m.se.c.nosp@m.z class for supporting locale settings and national language

Definition at line 124 of file klocale.h.

## Member Enumeration Documentation

enum KLocale::MeasureSystem

The Metric system will give you information in mm, while the Imperial system will give you information in inches.

Definition at line 1012 of file klocale.h.

enum KLocale::SignPosition

Various positions for where to place the positive or negative sign when they are related to a monetary value.

Definition at line 267 of file klocale.h.

## Constructor & Destructor Documentation

KLocale::KLocale | ( | const QString & | catalog,
|  | KConfig * | config = `0`
| ) |  |

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.

Parameters

  catalog | The name of the main language file
  config | The configuration file to use.

Definition at line 83 of file klocale.cpp.

KLocale::KLocale | ( | const KLocale & | rhs | ) |

Copy constructor.

Definition at line 2403 of file klocale.cpp.

KLocale::~KLocale | ( |  | ) |

Destructor.

Definition at line 696 of file klocale.cpp.

## Member Function Documentation

QStringList KLocale::allCountriesTwoAlpha | ( |  | ) | const

Returns list of all known country codes.

Returns
  a list of all country codes

Since
  3.1

Definition at line 2354 of file klocale.cpp.

QStringList KLocale::allLanguagesTwoAlpha | ( |  | ) | const

Returns list of all known ISO 639-1 codes.

Returns
  a list of all language codes

Since
  3.1

Definition at line 2333 of file klocale.cpp.

const KCalendarSystem * KLocale::calendar | ( |  | ) | const

Returns a pointer to the calendar system object.

Returns
  the current calendar system instance

Since
  3.2

Definition at line 2392 of file klocale.cpp.

QString KLocale::calendarType | ( |  | ) | const

Returns the name of the calendar system that is currently being used by the system.

Returns
  the name of the calendar system

Since
  3.2

Definition at line 2385 of file klocale.cpp.

QString KLocale::charset | ( |  | ) | const

Deprecated:
  See also
    encoding

Definition at line 2443 of file klocale.cpp.

QTextCodec * KLocale::codecForEncoding | ( |  | ) | const

Returns the user's preferred encoding.

Should never be NULL.

Returns
  The codec for the preferred encoding

See also
  encoding
  encodingMib

Definition at line 2279 of file klocale.cpp.

QString KLocale::country | ( |  | ) | const

Returns the country code of the country where the user lives.

defaultCountry() is returned by default, if no other available.

Returns
  The country code for the user.

Definition at line 543 of file klocale.cpp.

QString KLocale::currencySymbol | ( |  | ) | const

Returns what the symbol denoting currency in the current locale as as defined by user settings should look like.

Returns
  The default currency symbol used by locale.

Definition at line 1027 of file klocale.cpp.

QString KLocale::dateFormat | ( |  | ) | const

Returns the currently selected date format.

Returns
  Current date format.

See also
  setDateFormat()

Definition at line 2123 of file klocale.cpp.

QString KLocale::dateFormatShort | ( |  | ) | const

Returns the currently selected short date format.

Returns
  Current short date format.

See also
  setDateFormatShort()

Definition at line 2129 of file klocale.cpp.

bool KLocale::dateMonthNamePossessive | ( |  | ) | const

Use this to determine whether in dates a possessive form of month name is preferred ("of January" rather than "January")

Returns
  If possessive form should be used

Since
  3.1

Definition at line 997 of file klocale.cpp.

QString KLocale::decimalSymbol | ( |  | ) | const

Returns what a decimal point should look like ("." or "," etc.) according to the current locale or user settings.

Returns
  The decimal symbol used by locale.

Definition at line 1015 of file klocale.cpp.

QString KLocale::defaultCountry | ( |  | ) |

static

Returns the name of the default country.

Returns
  Name of the default country

Definition at line 2245 of file klocale.cpp.

QString KLocale::defaultLanguage | ( |  | ) |

static

Returns the name of the internal language.

Returns
  Name of the default language

Definition at line 2240 of file klocale.cpp.

const char * KLocale::encoding | ( |  | ) | const

Returns the user's preferred encoding.

Returns
  The name of the preferred encoding

See also
  codecForEncoding
  encodingMib

Definition at line 2250 of file klocale.cpp.

int KLocale::encodingMib | ( |  | ) | const

Returns the user's preferred encoding.

Returns
  The Mib of the preferred encoding

See also
  encoding
  codecForEncoding

Definition at line 2267 of file klocale.cpp.

int KLocale::fileEncodingMib | ( |  | ) | const

Returns the file encoding.

Returns
  The Mib of the file encoding

See also
  QFile::encodeName
  QFile::decodeName

Definition at line 2272 of file klocale.cpp.

QString KLocale::formatDate | ( | const QDate & | pDate,
|  | bool | shortFormat = `false`
| ) |  | const

Returns a string formatted to the current locale's conventions regarding dates.

Parameters

  pDate | The date to be formated.
  shortFormat | True for non text dates.

Returns
  The date as a string

Definition at line 1322 of file klocale.cpp.

QString KLocale::formatDateTime | ( | const QDateTime & | pDateTime,
|  | bool | shortFormat = `true`,
|  | bool | includeSecs = `false`
| ) |  | const

Returns a string formated to the current locale's conventions regarding both date and time.

Parameters

  pDateTime | The date and time to be formated.
  shortFormat | using the short date format.
  includeSecs | using the short date format.

Returns
  The date and time as a string

Definition at line 1952 of file klocale.cpp.

QString KLocale::formatLong | ( | long | num | ) | const

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).

Parameters

  num | The number to convert

Returns
  The number as a localized string

Since
  3.2

Definition at line 1187 of file klocale.cpp.

QString KLocale::formatMoney | ( | double | num,
|  | const QString & | currency = `QString::null`,
|  | int | digits = `-1`
| ) |  | const

Given a double, converts that to a numeric string containing the localized monetary equivalent.

e.g. given 123456, return "$ 123,456.00".

Parameters

  num | The number we want to format
  currency | The currency symbol you want.
  digits | Number of fractional digits, or -1 for the default value

Returns
  The number of money as a localized string

See also
  fracDigits()

Definition at line 1114 of file klocale.cpp.

QString KLocale::formatMoney | ( | const QString & | numStr | ) | const

Deprecated:
  use formatMoney(double)

Definition at line 1175 of file klocale.cpp.

QString KLocale::formatNumber | ( | double | num,
|  | int | precision = `-1`
| ) |  | const

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.

Parameters

  num | The number to convert
  precision | Number of fractional digits used.

Returns
  The number as a localized string

See also
  formatNumber(const QString, bool, int)

Definition at line 1180 of file klocale.cpp.

QString KLocale::formatNumber | ( | const QString & | numStr | ) | const

Deprecated:

KDE 4.0: merge with formatNumber(const QString int)

calls formatNumber(numStr, 2)

Definition at line 1192 of file klocale.cpp.

QString KLocale::formatNumber | ( | const QString & | numStr,
|  | bool | round,
|  | int | precision
| ) |  | const

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).

Parameters

  numStr | The number to convert
  round | Round fractional digits.
  precision | Number of fractional digits used.

Returns
  The number as a localized string

Since
  3.5

Definition at line 1288 of file klocale.cpp.

QString KLocale::formatTime | ( | const QTime & | pTime,
|  | bool | includeSecs,
|  | bool | isDuration
| ) |  | const

Returns a string formatted to the current locale's conventions regarding times.

Parameters

  pTime | The time to be formated.
  includeSecs | if true, seconds are included in the output, otherwise only hours and minutes are formatted.
  isDuration | if true, the given time is a duration, not a clock time. This means "am/pm" shouldn't be displayed.

Returns
  The time as a string

Definition at line 1847 of file klocale.cpp.

QString KLocale::formatTime | ( | const QTime & | pTime,
|  | bool | includeSecs = `false`
| ) |  | const

Returns a string formatted to the current locale's conventions regarding times.

Parameters

  pTime | The time to be formated.
  includeSecs | if true, seconds are included in the output, otherwise only hours and minutes are formatted.

Returns
  The time as a string

Definition at line 1842 of file klocale.cpp.

int KLocale::fracDigits | ( |  | ) | const

The number of fractional digits to include in numeric/monetary values (usually 2).

Returns
  Default number of fractional digits used by locale.

Definition at line 1057 of file klocale.cpp.

void KLocale::insertCatalogue | ( | const QString & | catalog | ) |

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.

Parameters

  catalog | The catalog to add.

Definition at line 629 of file klocale.cpp.

QString KLocale::langLookup | ( | const QString & | fname,
|  | const char * | rtype = `"html"`
| ) |  |

static

Finds localized resource in resourceDir( rtype ) + <lang> + fname.

Parameters

  fname | relative path to find
  rtype | resource type to use

Definition at line 2004 of file klocale.cpp.

QString KLocale::language | ( |  | ) | const

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.

Returns
  The currently used language.

Definition at line 538 of file klocale.cpp.

QStringList KLocale::languageList | ( |  | ) | const

Returns the languages selected by user.

The codes returned here is the internal language codes.

Returns
  List of language codes

See also
  languagesTwoAlpha

Definition at line 1947 of file klocale.cpp.

QString KLocale::languages | ( |  | ) | const

Deprecated:
  Use languageList()

Returns
  String containing language codes separated by colons

Definition at line 1942 of file klocale.cpp.

QStringList KLocale::languagesTwoAlpha | ( |  | ) | const

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".

Returns
  List of language codes

See also
  languageList

Definition at line 2293 of file klocale.cpp.

KLocale::MeasureSystem KLocale::measureSystem | ( |  | ) | const

Returns which measuring system we use.

Returns
  The preferred measuring system

Definition at line 2228 of file klocale.cpp.

QString KLocale::monetaryDecimalSymbol | ( |  | ) | const

Returns what a decimal point should look like ("." or "," etc.) for monetary values, according to the current locale or user settings.

Returns
  The monetary decimal symbol used by locale.

Definition at line 1033 of file klocale.cpp.

QString KLocale::monetaryThousandsSeparator | ( |  | ) | const

Returns what a thousands separator for monetary values should look like ("," or " " etc.) according to the current locale or user settings.

Returns
  The monetary thousands separator used by locale.

Definition at line 1039 of file klocale.cpp.

QString KLocale::monthName | ( | int | i,
|  | bool | shortName = `false`
| ) |  | const

Deprecated:

Returns a string containing the name of the month name used in the Gregorian calendar.

Parameters

  i | the month number of the year starting at 1/January.
  shortName | we will return the short version of the string.

Returns
  The name of the month

Typically the correct replacement for this deprecated class is calendar()->monthString(), which requires a QDate (rather than an integer month) or both a month and a year. This will work across different calendars. Note that you also need to add

#include <kcalendarsystem.h>

to the applicable file.

Definition at line 548 of file klocale.cpp.

QString KLocale::monthNamePossessive | ( | int | i,
|  | bool | shortName = `false`
| ) |  | const

Deprecated:

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.

Parameters

  i | the month number of the year starting at 1/January.
  shortName | we will return the short version of the string.

Returns
  The possessive form of the name of the month

Since
  3.1

Typically the correct replacement for this deprecated class is calendar()->monthNamePossessive(), which requires a QDate (rather than an integer month) or both a month and a year. This will work across different calendars. Note that you also need to add

#include <kcalendarsystem.h>

to the applicable file.

Definition at line 586 of file klocale.cpp.

KLocale::SignPosition KLocale::negativeMonetarySignPosition | ( |  | ) | const

Denotes where to place a negative sign in relation to a monetary value.

Returns
  Where/how to print the negative sign.

See also
  SignPosition

Definition at line 1081 of file klocale.cpp.

bool KLocale::negativePrefixCurrencySymbol | ( |  | ) | const

If and only if the currency symbol precedes a negative value, this will be true.

Returns
  True if the currency symbol precedes negative numbers.

Definition at line 1069 of file klocale.cpp.

QString KLocale::negativeSign | ( |  | ) | const

Returns what a negative sign should look like ("-", etc.) according to the current locale or user settings.

Returns
  The negative sign used by locale.

Definition at line 1051 of file klocale.cpp.

bool KLocale::nounDeclension | ( |  | ) | const

Use this to determine whether nouns are declined in locale's language.

This property should remain read-only (no setter function)

Returns
  If nouns are declined

Since
  3.1

Definition at line 991 of file klocale.cpp.

KLocale & KLocale::operator= | ( | const KLocale & | rhs | ) |

Assignment operator.

Definition at line 2410 of file klocale.cpp.

int KLocale::pageSize | ( |  | ) | const

Returns the preferred page size for printing.

Returns
  The preferred page size, cast it to QPrinter::PageSize

Definition at line 2215 of file klocale.cpp.

KLocale::SignPosition KLocale::positiveMonetarySignPosition | ( |  | ) | const

Returns the position of a positive sign in relation to a monetary value.

Returns
  Where/how to print the positive sign.

See also
  SignPosition

Definition at line 1075 of file klocale.cpp.

bool KLocale::positivePrefixCurrencySymbol | ( |  | ) | const

If and only if the currency symbol precedes a positive value, this will be true.

Returns
  Where to print the currency symbol for positive numbers.

Definition at line 1063 of file klocale.cpp.

QString KLocale::positiveSign | ( |  | ) | const

Returns what a positive sign should look like ("+", " ", etc.) according to the current locale or user settings.

Returns
  The positive sign used by locale.

Definition at line 1045 of file klocale.cpp.

QDate KLocale::readDate | ( | const QString & | str,
|  | bool * | ok = `0`
| ) |  | const

Converts a localized date string to a QDate.

The bool pointed by ok will be invalid if the date entered was not valid.

Parameters

  str | the string we want to convert.
  ok | the boolean that is set to false if it's not a valid date. If `ok` is 0, it will be ignored

Returns
  The string converted to a QDate

Definition at line 1581 of file klocale.cpp.

QDate KLocale::readDate | ( | const QString & | intstr,
|  | const QString & | fmt,
|  | bool * | ok = `0`
| ) |  | const

Converts a localized date string to a QDate, using the specified format.

You will usually not want to use this method.

Definition at line 1595 of file klocale.cpp.

QDate KLocale::readDate | ( | const QString & | str,
|  | ReadDateFlags | flags,
|  | bool * | ok = `0`
| ) |  | const

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 `flags`.

Parameters

  str | the string we want to convert.
  flags | whether the date string is to be in full format or in short format.
  ok | the boolean that is set to false if it's not a valid date. If `ok` is 0, it will be ignored

Returns
  The string converted to a QDate

Since
  3.2

Definition at line 1589 of file klocale.cpp.

double KLocale::readMoney | ( | const QString & | numStr,
|  | bool * | ok = `0`
| ) |  | const

Converts a localized monetary string to a double.

Parameters

  numStr | the string we want to convert.
  ok | the boolean that is set to false if it's not a number. If `ok` is 0, it will be ignored

Returns
  The string converted to a double

Definition at line 1467 of file klocale.cpp.

double KLocale::readNumber | ( | const QString & | numStr,
|  | bool * | ok = `0`
| ) |  | const

Converts a localized numeric string to a double.

Parameters

  numStr | the string we want to convert.
  ok | the boolean that is set to false if it's not a number. If `ok` is 0, it will be ignored

Returns
  The string converted to a double

Definition at line 1402 of file klocale.cpp.

QTime KLocale::readTime | ( | const QString & | str,
|  | bool * | ok = `0`
| ) |  | const

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 `ok` will be set to false if the time entered was not valid.

Parameters

  str | the string we want to convert.
  ok | the boolean that is set to false if it's not a valid time. If `ok` is 0, it will be ignored

Returns
  The string converted to a QTime

Definition at line 1726 of file klocale.cpp.

QTime KLocale::readTime | ( | const QString & | str,
|  | ReadTimeFlags | flags,
|  | bool * | ok = `0`
| ) |  | const

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.

Parameters

  str | the string we want to convert.
  flags | whether the time string is expected to contain seconds or not.
  ok | the boolean that is set to false if it's not a valid time. If `ok` is 0, it will be ignored

Returns
  The string converted to a QTime

Since
  3.2

Definition at line 1734 of file klocale.cpp.

void KLocale::removeCatalogue | ( | const QString & | catalog | ) |

Removes a catalog for translation lookup.

Parameters

  catalog | The catalog to remove.

See also
  insertCatalogue()

Definition at line 678 of file klocale.cpp.

void KLocale::setActiveCatalogue | ( | const QString & | catalog | ) |

Sets the active catalog for translation lookup.

Parameters

  catalog | The catalog to activate.

Definition at line 687 of file klocale.cpp.

void KLocale::setCalendar | ( | const QString & | calendarType | ) |

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.

Parameters

  calendarType | the name of the calendar type

Since
  3.2

Definition at line 2375 of file klocale.cpp.

bool KLocale::setCharset | ( | const QString & | charset | ) |

Deprecated:
  Returns
    True

Definition at line 2442 of file klocale.cpp.

bool KLocale::setCountry | ( | const QString & | country | ) |

Changes the current country.

The current country will be left unchanged if failed. It will force a reload of the country specific configuration.

Parameters

  country | The ISO 3166 country code.

Returns
  True on success.

Definition at line 382 of file klocale.cpp.

void KLocale::setCurrencySymbol | ( | const QString & | symbol | ) |

Changes the current currency symbol.

Parameters

  symbol | The new currency symbol

Definition at line 2209 of file klocale.cpp.

void KLocale::setDateFormat | ( | const QString & | format | ) |

Changes the current date format.

The format of the date is a string which contains variables that will be replaced:

- Y with the century (e.g. "19" for "1984")
- y with the lower 2 digits of the year (e.g. "84" for "1984")
- n with the month (January="1", December="12")
- m with the month with two digits (January="01", December="12")
- e with the day of the month (e.g. "1" on the first of march)
- d with the day of the month with two digits(e.g. "01" on the first of march)
- b with the short form of the month (e.g. "Jan" for January)
- B with the long form of the month (e.g. "January")
- a with the short form of the weekday (e.g. "Wed" for Wednesday)
- A with the long form of the weekday (e.g. "Wednesday" for Wednesday)

Everything else in the format string will be taken as is. For example, March 20th 1989 with the format "%y:%m:%d" results in "89:03:20".

Parameters

  format | The new date format

Definition at line 2081 of file klocale.cpp.

void KLocale::setDateFormatShort | ( | const QString & | format | ) |

Changes the current short date format.

The format of the date is a string which contains variables that will be replaced:

- Y with the century (e.g. "19" for "1984")
- y with the lower 2 digits of the year (e.g. "84" for "1984")
- n with the month (January="1", December="12")
- m with the month with two digits (January="01", December="12")
- e with the day of the month (e.g. "1" on the first of march)
- d with the day of the month with two digits(e.g. "01" on the first of march)
- b with the short form of the month (e.g. "Jan" for January)
- B with the long form of the month (e.g. "January")
- a with the short form of the weekday (e.g. "Wed" for Wednesday)
- A with the long form of the weekday (e.g. "Wednesday" for Wednesday)

Everything else in the format string will be taken as is. For example, March 20th 1989 with the format "%y:%m:%d" results in "89:03:20".

Parameters

  format | The new short date format

Definition at line 2087 of file klocale.cpp.

void KLocale::setDateMonthNamePossessive | ( | bool | possessive | ) |

Changes the form of month name used in dates.

Parameters

  possessive | True if possessive forms should be used

Since
  3.1

Definition at line 2093 of file klocale.cpp.

void KLocale::setDecimalSymbol | ( | const QString & | symbol | ) |

Changes the symbol used to identify the decimal pointer.

Parameters

  symbol | The new decimal symbol.

Definition at line 2141 of file klocale.cpp.

bool KLocale::setEncoding | ( | int | mibEnum | ) |

Changes the current encoding.

Parameters

  mibEnum | The mib of the preferred codec

Returns
  True on success.

Definition at line 2284 of file klocale.cpp.

void KLocale::setFracDigits | ( | int | digits | ) |

Changes the number of digits used when formating numbers.

Parameters

  digits | The default number of digits to use.

Definition at line 2190 of file klocale.cpp.

bool KLocale::setLanguage | ( | const QString & | language | ) |

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.

Parameters

  language | The language code.

Returns
  True on success.

Definition at line 405 of file klocale.cpp.

bool KLocale::setLanguage | ( | const QStringList & | languages | ) |

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.

Parameters

  languages | The list of language codes.

Returns
  True if one of the specified languages were used.

Definition at line 423 of file klocale.cpp.

void KLocale::setMainCatalogue | ( | const char * | catalog | ) |

static

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.

Parameters

  catalog | Catalogue to override all other main catalogues.

Definition at line 1397 of file klocale.cpp.

void KLocale::setMeasureSystem | ( | MeasureSystem | value | ) |

Changes the preferred measuring system.

Returns
  value The preferred measuring system

Definition at line 2234 of file klocale.cpp.

void KLocale::setMonetaryDecimalSymbol | ( | const QString & | symbol | ) |

Changes the symbol used to identify the decimal pointer for monetary values.

Parameters

  symbol | The new decimal symbol.

Definition at line 2203 of file klocale.cpp.

void KLocale::setMonetaryThousandsSeparator | ( | const QString & | separator | ) |

Changes the separator used to group digits when formating monetary values.

Parameters

  separator | The new thousands separator.

Definition at line 2196 of file klocale.cpp.

void KLocale::setNegativeMonetarySignPosition | ( | SignPosition | signpos | ) |

Changes the sign position used for negative monetary values.

Parameters

  signpos | The new sign position

Definition at line 2172 of file klocale.cpp.

void KLocale::setNegativePrefixCurrencySymbol | ( | bool | prefix | ) |

Changes the position where the currency symbol should be printed for negative monetary values.

Parameters

  prefix | True if the currency symbol should be prefixed instead of postfixed

Definition at line 2184 of file klocale.cpp.

void KLocale::setNegativeSign | ( | const QString & | sign | ) |

Changes the sign used to identify a negative number.

Parameters

  sign | Sign used for negative numbers.

Definition at line 2160 of file klocale.cpp.

void KLocale::setPageSize | ( | int | paperFormat | ) |

Changes the preferred page size when printing.

Parameters

  paperFormat | the new preferred page size in the format QPrinter::PageSize

Definition at line 2221 of file klocale.cpp.

void KLocale::setPositiveMonetarySignPosition | ( | SignPosition | signpos | ) |

Changes the sign position used for positive monetary values.

Parameters

  signpos | The new sign position

Definition at line 2166 of file klocale.cpp.

void KLocale::setPositivePrefixCurrencySymbol | ( | bool | prefix | ) |

Changes the position where the currency symbol should be printed for positive monetary values.

Parameters

  prefix | True if the currency symbol should be prefixed instead of postfixed

Definition at line 2178 of file klocale.cpp.

void KLocale::setPositiveSign | ( | const QString & | sign | ) |

Changes the sign used to identify a positive number.

Normally this is left blank.

Parameters

  sign | Sign used for positive numbers.

Definition at line 2154 of file klocale.cpp.

void KLocale::setThousandsSeparator | ( | const QString & | separator | ) |

Changes the separator used to group digits when formating numbers.

Parameters

  separator | The new thousands separator.

Definition at line 2147 of file klocale.cpp.

void KLocale::setTimeFormat | ( | const QString & | format | ) |

Changes the current time format.

The format of the time is string a which contains variables that will be replaced:

- H with the hour in 24h format and 2 digits (e.g. 5pm is "17", 5am is "05")
- k with the hour in 24h format and one digits (e.g. 5pm is "17", 5am is "5")
- I with the hour in 12h format and 2 digits (e.g. 5pm is "05", 5am is "05")
- l with the hour in 12h format and one digits (e.g. 5pm is "5", 5am is "5")
- M with the minute with 2 digits (e.g. the minute of 07:02:09 is "02")
- S with the seconds with 2 digits (e.g. the minute of 07:02:09 is "09")
- p with pm or am (e.g. 17.00 is "pm", 05.00 is "am")

Everything else in the format string will be taken as is. For example, 5.23pm with the format "%H:%M" results in "17:23".

Parameters

  format | The new time format

Definition at line 2099 of file klocale.cpp.

void KLocale::setWeekStartDay | ( | int | day | ) |

Changes how KLocale defines the first day in week.

Parameters

  day | first day of the week (Monday=1..Sunday=7) as integer

Since
  3.1

Definition at line 2114 of file klocale.cpp.

void KLocale::setWeekStartsMonday | ( | bool | start | ) |

Deprecated:

Please use setWeekStartDay instead.

Changes how KLocale defines the first day in week.

Parameters

  start | True if Monday is the first day in the week

Definition at line 2105 of file klocale.cpp.

void KLocale::splitLocale | ( | const QString & | str,
|  | QString & | language,
|  | QString & | country,
|  | QString & | charset
| ) |  |

static

Returns the parts of the parameter str understood as language setting the format is language_COUNTRY.charset.

Parameters

  str | The string to split.
  language | This will be set to the language part of the string.
  country | This will be set to the country part of the string.
  charset | This will be set to the charset part of the string.

Definition at line 505 of file klocale.cpp.

QString KLocale::thousandsSeparator | ( |  | ) | const

Returns what the thousands separator should look like ("," or "." etc.) according to the current locale or user settings.

Returns
  The thousands separator used by locale.

Definition at line 1021 of file klocale.cpp.

QString KLocale::timeFormat | ( |  | ) | const

Returns the currently selected time format.

Returns
  Current time format.

See also
  setTimeFormat()

Definition at line 2135 of file klocale.cpp.

QString KLocale::translate | ( | const char * | index | ) | const

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)

Parameters

  index | The lookup text and default text, if not found.

Definition at line 753 of file klocale.cpp.

QString KLocale::translate | ( | const char * | comment,
|  | const char * | fallback
| ) |  | const

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()

Parameters

  comment | the comment. The lookup text is made out of comment + `fallback`
  fallback | the default text, if not found

Returns
  translation

Definition at line 758 of file klocale.cpp.

QString KLocale::translate | ( | const char * | singular,
|  | const char * | plural,
|  | unsigned long | n
| ) |  | const

Used to get the correct, translated singular or plural of a word.

Parameters

  singular | the singular form of the word, for example "file".
  plural | the plural form of the word. Must contain a "%n" that will be replaced by the number `n`, for example "%n files"
  n | the number

Returns
  the correct singular or plural for the selected language, depending on n

Definition at line 794 of file klocale.cpp.

QString KLocale::translateQt | ( | const char * | context,
|  | const char * | sourceText,
|  | const char * | message
| ) |  | const

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)

Since
  3.1

Definition at line 947 of file klocale.cpp.

QString KLocale::twoAlphaToCountryName | ( | const QString & | code | ) | const

Convert a country code to a human readable form.

Parameters

  code | the country code

Returns
  the human readable form of the country name

Since
  3.1

Definition at line 2368 of file klocale.cpp.

QString KLocale::twoAlphaToLanguageName | ( | const QString & | code | ) | const

Convert a ISO 639-1 code to a human readable form.

Parameters

  code | the language ISO 639-1 code

Returns
  the human readable form

Since
  3.1

Definition at line 2341 of file klocale.cpp.

bool KLocale::use12Clock | ( |  | ) | const

Use this to determine if the user wants a 12 hour clock.

Returns
  If the user wants 12h clock

Definition at line 1933 of file klocale.cpp.

QString KLocale::weekDayName | ( | int | i,
|  | bool | shortName = `false`
| ) |  | const

Deprecated:
  use calendar()->weekDayName

Returns a string containing the name of the week day used in the Gregorian calendar.

Parameters

  i | the day number of the week starting at 1/Monday.
  shortName | we will return the short version of the string.

Returns
  The name of the day

Definition at line 624 of file klocale.cpp.

int KLocale::weekStartDay | ( |  | ) | const

Use this to determine which day is the first day of the week.

Returns
  an integer (Monday=1..Sunday=7)

Since
  3.1

Definition at line 1003 of file klocale.cpp.

bool KLocale::weekStartsMonday | ( |  | ) | const

Deprecated:

Please use the weekStartDay method instead.

Use this to determine if the user wants the week to start on Monday.

Returns
  true if the week starts on Monday

Definition at line 1009 of file klocale.cpp.

## Friends And Related Function Documentation

QString i18n | ( | const char * | text | ) |

related

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 1961 of file klocale.cpp.

QString i18n | ( | const char * | comment,
|  | const char * | text
| ) |  |

related

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.

See also
  translate

Definition at line 1969 of file klocale.cpp.

QString i18n | ( | const char * | singular,
|  | const char * | plural,
|  | unsigned long | n
| ) |  |

related

If you want to handle plural forms, use this form of i18n.

Parameters

  singular | the singular form of the word, for example "file".
  plural | the plural form of the word. Must contain a "%n" that will be replaced by the number `n`, for example "%n files"
  n | the number

Returns
  the correct singular or plural for the selected language, depending on n

See also
  translate

Definition at line 1977 of file klocale.cpp.

#define I18N_NOOP | ( |  | x | ) | x

related

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

Definition at line 52 of file klocale.h.

#define I18N_NOOP2 | ( |  | comment,
|  |  | x
| ) |  | x

related

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.

Warning
  You need to call i18n( comment, stringVar ) later on, not just i18n( stringVar ).

Since
  3.3

Definition at line 63 of file klocale.h.

QString tr2i18n | ( | const char * | message,
|  | const char * | = `0`
| ) |  |

related

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

Definition at line 108 of file klocale.h.

The documentation for this class was generated from the following files:

- klocale.h
- klocale.cpp

KDE Home | KDE Accessibility Home | Description of Access Keys