Wt  4.10.4
Public Member Functions | Static Public Member Functions | List of all members
Wt::WLocale Class Reference

A locale. More...

#include <Wt/WLocale.h>

Public Member Functions

 WLocale ()
 Default constructor. More...
 
 WLocale (const Wt::WLocale &locale)
 Copy constructor.
 
 WLocale (const std::string &locale)
 Creates a locale by name. More...
 
 WLocale (const char *locale)
 Creates a locale by name. More...
 
WLocaleoperator= (const WLocale &locale)
 Assignment operator.
 
void setDecimalPoint (std::string c)
 Sets the decimal point. More...
 
std::string decimalPoint () const
 Returns the decimal point. More...
 
void setGroupSeparator (std::string c)
 Sets the decimal group separator. More...
 
std::string groupSeparator () const
 Returns the decimal group separator. More...
 
void setTimeZone (const cpp20::date::time_zone *zone)
 Sets the time zone. More...
 
const cpp20::date::time_zone * timeZone () const
 Returns the user's time zone. More...
 
void setDateFormat (const WString &format)
 Sets the date format. More...
 
WString dateFormat () const
 Returns the date format. More...
 
void setTimeFormat (const WString &format)
 Sets the time format. More...
 
WString timeFormat () const
 Returns the time format. More...
 
void setDateTimeFormat (const WString &format)
 Sets the date/time format. More...
 
WString dateTimeFormat () const
 Returns the date/time format. More...
 
std::string name () const
 Returns the locale name. More...
 
double toDouble (const WString &value) const
 Parses a floating point number. More...
 
int toInt (const WString &value) const
 Parses an integer number. More...
 
WString toString (int value) const
 Formats an integer number.
 
WString toString (unsigned int value) const
 Formats an integer number.
 
WString toString (long value) const
 Formats an integer number.
 
WString toString (unsigned long value) const
 Formats an integer number.
 
WString toString (long long value) const
 Formats an integer number.
 
WString toString (unsigned long long value) const
 Formats an integer number.
 
WString toString (double value) const
 Formats a floating point number.
 
WString toFixedString (double value, int precision) const
 Formats a floating point number with given precision.
 

Static Public Member Functions

static const WLocalecurrentLocale ()
 Returns the current (user) locale. More...
 
static void setCurrentLocale (const WLocale &locale)
 Sets the current (user) locale. More...
 

Detailed Description

A locale.

This class provides localization support for an application.

It can be used to determine the formatting of dates and numbers, and by WLocalDateTime to determine the time zone.

Note that only the name() parameter is automatically retrieved from the browser, if possible, and message resources are deduced based on that. All other parameters have to be configured.

See also
WApplication::locale()

Constructor & Destructor Documentation

◆ WLocale() [1/3]

Wt::WLocale::WLocale ( )

Default constructor.

Configures a locale with an empty name, and US conventions:

  • "yyyy/MM/dd" format for dates.
  • "." as decimal point, and no group separator.

◆ WLocale() [2/3]

Wt::WLocale::WLocale ( const std::string &  locale)

Creates a locale by name.

The locale name is a string such as "en" (for English) or "en_GB" (for UK English).

◆ WLocale() [3/3]

Wt::WLocale::WLocale ( const char *  locale)

Creates a locale by name.

The locale name is a string such as "en" (for English) or "en_GB" (for UK English).

Member Function Documentation

◆ currentLocale()

const WLocale & Wt::WLocale::currentLocale ( )
static

Returns the current (user) locale.

This returns WApplication::instance()->locale() if the WApplication::instance() != 0, or a default locale otherwise.

◆ dateFormat()

WString Wt::WLocale::dateFormat ( ) const

Returns the date format.

Returns the date format.

◆ dateTimeFormat()

WString Wt::WLocale::dateTimeFormat ( ) const

Returns the date/time format.

Returns the date/time format.

◆ decimalPoint()

std::string Wt::WLocale::decimalPoint ( ) const

Returns the decimal point.

See also
setDecimalPoint()

◆ groupSeparator()

std::string Wt::WLocale::groupSeparator ( ) const

Returns the decimal group separator.

See also
setGroupSeparator()

◆ name()

std::string Wt::WLocale::name ( ) const

Returns the locale name.

This is the name of the locale that was set through the constructor.

◆ setCurrentLocale()

void Wt::WLocale::setCurrentLocale ( const WLocale locale)
static

Sets the current (user) locale.

This calls WApplication::setLocale().

When there is no session (e.i. WApplication::instance() == 0), for example in WResource::handleRequest(), then this sets the locale for the current request.

◆ setDateFormat()

void Wt::WLocale::setDateFormat ( const WString format)

Sets the date format.

Sets the default format for date entry, e.g. as used in WDateValidator. See WDate::toString() for the supported syntax.

The default date format is "yyyy-MM-dd".

◆ setDateTimeFormat()

void Wt::WLocale::setDateTimeFormat ( const WString format)

Sets the date/time format.

Sets the format for a localized time stamp (using WLocalDateTime::toString()). See WDateTime::toString() for the supported syntax.

The default date/time format is "yyyy-MM-dd HH:mm:ss".

◆ setDecimalPoint()

void Wt::WLocale::setDecimalPoint ( std::string  c)

Sets the decimal point.

Sets the character used to separate integral from fractional digits in a double.

Note
the argument is a UTF-8 encoded character and can thus be up to 4 byte.

◆ setGroupSeparator()

void Wt::WLocale::setGroupSeparator ( std::string  c)

Sets the decimal group separator.

Sets the character used to separate thousands in a number.

Note
the argument is a UTF-8 encoded character and can thus be up to 4 byte.

◆ setTimeFormat()

void Wt::WLocale::setTimeFormat ( const WString format)

Sets the time format.

Sets the default format for time entry, eg. as used in WTimeValidator. See WTime::toString() for the supported syntax.

The default time format is "HH:mm:ss".

◆ setTimeZone()

void Wt::WLocale::setTimeZone ( const cpp20::date::time_zone *  zone)

Sets the time zone.

This sets the time zone (used by the client). This is a time zone from Howard Hinnant's date library, which will become integrated into the C++20 standard.

A time zone can be retrieved with date::locate_zone using the name of the time zone. The time zone name may be retrieved with WEnvironment::timeZoneName(), if supported by the browser.

WEnvironment::timeZoneOffset() will also (if available) contain an offset. This offset could be used to let the user select a time zone from a list of timezones. You can get a list of zones with date::get_tzdb().zones.

The timezone is used by WLocalDateTime.

See also
https://howardhinnant.github.io/date/date.html
https://howardhinnant.github.io/date/tz.html
WEnvironment::timeZoneName()
WEnvironment::timeZoneOffset()

◆ timeFormat()

WString Wt::WLocale::timeFormat ( ) const

Returns the time format.

Returns the time format.

◆ timeZone()

const cpp20::date::time_zone* Wt::WLocale::timeZone ( ) const

Returns the user's time zone.

See also
setTimeZone()

◆ toDouble()

double Wt::WLocale::toDouble ( const WString value) const

Parses a floating point number.

Throws a runtime exception if the number could not be parsed.

◆ toInt()

int Wt::WLocale::toInt ( const WString value) const

Parses an integer number.

Throws a runtime exception if the number could not be parsed.