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 Static Methods


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, KConfig *config = 0 )

KLocale

Constructs a KLocale with the given catalogue 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 fie. If we were not able to use non 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:
catalogueThe name of the main language file
configThe configuration file to use.

 KLocale ( const KLocale & rhs )

KLocale

Copy constructor.

KLocale&  operator= ( const KLocale & rhs )

operator=

Assignment operator.

 ~KLocale ()

~KLocale

Destructor.

QString  translate ( const char *index )

translate

[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 catalogue 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:
indexThe lookup text and default text, if not found.

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

translate

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

Returns: translation

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

translate

[const]

bool  setCharset (const QString & charset)

setCharset

Parameters:
charsetThe new charset

Returns: True on success.

bool  setEncoding (int mibEnum)

setEncoding

Changes the current encoding.

Parameters:
mibEnumThe mib of the preferred codec

Returns: True on success.

bool  setLanguage (const QString & language)

setLanguage

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:
languageThe language code.

Returns: True on success.

bool  setLanguage (const QStringList & languages)

setLanguage

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:
languagesThe list of language codes.

Returns: True if one of the specified languages were used.

bool  setCountry (const QString & country)

setCountry

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

Parameters:
countryThe ISO 3166 country code.

Returns: True on success.

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]

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.

QString  thousandsSeparator ()

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.

QString  currencySymbol ()

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.

QString  monetaryDecimalSymbol ()

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.

QString  monetaryThousandsSeparator ()

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.

QString  positiveSign ()

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.

QString  negativeSign ()

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.

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 currency symbol for negative numbers.

SignPosition  positiveMonetarySignPosition ()

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

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 a double, converts 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]

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, converts 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 fractional digits used.

Returns: The number as a localized string

QString  formatNumber (const QString &numStr)

formatNumber

[const]

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 shortFormat = false)

formatDate

[const]

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

Parameters:
pDateThe date to be formated.
shotFormatTrue for non text dates.

Returns: The date as a string

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

formatTime

[const]

Returns 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 shortName = false)

monthName

[const]

Returns a string containing the name of the month name.

Parameters:
ithe month number of the year starting at 1/January.
shortNamewe will return the short version of the string.

Returns: The name of the month

QString  weekDayName (int i, bool shortName = false)

weekDayName

[const]

Returns a string containing the name of the week day.

Parameters:
ithe day number of the week starting at 1/Monday.
shortNamewe will return the short version of the string.

Returns: The name of the week

QString  formatDateTime (const QDateTime &pDateTime, bool shortFormat = true, bool includeSecs = false)

formatDateTime

[const]

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

Parameters:
pDateTimeThe date and time to be formated.
shortFormatusing 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, bool* ok = 0)

readDate

[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:
strthe string we want to convert.
okthe boolean that is set to false if it's not a valid date.

Returns: The string converted to a QDate

QDate  readDate ( const QString &intstr, const QString &fmt, bool* ok = 0)

readDate

[const]

Converts a localized date string to a QDate, using the specified format. You will usually not want to use this method.

QTime  readTime (const QString &str, bool* ok = 0)

readTime

[const]

Converts a localized time string to a QTime. The bool pointed by ok will be false if the time entered was not valid.

Parameters:
strthe string we want to convert.
okthe boolean that is set to false if it's not a valid time.

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. "en_US" 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: String containing language codes separated by colons

QStringList  languagesTwoAlpha ()

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, no, nb, pt".

Returns: List of language codes

See also: languageList

QStringList  languageList ()

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

QString  charset ()

charset

[const]

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 preferred charset for fonts

See also: encoding

const char *  encoding ()

encoding

[const]

Returns the user's preferred encoding.

Returns: The name of the preferred encoding

See also: codecForEncoding, encodingMib

int  encodingMib ()

encodingMib

[const]

Returns the user's preferred encoding.

Returns: The Mib of the preferred encoding

See also: encoding, codecForEncoding

QTextCodec *  codecForEncoding ()

codecForEncoding

[const]

Returns the user's preferred encoding. Should never be NULL.

Returns: The codec for the preferred encoding

See also: encoding, encodingMib

void  setDateFormat (const QString & format)

setDateFormat

Changes the current date format.

Parameters:
formatThe new date format

void  setDateFormatShort (const QString & format)

setDateFormatShort

Changes the current short date format.

Parameters:
formatThe new short date format

void  setTimeFormat (const QString & format)

setTimeFormat

Changes the current time format.

Parameters:
formatThe new time format

void  setWeekStartsMonday (bool start)

setWeekStartsMonday

Changes how KLocale defines the first day in week.

Parameters:
startTrue if Monday is the first day in the week

QString  dateFormat ()

dateFormat

[const]

Returns the currently selected date format.

Returns: Current date format.

QString  dateFormatShort ()

dateFormatShort

[const]

Returns the currently selected short date format.

Returns: Current short date format.

QString  timeFormat ()

timeFormat

[const]

Returns the currently selected time format.

Returns: Current time format.

void  setDecimalSymbol (const QString & symbol)

setDecimalSymbol

Changes the symbol used to identify the decimal pointer.

Parameters:
symbolThe new decimal symbol.

void  setThousandsSeparator (const QString & separator)

setThousandsSeparator

Changes the separator used to group digits when formating numbers.

Parameters:
separatorThe new thousands separator.

void  setPositiveSign (const QString & sign)

setPositiveSign

Changes the sign used to identify a positive number. Normally this is left blank.

Parameters:
signSign used for positive numbers.

void  setNegativeSign (const QString & sign)

setNegativeSign

Changes the sign used to identify a negative number.

Parameters:
signSign used for negative numbers.

void  setPositiveMonetarySignPosition (SignPosition signpos)

setPositiveMonetarySignPosition

Changes the sign position used for positive monetary values.

Parameters:
signposThe new sign position

void  setNegativeMonetarySignPosition (SignPosition signpos)

setNegativeMonetarySignPosition

Changes the sign position used for negative monetary values.

Parameters:
signposThe new sign position

void  setPositivePrefixCurrencySymbol (bool prefix)

setPositivePrefixCurrencySymbol

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

Parameters:
prefixTrue if the currency symbol should be prefixed instead of postfixed

void  setNegativePrefixCurrencySymbol (bool prefix)

setNegativePrefixCurrencySymbol

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

Parameters:
prefixTrue if the currency symbol should be prefixed instead of postfixed

void  setFracDigits (int digits)

setFracDigits

Changes the number of digits used when formating numbers.

Parameters:
digitsThe default number of digits to use.

void  setMonetaryThousandsSeparator (const QString & separator)

setMonetaryThousandsSeparator

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

Parameters:
separatorThe new thousands separator.

void  setMonetaryDecimalSymbol (const QString & symbol)

setMonetaryDecimalSymbol

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

Parameters:
symbolThe new decimal symbol.

void  setCurrencySymbol (const QString & symbol)

setCurrencySymbol

Changes the current currency symbol.

Parameters:
symbolThe new currency symbol

int  pageSize ()

pageSize

[const]

Returns the preferred page size for printing.

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

void  setPageSize (int paperFormat)

setPageSize

Changes the preferred page size when printing.

Parameters:
Thenew preferred page size in the format QPrinter::PageSize

enum MeasureSystem { Metric, Imperial }

MeasureSystem

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

MeasureSystem  measureSystem ()

measureSystem

[const]

Returns which measuring system we use.

Returns: The preferred measuring system

void  setMeasureSystem (MeasureSystem value)

setMeasureSystem

Changes the preferred measuring system.

Returns: value The preferred measuring system

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 en_US will be used.

Parameters:
catalogueThe catalogue to add.

void  removeCatalogue (const QString &catalogue)

removeCatalogue

void  setActiveCatalogue (const QString &catalogue)

setActiveCatalogue

QString  translateQt (const char *context, const char *sourceText, const char *message)

translateQt

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

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

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]

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

Parameters:
fnamerelative path to find
rtyperesource type to use

QString  defaultLanguage ()

defaultLanguage

[static]

Returns the name of the internal language.

Returns: Name of the default language

QString  defaultCountry ()

defaultCountry

[static]

Returns the name of the default country.

Returns: Name of the default country

QString  _initLanguage (KConfigBase *config)

_initLanguage

[static]

void  initInstance ()

initInstance

[protected static]

pointer.