Hot Door CORE  0.7.0
Adobe® Illustrator® Plug-in Library
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. More...
 
void setDefaultLocale (const Locale defaultLocale_)
 Sets the default locale of the Localizer instance. More...
 
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. More...
 
void removeString (const std::string &key_, const Locale locale_)
 Removes an existing localized string value by its key and locale. More...
 
StringMap getAllStrings (const std::string &key_) const
 Gets a map of locales and their corresponding localized strings for a given key. More...
 
std::string getString (const std::string &key_, const Locale locale_) const
 Gets a localized string for a given key and locale. More...
 
std::string getLocalString (const std::string &key_) const
 Gets a localized string for a given key and whatever locale Illustrator currently has. More...
 

Static Public Member Functions

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

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 Illustrator'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");

Member Function Documentation

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
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
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
std::string hdi::core::Localizer::getLocalString ( const std::string &  key_) const

Gets a localized string for a given key and whatever locale Illustrator 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
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
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
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
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