mirror of https://github.com/axmolengine/axmol.git
Modify the interface of localization manager.
This commit is contained in:
parent
fe917e00fc
commit
4e4558e509
|
@ -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;
|
||||
}
|
|
@ -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__
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue