i18n

Since: BlackBerry 10.0.0

To link against this class, add the following line to your .pro file: LIBS += -lbbutilityi18n

This namespace offers functions for formatting text into dates, time, and percentages.

These functions open up International Components for Unicode (ICU) Internationalization (i18n) APIs in a manner that can be conveniently used with Qt.


Overview

Classes

ClockFormat

A wrapper for a list of supported date/time formats.

CustomDateFormatter

Formats QDateTime objects using skeleton patterns.

DateFormat

A wrapper for a list of supported date/time formats.

RelativeDateFormat

A list of supported relative date/time formatters.

RelativeDateFormatter

Formats QDateTime objects relative to current date/time.

Functions Index

QStringdateFormat (DateFormat::Type format=DateFormat::Short)
QStringdateFormat (const QLocale &locale, DateFormat::Type format=DateFormat::Short)
QStringdateTimeFormat (DateFormat::Type format=DateFormat::Short)
QStringdateTimeFormat (const QLocale &locale, DateFormat::Type format=DateFormat::Short)
QStringtimeFormat (DateFormat::Type format=DateFormat::Short)
QStringtimeFormat (const QLocale &locale, DateFormat::Type format=DateFormat::Short)
QStringtoPercentageString (double number, int maxFractionDigits=6, int minFractionDigits=0)
QStringtoPercentageString (const QLocale &locale, double number, int maxFractionDigits=6, int minFractionDigits=0)

Functions

QString dateFormat (

Provides a QDate formatting pattern based on a DateFormat::Type and the current LocaleType::Region QLocale.

Note:

You should always make sure to format the text using the region locale. See the documentation for bb::system::LocaleHandler for more details.

Parameters
format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized date format pattern string.

Since:

BlackBerry 10.0.0

QString dateFormat (

Provides QDate formatting pattern given a QLocale and a DateFormat::Type.

This overloaded function is identical to dateFormat(DateFormat::Type) except that it allows for specifying a custom QLocale instead of the user's region locale.

Parameters
locale

The QLocale used for generating the date pattern.

format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized date format pattern string.

Since:

BlackBerry 10.0.0

QString dateTimeFormat (

This function provides a QDateTime formatting pattern based on a DateFormat::Type and the current bb::system::LocaleType::Region QLocale.

If supplied with DateFormat::Medium, and the user has selected US English as the region locale, "MMM d,yyyy h:mm:ss" is returned. This function accounts for the user's choice of the 12/24 hour clock.

The returned QString can be passed in as the second parameter of QLocale::toString(const QDateTime &, const QString &) const thus allowing you to display any QDateTime object in a localized standard ICU format.

Note:

You should always make sure to format the text using the region locale. See the documentation for bb::system::LocaleHandler for more details.

Parameters
format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized date-time format pattern string.

Since:

BlackBerry 10.0.0

QString dateTimeFormat (

This function provides a QDateTime formatting pattern given a QLocale and DateFormat::Type.

This overloaded function is identical to dateTimeFormat(DateFormat::Type) except that it allows for specifying a custom QLocale instead of the user's region locale.

Parameters
locale

The QLocale used for generating the date-time pattern.

format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized date-time format pattern string.

Since:

BlackBerry 10.0.0

QString timeFormat (

Provides a QTime formatting pattern based on a DateFormat::Type and the current bb::system::LocaleType::Region QLocale.

If supplied with DateFormat::Medium, and the user has selected US English as the region locale, "h:mm:ss" is returned. This function accounts for the user's choice of the 12/24 hour clock.

The returned QString can be passed in as the second parameter of QLocale::toString(const QTime &, const QString &) const thus allowing you to display any QTime object in a localized standard ICU format.

Note:

You should always make sure to format the text using the region locale. See the documentation for bb::system::LocaleHandler for more details.

Parameters
format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized time format pattern string.

Since:

BlackBerry 10.0.0

QString timeFormat (

This function provides a QTime formatting pattern given a QLocale and DateFormat::Type.

This overloaded function is identical to timeFormat(DateFormat::Type) except that it allows for specifying a custom QLocale instead of the user's region locale.

Parameters
locale

The QLocale used for generating the time pattern.

format

A DateFormat::Type to specify the length and complexity of the generated format.

Return:

A localized time format pattern string.

Since:

BlackBerry 10.0.0

QString toPercentageString (
  • doublenumber,
  • intmaxFractionDigits,
  • intminFractionDigits )

This function formats a number as a percentage according to the current bb::system::LocaleType::Region QLocale.

Some example use cases:
  • toPercentageString(0.4500005) returns "45%" if the region locale is US English.

  • toPercentageString(0.4499995) returns "% 45" if the region locale is Turkish.

See also:

bb::system::LocaleHandler for more details on the region locale.

Parameters
number

The number to be represented as a percentage.

maxFractionDigits

The maximum number of digits allowed in the fraction portion of the percentage.

minFractionDigits

The minimum number of digits allowed in the fraction portion of the percentage.

Return:

Returns a localized percentage string.

Since:

BlackBerry 10.0.0

QString toPercentageString (
  • const QLocale &locale,
  • doublenumber,
  • intmaxFractionDigits,
  • intminFractionDigits )

This function formats a number as a percentage localized to any QLocale.

This overloaded function is identical to toPercentageString(double, int, int) except that it allows specifying a custom QLocale instead of the user's region locale.

Parameters
locale

The QLocale used for generating the date-time pattern.

number

The number to be represented as a percentage.

maxFractionDigits

The maximum number of digits allowed in the fraction portion of the percentage.

minFractionDigits

The minimum number of digits allowed in the fraction portion of the percentage.

Return:

Returns a localized percentage string.

Since:

BlackBerry 10.0.0

Last modified: 2014-06-24



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus