# class KLocale | class for supporting locale settings and national language. More...
Definition | `#include <klocale.h>`
List of all Methods
Annotated List
Files
Globals
Hierarchy
Index

#### Public Types

- enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, AfterQuantityMoney = 2, BeforeMoney = 3, AfterMoney = 4 }

#### Public Methods

- KLocale ( const QString& catalogue = QString::null )
- ~KLocale ()
- QString translate ( const char *index ) const
- QString translate ( const char *index, const char *fallback) const
- void setLanguage (const QString &_lang)
- 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 formatMoney (const QString &numStr) const
- QString formatNumber (double num, int precision = -1) const
- QString formatNumber (const QString &numStr) const
- QString formatDate (const QDate &pDate, bool shortfmt = false) const
- QString formatTime (const QTime &pTime, bool includeSecs = false) const
- bool use12Clock () const
- bool weekStartsMonday () const
- QString monthName (int i, bool _short = false) const
- QString weekDayName (int i, bool _short = false) const
- QString formatDateTime (const QDateTime &pDateTime) const
- QString formatDateTime (const QDateTime &pDateTime, bool shortfmt, 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) const
- QTime readTime (const QString &str) const
- QString language () const
- QString country () const
- QString languages () const
- QStringList languageList () const
- QString charset () const
- void insertCatalogue (const QString& catalogue)
- QString translateQt (const char *context, const char *sourceText) const
- void initFormat (KConfig *config)
- void initLanguage (KConfig *config, const QString& catalogue)
- bool inited () const

#### Public Static Methods

- static void splitLocale (const QString& str,QString& language, QString& country, QString &charset)
- static void setMainCatalogue (const char *catalogue)

#### Protected Methods

- QTime readTime (const QString &str, bool seconds) const
- QDate readDate (const QString &str, bool shortfmt) const
- void setEncodingLang (const QString &_lang)
- KLocale ( const KLocale& )
- KLocale& operator= ( const KLocale& )

#### Protected Members

- QString chset
- bool m_weekStartsMonday
- QString _decimalSymbol
- QString _thousandsSeparator
- QString _currencySymbol
- QString _monetaryDecimalSymbol
- QString _monetaryThousandsSeparator
- QString _positiveSign
- QString _negativeSign
- int _fracDigits
- bool _positivePrefixCurrencySymbol
- bool _negativePrefixCurrencySymbol
- SignPosition _positiveMonetarySignPosition
- SignPosition _negativeMonetarySignPosition
- QString _timefmt
- QString _datefmt
- QString _datefmtshort
- QStrList *catalogues
- bool _inited
- QCString lang
- QTextCodec *_codec
- QString langs
- QString _country

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

KLocale ( const QString& catalogue = QString::null ) | ### KLocale

Create a KLocale with the given catalogue name. If no catalogue is given, the application name is used. The constructor looks for an entry Locale/Language in the configuration file. If nothing is set there, it looks for the environment variable $LANG. The format for LANG is de, if de (german) is your prefered language. If none of them can be find, the default (C) will be used.

Parameters:

catalogue | The name of the language file

~KLocale () | ### ~KLocale

Destructor.

QString translate ( const char *index ) | ### translate

[const]

Translate 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 catalogue given to the constructor, it will search in the system catalog. This makes it possible to override some phrases for your needs.

Parameters:

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

QString translate ( const char *index, const char *fallback) | ### translate

[const]

Translate 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 ambigious 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:

index | The lookup text
fallback | the default text, if not found

Returns: translation

void setLanguage (const QString &_lang) | ### setLanguage

Allows programs such as kcmlocale to choose which translation to use.

Parameters:

_lang | The language you want to use.

enum SignPosition { ParensAround = 0, BeforeQuantityMoney = 1, AfterQuantityMoney = 2, BeforeMoney = 3, AfterMoney = 4 } | ### SignPosition

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

QString decimalSymbol () | ### decimalSymbol

[const]

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

Returns: The decimal symbol used by locale.

QString thousandsSeparator () | ### thousandsSeparator

[const]

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

Returns: The thousands separator used by locale.

QString currencySymbol () | ### currencySymbol

[const]

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

Returns: The default currecy symbol used by locale.

QString monetaryDecimalSymbol () | ### monetaryDecimalSymbol

[const]

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

QString monetaryThousandsSeparator () | ### monetaryThousandsSeparator

[const]

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

QString positiveSign () | ### positiveSign

[const]

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

Returns: The positive sign used by locale.

QString negativeSign () | ### negativeSign

[const]

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

Returns: The negative sign used by locale.

int fracDigits () | ### fracDigits

[const]

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

Returns: Default number of fractional digits used by locale.

bool positivePrefixCurrencySymbol () | ### 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.

bool negativePrefixCurrencySymbol () | ### negativePrefixCurrencySymbol

[const]

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

Returns: Where to print the currecy symbol for negative numbers.

SignPosition positiveMonetarySignPosition () | ### positiveMonetarySignPosition

[const]

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

Returns: Where/how to print the positive sign.

See also: SignPosition

SignPosition negativeMonetarySignPosition () | ### 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

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

[const]

Given an double, convert 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.

Returns: The number of money as a localized string

QString formatMoney (const QString &numStr) | ### formatMoney

[const]

This function differs from the above only in that it can take a QString as the argument for convenience.

Parameters:

numStr | The string you want to reformat.

Returns: The number of money as a localized string

QString formatNumber (double num, int precision = -1) | ### formatNumber

[const]

Given an double, convert that to a numeric string containing the localized numeric equivalent.

e.g. given 123456.78, return "123,456.78" (for some European country). If precision isn't specified, 2 is used.

Parameters:

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

Returns: The number as a localized string

QString formatNumber (const QString &numStr) | ### formatNumber

[const]

This function differs from the above only in that it can take a QString as the argument for convenience.

Parameters:

numStr | The string you want to convert.

Returns: The number as a formated string

QString formatDate (const QDate &pDate, bool shortfmt = false) | ### formatDate

[const]

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

Parameters:

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

Returns: The date as a string

QString formatTime (const QTime &pTime, bool includeSecs = false) | ### formatTime

[const]

Return 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

bool use12Clock () | ### use12Clock

[const]

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

Returns: If the user wants 12h clock

bool weekStartsMonday () | ### weekStartsMonday

[const]

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

Returns: true if the week starts on monday

QString monthName (int i, bool _short = false) | ### monthName

[const]

Return a string containing the name of the month name.

Parameters:

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

Returns: The name of the month

QString weekDayName (int i, bool _short = false) | ### weekDayName

[const]

Return a string containing the name of the week day.

Parameters:

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

Returns: The name of the week

QString formatDateTime (const QDateTime &pDateTime) | ### formatDateTime

[const]

Return a string formated to the current locale's conventions regarding both date and time. Defaults to short date format.

Parameters:

pDateTime | The date and time to be formated.

Returns: The date and time as a string

QString formatDateTime (const QDateTime &pDateTime, bool shortfmt, bool includeSecs = false) | ### formatDateTime

[const]

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

Parameters:

pDateTime | The date and time to be formated.
shortfmt | using the short date format.
includeSeconds | using the short date format.

Returns: The date and time as a string

double readMoney (const QString &numStr, bool * ok=0) | ### readMoney

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

Returns: The string converted to a double

double readNumber (const QString &numStr, bool * ok=0) | ### readNumber

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

Returns: The string converted to a double

QDate readDate (const QString &str) | ### readDate

[const]

Converts a localized date string to a QDate. isValid() on the returning object will be false if the date entered was not valid.

Note: This only works on short dates for the time beeing.

Parameters:

str | the string we want to convert.

Returns: The string converted to a QDate

QTime readTime (const QString &str) | ### readTime

[const]

Converts a localized time string to a QTime. isValid() on the returning object will be false if the time entered was not valid.

Parameters:

str | the string we want to convert.

Returns: The string converted to a QTime

QString language () | ### language

[const]

Returns the language used by this object. The domain AND the library translation must be available in this language. 'C' is default, if no other available.

Returns: The currently used language.

QString country () | ### country

[const]

Returns the country code of the country where the user lives. 'C' is default, if no other available

Returns: The country code for the user.

QString languages () | ### languages

[const]

Returns the languages selected by user.

Returns: String containing language codes separated by colons

QStringList languageList () | ### languageList

[const]

Returns the languages selected by user.

Returns: List of language codes

QString charset () | ### charset

[const]

Returns the charset name by selected locale. This will be the charset defined in the config file. NOTE: This is no longer the same as encoding. "iso-8859-1" is default

Returns: Name of the prefered charset for fonts

void insertCatalogue (const QString& catalogue) | ### insertCatalogue

adds anther catalogue to search for translation lookup. This function is useful for extern libraries and/or code, that provides it's own messages.

If the catalogue does not exist for the chosen language, it will be ignored and C will be used.

Parameters:

catalogue | The catalogue to add.

QString translateQt (const char *context, const char *sourceText) | ### translateQt

[const]

translates a message as a QTranslator is supposed to. The parameters are similiar to i18n(), but the result value has other semantics (it can be QString::null)

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

[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 stirng.

void initFormat (KConfig *config) | ### initFormat

Init the localization part of the instance with the config object.

Parameters:

config | The configuration object used for init.

void initLanguage (KConfig *config, const QString& catalogue) | ### initLanguage

Init the language part of the instance with the given config object. It should be valid and contain the global entries.

Parameters:

config | The configuration object used for init.
catalogue | The main catalogue to use.

bool inited () | ### inited

[const]

Returns: Returns true if locale is inited.

void setMainCatalogue (const char *catalogue) | ### setMainCatalogue

[static]

Use this to as main catalogue for *all* KLocales, if not the appname will be used.

Parameters:

catalogue | Catalogue to override all other main catalogues.

QString chset | ### chset

[protected]

bool m_weekStartsMonday | ### m_weekStartsMonday

[protected]

QString _decimalSymbol | ### _decimalSymbol

[protected]

QString _thousandsSeparator | ### _thousandsSeparator

[protected]

QString _currencySymbol | ### _currencySymbol

[protected]

QString _monetaryDecimalSymbol | ### _monetaryDecimalSymbol

[protected]

QString _monetaryThousandsSeparator | ### _monetaryThousandsSeparator

[protected]

QString _positiveSign | ### _positiveSign

[protected]

QString _negativeSign | ### _negativeSign

[protected]

int _fracDigits | ### _fracDigits

[protected]

bool _positivePrefixCurrencySymbol | ### _positivePrefixCurrencySymbol

[protected]

bool _negativePrefixCurrencySymbol | ### _negativePrefixCurrencySymbol

[protected]

SignPosition _positiveMonetarySignPosition | ### _positiveMonetarySignPosition

[protected]

SignPosition _negativeMonetarySignPosition | ### _negativeMonetarySignPosition

[protected]

QString _timefmt | ### _timefmt

[protected]

QString _datefmt | ### _datefmt

[protected]

QString _datefmtshort | ### _datefmtshort

[protected]

QStrList * catalogues | ### catalogues

[protected]

bool _inited | ### _inited

[protected]

QCString lang | ### lang

[protected]

QTextCodec * _codec | ### _codec

[protected]

QString langs | ### langs

[protected]

QString _country | ### _country

[protected]

QTime readTime (const QString &str, bool seconds) | ### readTime

[protected const]

QDate readDate (const QString &str, bool shortfmt) | ### readDate

[protected const]

void setEncodingLang (const QString &_lang) | ### setEncodingLang

[protected]

KLocale ( const KLocale& ) | ### KLocale

[protected]

KLocale& operator= ( const KLocale& ) | ### operator=

[protected]

- Author: Stephan Kulow <coolo@kde.org>, Preston Brown <pbrown@kde.org>, Hans Petter Bieker <bieker@kde.org>
- Generated: root@sparc.ports.openbsd.org on Wed May 2 09:34:58 2001, using kdoc 2.0a53.