Hot Door CORE 0.8.2
Adobe® Illustrator® Plug-in Library
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
hdi::core::Localizer Class Reference

Singleton class to aid in runtime localization. More...

#include <hdicoreLocalizer.h>

Public Types

typedef std::map< Locale, std::string > StringMap
 

Public Member Functions

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 Public Member Functions

static Localizerinstance ()
 Allows access to the singleton localizer instance object.
 

Friends

class Plugin
 

Detailed Description

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.

// It's best to picture the localized strings as being stored in a map keyed on the locale, with this
// map then being stored in another map keyed on a unique string.
// To add strings:
HDI_CORE_LOCALIZER->addString("HelloKey", Locale_ENG_US, "Hello");
HDI_CORE_LOCALIZER->addString("HelloKey", Locale_FRA_FR, "Bonjour");
HDI_CORE_LOCALIZER->addString("HelloKey", Locale_DEU_DE, "Hallo");
HDI_CORE_LOCALIZER->addString("HelloKey", Locale_SPA_MX, "Hola");
// To get strings:
// (This would return a map keyed on locale, with the values as in the example above)
HDI_CORE_LOCALIZER->getAllStrings("HelloKey");
// (This would return the string "Bonjour")
HDI_CORE_LOCALIZER->getString("HelloKey", Locale_FRA_FR);
// (This would use whatever the app's current locale is to acquire the string, defaulting to
// defaultLocale() if the current locale has not been added for the key "HelloKey")
HDI_CORE_LOCALIZER->getLocalString("HelloKey");
#define HDI_CORE_LOCALIZER
Slightly shorter way to access the Localizer instance, but still utilizing a non-colliding name schem...
Definition: hdicoreLocalizer.h:17

Member Function Documentation

◆ 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