A locale. More...
#include <Wt/WLocale>
Public Member Functions | |
WLocale () | |
Default constructor. More... | |
WLocale (const Wt::WLocale &locale) | |
Copy constructor. | |
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 std::string &posixTimeZone) |
Sets the time zone. More... | |
std::string | timeZone () const |
Returns the user's time zone. More... | |
void | setDateFormat (const WString &format) |
Sets the date format. More... | |
WString | dateFormat () const |
void | setDateTimeFormat (const WString &format) |
Sets the date/time format. More... | |
WString | dateTimeFormat () const |
std::string | name () const |
Returns the locale name. More... | |
operator std::string () const | |
Casts to the locale string (for pre-3.3.0 compatibility). 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 (::int64_t value) const |
Formats an integer number. | |
WString | toString (::uint64_t 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 WLocale & | currentLocale () |
Returns the current (user) locale. More... | |
A locale.
This class provides localization support for an application.
It's functionality is currently limited to date and number formatting, and the formatting properties need to be configured here, we plan to leverage standard C++ locale functionality to obtain these configurations. The locale also provides client-side support, and thus cannot solely rely on C++'s locale support.
Wt::WLocale::WLocale | ( | ) |
Default constructor.
Configures a locale with an empty name, and US conventions:
|
static |
Returns the current (user) locale.
This returns WApplication::instance()->locale() if the WApplication::instance() != 0, or a default locale otherwise.
WString Wt::WLocale::dateFormat | ( | ) | const |
Returns the date format.
WString Wt::WLocale::dateTimeFormat | ( | ) | const |
Returns the date/time format.
std::string Wt::WLocale::decimalPoint | ( | ) | const |
Returns the decimal point.
std::string Wt::WLocale::groupSeparator | ( | ) | const |
Returns the decimal group separator.
std::string Wt::WLocale::name | ( | ) | const |
Returns the locale name.
This is the name of the locale that was set through the constructor.
Wt::WLocale::operator std::string | ( | ) | const |
Casts to the locale string (for pre-3.3.0 compatibility).
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".
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".
void Wt::WLocale::setDecimalPoint | ( | std::string | c) |
Sets the decimal point.
Sets the character used to separate integral from fractional digits in a double.
void Wt::WLocale::setGroupSeparator | ( | std::string | c) |
Sets the decimal group separator.
Sets the character used to separate thousands in a number.
void Wt::WLocale::setTimeZone | ( | const std::string & | posixTimeZone) |
Sets the time zone.
This sets the time zone (used by the client). The posixTimeZone
must be an IEEE Std 1003.1 zone string in the form of: "std offset dst [offset],start[/time],end[/time]" and specifies all aspects of UTC to local time conversion for the user, including taking into account daylight savings time.
e.g. "EST-5EDT,M4.1.0,M10.5.0" represents the time zone configuration suitable for USA EastCoast (NYC).
The time zone is not provided by the browser and therefore you will need to ask the user to select an appropriate time zone. This can be done using for example boost::local_time::tz_database by asking the user to select his region from this database, and retrieving the corresponding time zone string. You may want to propose a suitable default time zone by using WEnvironment::timeZoneOffset() and pre-selecting a region that matches this offset.
The default value is empty.
The timezone is used by WLocalDateTime.
std::string Wt::WLocale::timeZone | ( | ) | const |
Returns the user's time zone.
double Wt::WLocale::toDouble | ( | const WString & | value) | const |
Parses a floating point number.
Throws a runtime exception if the number could not be parsed.
int Wt::WLocale::toInt | ( | const WString & | value) | const |
Parses an integer number.
Throws a runtime exception if the number could not be parsed.