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

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:fr:.., if de (german) is your prefered language and fr (french) is your second prefered language. You can add as many languages as you want. If none of them can be find, the default (C) will be used.

Parameters:
catalogueThe name of the language file

KLocale ()

Destructor.

QString  translate ( const char *index )

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

void  setLanguage (const QString &_lang)

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 }

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

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

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

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

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

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

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

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

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

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

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

[const]

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

Returns: Where/how to print the positive sign.

SignPosition  negativeMonetarySignPosition ()

[const]

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

Returns: Where/how to print the negative sign.

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

[const]

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

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

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)

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

[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, fracDigits is used.

Parameters:
numThe number to convert
precisionNumber of fractinal digits used.

Returns: The number as a localized string

QString  formatNumber (const QString &numStr)

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

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

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

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

Returns: If the user wants 12h lock

QString  MonthName (int i)

[const]

Return a string containing the name of the month name.

Parameters:
ithe month number of the year starting at 1/January.

Returns: The name of the month

QString  WeekDayName (int i)

[const]

Return a string containing the name of the week day.

Parameters:
ithe day number of the week starting at 1/Monday.

Returns: The name of the week

QString  formatDateTime (const QDateTime &pDateTime)

[const]

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

Parameters:
pDateTimeThe date and time to be formated.

Returns: The date and time as a string

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

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

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

[const]

Converts a localized date string to a QDate. 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

void  aliasLocale ( const char *text, long int index)

Creates an alias for the string text. It will be translated and stored under the integer constant index. This can help you to avoid repeated translation. Be aware, that this is only needed in cases, where you want to translate it in loops or something like that. In every other case, the translate methods is fast enough.

Parameters:
textThe text to alias.
indexThe index key to use.

QString  getAlias ( long key )

[const]

Returns an alias, that you have set before or 0, if not set. This method uses QIntDict.

Parameters:
Thekey of the string to look up.

Returns: The translated string.

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

[const]

Returns the locale used for money by object.

Returns: The currency use locale for money formating.

QString  number ()

[const]

Returns the locale used for numbers by object.

Returns: The currently used locale for numer formating.

QString  time ()

[const]

Returns the locale used for time by object.

Returns: The currently used locale for time formated.

QString  languages ()

[const]

Returns the languages selected by user.

Returns: String containing locale codes separated by colons

QStringList  languageList ()

[const]

Returns the languages selected by user.

Returns: List of language codes

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

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:
catalogueThe catalogue to add.

void  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:
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)

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

Parameters:
configThe configuration object used for init.

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

Init the l18n 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 ()

[const]

Returns: Returns true if locale is inited.

void  setMainCatalogue (const char *catalogue)

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