Singleton class to aid in runtime localization.
More...
#include <hdicoreLocalizer.h>
|
typedef std::map< Locale, std::string > | StringMap |
|
|
Locale | defaultLocale () const |
| Gets the default locale of the Localizer instance.
|
|
void | setDefaultLocale (const Locale defaultLocale_) |
| Sets the default locale of the Localizer instance.
|
|
void | addString (const std::string &key_, const Locale locale_, const std::string &str_) |
| Adds a new localized string value, keyed by a unique string and the value's locale.
|
|
void | removeString (const std::string &key_, const Locale locale_) |
| Removes an existing localized string value by its key and locale.
|
|
StringMap | getAllStrings (const std::string &key_) const |
| Gets a map of locales and their corresponding localized strings for a given key.
|
|
std::string | getString (const std::string &key_, const Locale locale_) const |
| Gets a localized string for a given key and locale.
|
|
std::string | getLocalString (const std::string &key_) const |
| Gets a localized string for a given key and whatever locale the app currently has.
|
|
|
static Localizer * | instance () |
| Allows access to the singleton localizer instance object.
|
|
Singleton class to aid in runtime localization.
Strings are added to this container with a key, locale for the value, and the localized value itself. Localized strings can then be retrieved from the container at runtime using a variety of methods.
#define HDI_CORE_LOCALIZER
Slightly shorter way to access the Localizer instance, but still utilizing a non-colliding name schem...
Definition: hdicoreLocalizer.h:17
◆ addString()
void hdi::core::Localizer::addString |
( |
const std::string & |
key_, |
|
|
const Locale |
locale_, |
|
|
const std::string & |
str_ |
|
) |
| |
Adds a new localized string value, keyed by a unique string and the value's locale.
- Author
- GW
- Date
- 08/2013
- Parameters
-
key_ | Unique string key for the value, as UTF-8 |
locale_ | Locale of the value |
str_ | Localized string value, as UTF-8 |
◆ defaultLocale()
Locale hdi::core::Localizer::defaultLocale |
( |
| ) |
const |
Gets the default locale of the Localizer instance.
- Author
- GW
- Date
- 08/2013
- Returns
- Default locale; always set to Locale_ENG_US initially
◆ getAllStrings()
StringMap hdi::core::Localizer::getAllStrings |
( |
const std::string & |
key_ | ) |
const |
Gets a map of locales and their corresponding localized strings for a given key.
- Author
- GW
- Date
- 08/2013
- Parameters
-
key_ | Unique string key for the value |
- Returns
- A map of all locales and their values, as UTF-8, for a given key, or an empty map for an unknown key
◆ getLocalString()
std::string hdi::core::Localizer::getLocalString |
( |
const std::string & |
key_ | ) |
const |
Gets a localized string for a given key and whatever locale the app currently has.
- Author
- GW
- Date
- 08/2013
- Parameters
-
key_ | Unique string key for the value, as UTF-8 |
- Returns
- The localized string for the given key and current locale combination, as UTF-8
- Note
- If the given key does not have a value for the current locale, this method will default to the value for defaultLocale() and the given key.
-
Returns "" in the case of key_, the current locale, and defaultLocale() all being invalid
◆ getString()
std::string hdi::core::Localizer::getString |
( |
const std::string & |
key_, |
|
|
const Locale |
locale_ |
|
) |
| const |
Gets a localized string for a given key and locale.
- Author
- GW
- Date
- 08/2013
- Parameters
-
key_ | Unique string key for the value, as UTF-8 |
locale_ | Locale of the value |
- Returns
- The localized string for the given key/locale combination, as UTF-8
- Note
- Will return "" in the case of key_, locale_, and defaultLocale() all being invalid
◆ instance()
static Localizer * hdi::core::Localizer::instance |
( |
| ) |
|
|
static |
Allows access to the singleton localizer instance object.
- Author
- GW
- Date
- 08/2013
- Returns
- The localizer instance object
◆ removeString()
void hdi::core::Localizer::removeString |
( |
const std::string & |
key_, |
|
|
const Locale |
locale_ |
|
) |
| |
Removes an existing localized string value by its key and locale.
- Author
- GW
- Date
- 08/2013
- Parameters
-
key_ | Unique string key for the value, as UTF-8 |
locale_ | Locale of the value |
◆ setDefaultLocale()
void hdi::core::Localizer::setDefaultLocale |
( |
const Locale |
defaultLocale_ | ) |
|
Sets the default locale of the Localizer instance.
- Author
- GW
- Date
- 08/2013
- Parameters
-
defaultLocale_ | New default locale |