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 )

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:

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:

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

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

Returns: translation

void  setLanguage (const QString &_lang)

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

Parameters:

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

Parameters:

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:

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

Parameters:

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:

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:

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:

Returns: The time as a string

bool  use12Clock ()

[const]

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

Returns: If the user wants 12h clock

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

[const]

Return a string containing the name of the month name.

Parameters:

Returns: The name of the month

QString  weekDayName (int i, bool _short = false)

[const]

Return a string containing the name of the week day.

Parameters:

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. Defaults to short date format.

Parameters:

Returns: The date and time as a string

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

[const]

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

Parameters:

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:

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:

Returns: The string converted to a double

QDate  readDate (const QString &str)

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

Returns: The string converted to a QDate

QTime  readTime (const QString &str)

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

Returns: The string converted to a QTime

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

[const]

Returns the languages selected by user.

Returns: String containing language 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:

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

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

[static]

returns the parts of the parameter str understood as language setting the format is language_country.charset

Parameters:

void  initFormat (KConfig *config)

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

Parameters:

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

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

Parameters:

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:

QString chset

[protected]

bool m_weekStartsMonday

[protected]

QString _decimalSymbol

[protected]

QString _thousandsSeparator

[protected]

QString _currencySymbol

[protected]

QString _monetaryDecimalSymbol

[protected]

QString _monetaryThousandsSeparator

[protected]

QString _positiveSign

[protected]

QString _negativeSign

[protected]

int _fracDigits

[protected]

bool _positivePrefixCurrencySymbol

[protected]

bool _negativePrefixCurrencySymbol

[protected]

SignPosition _positiveMonetarySignPosition

[protected]

SignPosition _negativeMonetarySignPosition

[protected]

QString _timefmt

[protected]

QString _datefmt

[protected]

QString _datefmtshort

[protected]

QStrList * catalogues

[protected]

bool _inited

[protected]

QCString lang

[protected]

QTextCodec * _codec

[protected]

QString langs

[protected]

QString _country

[protected]

QTime  readTime (const QString &str, bool seconds)

[protected const]

QDate  readDate (const QString &str, bool shortfmt)

[protected const]

void  setEncodingLang (const QString &_lang)

[protected]

 KLocale ( const KLocale& )

[protected]

KLocale&  operator= ( const KLocale& )

[protected]