Wt: Wt::WCombinedLocalizedStrings Class Reference

Wt 4.10.4

Loading...
Searching...
No Matches
Public Member Functions | List of all members
Wt::WCombinedLocalizedStrings Class Reference

A localized string resolver that bundles multiple string resolvers. More...

`#include <Wt/WCombinedLocalizedStrings.h>`

Inheritance diagram for Wt::WCombinedLocalizedStrings:
[legend]

## Public Member Functions
| WCombinedLocalizedStrings ()
| Constructor.
void | add (const std::shared_ptr< WLocalizedStrings > &resolver)
| Adds a string resolver.
void | insert (int index, const std::shared_ptr< WLocalizedStrings > &resolver)
| Inserts a string resolver.
void | remove (const std::shared_ptr< WLocalizedStrings > &resolver)
| Removes a string resolver.
virtual void | hibernate () override
| Purges memory resources, if possible.
virtual LocalizedString | resolveKey (const WLocale &locale, const std::string &key) override
| Resolves a key in the given locale.
virtual LocalizedString | resolvePluralKey (const WLocale &locale, const std::string &key, ::uint64_t amount) override
| Resolves the plural form of a key in the given locale.
Public Member Functions inherited from Wt::WLocalizedStrings
virtual | ~WLocalizedStrings ()
| Destructor.

## Additional Inherited Members
Static Public Member Functions inherited from Wt::WLocalizedStrings
static int | evaluatePluralExpression (const std::string &expression, ::uint64_t n)
| Utility method to evaluate a plural expression.

## Detailed Description

A localized string resolver that bundles multiple string resolvers.

This class implements the localized strings interface and delegates WString::tr() string resolution to one or more string resolvers. You will typically use this class if you want to combine different methods of string resolution (e.g. some from files, and other strings using a database).

See also
  WApplication::setLocalizedStrings()

## Member Function Documentation

## ◆ add()

void Wt::WCombinedLocalizedStrings::add | ( | const std::shared_ptr< WLocalizedStrings > & | resolver | ) |

Adds a string resolver.

The order in which string resolvers are added is significant: resolveKey() will consult each string resolver in the order they have been added, until a match is found.

Ownership of the resolver is transferred.

## ◆ hibernate()

virtual void Wt::WCombinedLocalizedStrings::hibernate | ( |  | ) |
| overridevirtual

Purges memory resources, if possible.

This is called afer event handling, and is an opportunity to conserve memory inbetween events, by freeing memory used for cached key/value bindings, if applicable.

The default implementation does nothing.

Reimplemented from Wt::WLocalizedStrings.

## ◆ insert()

void Wt::WCombinedLocalizedStrings::insert | ( | int | index,
|  | const std::shared_ptr< WLocalizedStrings > & | resolver )

Inserts a string resolver.

See also
  add()

## ◆ remove()

void Wt::WCombinedLocalizedStrings::remove | ( | const std::shared_ptr< WLocalizedStrings > & | resolver | ) |

Removes a string resolver.

See also
  add()

## ◆ resolveKey()

virtual LocalizedString Wt::WCombinedLocalizedStrings::resolveKey | ( | const WLocale & | locale,
|  | const std::string & | key )
| overridevirtual

Resolves a key in the given locale.

This method is used by WString to obtain the UTF-8 value corresponding to a key in the given locale.

Returns a successful LocalizedString if the key could be resolved.

See also
  WString::tr()

Implements Wt::WLocalizedStrings.

## ◆ resolvePluralKey()

virtual LocalizedString Wt::WCombinedLocalizedStrings::resolvePluralKey | ( | const WLocale & | locale,
|  | const std::string & | key,
|  | ::uint64_t | amount )
| overridevirtual

Resolves the plural form of a key in the given locale.

This method is used by WString to obtain the UTF-8 value corresponding to a key in the current locale, taking into account the possibility of multiple plural forms, and chosing the right plural form based on the `amount` passed.

Throws a std::logic_error if the underlying implementation does not provide support for plural internationalized strings.

Returns a successful LocalizedString if the key could be resolved.

See also
  WString::trn()

Reimplemented from Wt::WLocalizedStrings.