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; static JsonLocalizationManager* _sharedJsonLocalizationManager = nullptr;
JsonLocalizationManager* JsonLocalizationManager::getInstance() ILocalizationManager* JsonLocalizationManager::getInstance()
{ {
if (!_sharedJsonLocalizationManager) if (!_sharedJsonLocalizationManager)
{ {
@ -60,7 +60,7 @@ std::string JsonLocalizationManager::getLocalizationString(std::string key)
static BinLocalizationManager* _sharedBinLocalizationManager = nullptr; static BinLocalizationManager* _sharedBinLocalizationManager = nullptr;
BinLocalizationManager* BinLocalizationManager::getInstance() ILocalizationManager* BinLocalizationManager::getInstance()
{ {
if (!_sharedBinLocalizationManager) if (!_sharedBinLocalizationManager)
{ {
@ -121,3 +121,19 @@ std::string BinLocalizationManager::getLocalizationString(std::string key)
return result; 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 class CC_STUDIO_DLL JsonLocalizationManager : ILocalizationManager
{ {
public: public:
static JsonLocalizationManager* getInstance(); static ILocalizationManager* getInstance();
JsonLocalizationManager(); JsonLocalizationManager();
~JsonLocalizationManager(); ~JsonLocalizationManager();
@ -52,7 +52,7 @@ namespace cocostudio {
class CC_STUDIO_DLL BinLocalizationManager : ILocalizationManager class CC_STUDIO_DLL BinLocalizationManager : ILocalizationManager
{ {
public: public:
static BinLocalizationManager* getInstance(); static ILocalizationManager* getInstance();
BinLocalizationManager(); BinLocalizationManager();
~BinLocalizationManager(); ~BinLocalizationManager();
@ -73,6 +73,21 @@ namespace cocostudio {
protected: protected:
std::unordered_map<std::string, std::string> languageData; 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__ #endif //__LOCALLIZATION_MANAGER_H__

View File

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

View File

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

View File

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

View File

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