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

Public Methods

Public Static Methods

Protected Methods

Protected Members


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:
catalogueThe 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:
indexThe 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:
indexThe lookup text
fallbackthe default text, if not found

Returns: translation

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

translate

[const]

void  setLanguage (const QString &_lang)

setLanguage

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

Parameters:
_langThe 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 ¤cy = QString::null, int digits = -1)

formatMoney

[const]

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

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

Parameters:
numThe number we want to format
currencyThe currency symbol you want.
digitsNumber 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:
numStrThe string you want to reformat.

Returns: The number of money as a localized string

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

formatNumber

[const]

Given a 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:
numThe number to convert
precisionNumber 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:
numStrThe 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:
pDateThe date to be formated.
shotfmtTrue 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:
pTimeThe time to be formated.
includeSecsif 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:
ithe month number of the year starting at 1/January.
_shortwe 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:
ithe day number of the week starting at 1/Monday.
_shortwe 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:
pDateTimeThe 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:
pDateTimeThe date and time to be formated.
shortfmtusing the short date format.
includeSecondsusing 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:
numStrthe string we want to convert.
okthe 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:
numStrthe string we want to convert.
okthe 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:
strthe 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:
strthe 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 another catalogue to search for translation lookup. This function is useful for extern libraries and/or code, that provides its own messages.

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

Parameters:
catalogueThe 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:
strThe string to split.
languageThis will be set to the language part of the string.
countryThis will be set to the country part of the string.
charsetThis 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:
configThe 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:
configThe configuration object used for init.
catalogueThe 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:
catalogueCatalogue to override all other main catalogues.

QString  langLookup (const QString &fname, const char *rtype = "html")

langLookup

[static]

Find localized resource in resourceDir( rtype ) + + fname.

Parameters:
fnamerelative path to find
rtyperesource type to use

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]