Modify the interface of localization manager.

This commit is contained in:
beichen.liu 2016-03-01 14:27:12 +08:00
parent fe917e00fc
commit 4e4558e509
6 changed files with 43 additions and 12 deletions

View File

@ -8,7 +8,7 @@ using namespace cocos2d;
static JsonLocalizationManager* _sharedJsonLocalizationManager = nullptr;
JsonLocalizationManager* JsonLocalizationManager::getInstance()
ILocalizationManager* JsonLocalizationManager::getInstance()
{
if (!_sharedJsonLocalizationManager)
{
@ -60,7 +60,7 @@ std::string JsonLocalizationManager::getLocalizationString(std::string key)
static BinLocalizationManager* _sharedBinLocalizationManager = nullptr;
BinLocalizationManager* BinLocalizationManager::getInstance()
ILocalizationManager* BinLocalizationManager::getInstance()
{
if (!_sharedBinLocalizationManager)
{
@ -121,3 +121,19 @@ std::string BinLocalizationManager::getLocalizationString(std::string key)
return result;
}
static ILocalizationManager* _sharedLocalizationManager = nullptr;
ILocalizationManager* LocalizationHelper::getCurrentManager()
{
if (!_sharedLocalizationManager)
{
_sharedLocalizationManager = BinLocalizationManager::getInstance();
}
return _sharedLocalizationManager;
}
void LocalizationHelper::setCurrentManager(ILocalizationManager* manager)
{
_sharedLocalizationManager = manager;
}

View File

@ -26,7 +26,7 @@ namespace cocostudio {
class CC_STUDIO_DLL JsonLocalizationManager : ILocalizationManager
{
public:
static JsonLocalizationManager* getInstance();
static ILocalizationManager* getInstance();
JsonLocalizationManager();
~JsonLocalizationManager();
@ -52,7 +52,7 @@ namespace cocostudio {
class CC_STUDIO_DLL BinLocalizationManager : ILocalizationManager
{
public:
static BinLocalizationManager* getInstance();
static ILocalizationManager* getInstance();
BinLocalizationManager();
~BinLocalizationManager();
@ -73,6 +73,21 @@ namespace cocostudio {
protected:
std::unordered_map<std::string, std::string> languageData;
};
class CC_STUDIO_DLL LocalizationHelper
{
public:
/* Get current localization manager.
* @return If the manager has been set, return current localization manager,
* otherwise return the singleton instance of BinLocalizationManager.
*/
static ILocalizationManager* getCurrentManager();
/* Set current localization manager.
* @param manager Instance of current localization manager.
*/
static void setCurrentManager(ILocalizationManager* manager);
};
}
#endif //__LOCALLIZATION_MANAGER_H__

View File

@ -834,8 +834,8 @@ namespace cocostudio
bool isLocalized = options->isLocalized() != 0;
if (isLocalized)
{
BinLocalizationManager* localizer = BinLocalizationManager::getInstance();
button->setTitleText(localizer->getLocalizationString(titleText));
ILocalizationManager* lm = LocalizationHelper::getCurrentManager();
button->setTitleText(lm->getLocalizationString(titleText));
}
else
{

View File

@ -240,8 +240,8 @@ namespace cocostudio
bool isLocalized = options->isLocalized() != 0;
if (isLocalized)
{
BinLocalizationManager* localizer = BinLocalizationManager::getInstance();
labelBMFont->setString(localizer->getLocalizationString(text));
ILocalizationManager* lm = LocalizationHelper::getCurrentManager();
labelBMFont->setString(lm->getLocalizationString(text));
}
else
{

View File

@ -298,8 +298,8 @@ namespace cocostudio
bool isLocalized = options->isLocalized() != 0;
if (isLocalized)
{
BinLocalizationManager* localizer = BinLocalizationManager::getInstance();
textField->setString(localizer->getLocalizationString(text));
ILocalizationManager* lm = LocalizationHelper::getCurrentManager();
textField->setString(lm->getLocalizationString(text));
}
else
{

View File

@ -460,8 +460,8 @@ namespace cocostudio
bool isLocalized = options->isLocalized() != 0;
if (isLocalized)
{
BinLocalizationManager* localizer = BinLocalizationManager::getInstance();
label->setString(localizer->getLocalizationString(text));
ILocalizationManager* lm = LocalizationHelper::getCurrentManager();
label->setString(lm->getLocalizationString(text));
}
else
{