|
|
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:
catalogue | The name of the language file |
~KLocale () |
Destructor.
QString translate ( const char *index ) |
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. |
void setLanguage (const QString &_lang) |
Allows programs such as kcmlocale to choose which translation to use.
void setCountry (const QString &country) |
Allows programs such as kcmlocale to choose how to format numbers etc.
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 () |
Retrieve what a decimal point should look like ("." or "," etc.) according to the current locale or user settings.
QString thousandsSeparator () |
Retrieve what the thousands separator should look like ("," or "." etc.) according to the current locale or user settings.
QString currencySymbol () |
Retrieve what the symbol denoting currency in the current locale as as defined by user settings should look like.
QString monetaryDecimalSymbol () |
Retrieve what a decimal point should look like ("." or "," etc.) for monetary values, according to the current locale or user settings.
QString monetaryThousandsSeparator () |
Retrieve what a thousands separator for monetary values should look like ("," or " " etc.) according to the current locale or user settings.
QString positiveSign () |
Retrieve what a positive sign should look like ("+", " ", etc.) according to the current locale or user settings.
QString negativeSign () |
Retrieve what a negative sign should look like ("-", etc.) according to the current locale or user settings.
int fracDigits () |
The number of fractional digits to include in numeric/monetary values (usually 2).
bool positivePrefixCurrencySymbol () |
If and only if the currency symbol precedes a positive value, this will be true.
bool negativePrefixCurrencySymbol () |
If and only if the currency symbol precedes a negative value, this will be true.
SignPosition positiveMonetarySignPosition () |
Retrieve the position of a positive sign in relation to a monetary value.
SignPosition negativeMonetarySignPosition () |
Denotes where to place a negative sign in relation to a monetary value.
QString formatMoney (double num, const QString ¤cy = QString::null, int digits = -1) |
Given an double, convert that to a numeric string containing the localized monetary equivalent.
e.g. given 123456, return "$123,456".
Returns: The number of money as a localized string
QString formatMoney (const QString &numStr) |
This function differs from the above only in that it can take a QString as the argument for convenience.
Returns: The number of money as a localized string
QString formatNumber (double num, int precision = -1) |
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.
Returns: The number as a localized string
QString formatNumber (const QString &numStr) |
This function differs from the above only in that it can take a QString as the argument for convenience.
Returns: The number as a formated string
QString formatDate (const QDate &pDate, bool shortfmt = false) |
Return a string formatted to the current locale's conventions regarding dates.
Returns: The date as a string
QString formatTime (const QTime &pTime, bool includeSecs = false) |
Return a string formatted to the current locale's conventions regarding times.
Parameters:
includeSecs | if 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) |
Return a string containing the name of the month name.
Returns: The name of the month
QString WeekDayName (int i) |
Return a string containing the name of the week day.
Returns: The name of the week
QString formatDateTime (const QDateTime &pDateTime) |
Return a string formated to the current locale's conventions regarding both date and time.
Returns: The date and time as a string
double readMoney (const QString &numStr, bool * ok=0) |
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) |
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) |
Converts a localized date string to a QDate. 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
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.
QString getAlias ( long key ) |
Returns an alias, that you have set before or 0, if not set. This method uses QIntDict.
QString language () |
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.
QString languages () |
Returns the languages selected by user.
Returns: String containing locale codes separated by colons
QStringList languageList () |
Returns the languages selected by user.
Returns: List of language codes
QString charset () |
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. "unicode" 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.
void splitLocale (const QString& str,QString& language, QString& country, QString &charset) |
returns the parts of the parameter str understood as language setting the format is language_country.charset
void initFormat (KConfig *config) |
Init the l10n part of the instance with the config object.
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.
bool inited () |
Returns: True if the KLocale instance is initialized already. You can't translate before it is. The constructor will initialize the instance, but under some circumstances - when the circumstances do not fit for initialization - it will just delay the initialization til you call initLanguage
void setMainCatalogue (const char *catalogue) |
Use this to as main catalogue for *all* KLocales, if not the appname will be used.