diff --git a/cocos/editor-support/cocostudio/LocalizationManager.cpp b/cocos/editor-support/cocostudio/LocalizationManager.cpp index f2dd985be6..b6df13e898 100644 --- a/cocos/editor-support/cocostudio/LocalizationManager.cpp +++ b/cocos/editor-support/cocostudio/LocalizationManager.cpp @@ -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; +} \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/LocalizationManager.h b/cocos/editor-support/cocostudio/LocalizationManager.h index 17f3ed3b7d..a06326a9d8 100644 --- a/cocos/editor-support/cocostudio/LocalizationManager.h +++ b/cocos/editor-support/cocostudio/LocalizationManager.h @@ -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 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__ \ No newline at end of file diff --git a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp index e0af24bda2..c3289cba02 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/ButtonReader/ButtonReader.cpp @@ -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 { diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp index b83091c5c8..8207e91b38 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextBMFontReader/TextBMFontReader.cpp @@ -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 { diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp index 8d1401963d..cf7ffd3a3b 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextFieldReader/TextFieldReader.cpp @@ -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 { diff --git a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp index 8082278e96..e0def35086 100644 --- a/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp +++ b/cocos/editor-support/cocostudio/WidgetReader/TextReader/TextReader.cpp @@ -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 {