Add cocostudio localization editor export data parser and demo

This commit is contained in:
肖峰 2016-02-26 17:15:24 +08:00
parent 9af2f4e73a
commit 6b4a0f808f
19 changed files with 360 additions and 10 deletions

View File

@ -3745,6 +3745,12 @@
85505F0E1B60E3DB003F2CD4 /* SkeletonNodeReader.h in Headers */ = {isa = PBXBuildFile; fileRef = C50306741B60B5B2001E6D43 /* SkeletonNodeReader.h */; };
85B3743A1B204B9400C488D6 /* clipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85B374381B204B9400C488D6 /* clipper.cpp */; };
85B3743B1B204B9400C488D6 /* clipper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 85B374381B204B9400C488D6 /* clipper.cpp */; };
94A6DF051C7303FD0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; };
94A6DF061C7303FD0094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; };
94A6DF071C73040D0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; };
94A6DF081C73040E0094AEF7 /* LocalizationManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */; };
94A6DF091C7304120094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; };
94A6DF0A1C7304120094AEF7 /* LocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */; };
A045F6D61BA81577005076C7 /* CCTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A045F6D41BA81577005076C7 /* CCTextureCube.cpp */; };
A045F6D71BA81577005076C7 /* CCTextureCube.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A045F6D41BA81577005076C7 /* CCTextureCube.cpp */; };
A045F6D81BA81577005076C7 /* CCTextureCube.h in Headers */ = {isa = PBXBuildFile; fileRef = A045F6D51BA81577005076C7 /* CCTextureCube.h */; };
@ -6580,6 +6586,8 @@
5E9F61251A3FFE3D0038DE01 /* CCPlane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCPlane.h; sourceTree = "<group>"; };
8525E3A11B291E42008EE815 /* clipper.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = clipper.hpp; sourceTree = "<group>"; };
85B374381B204B9400C488D6 /* clipper.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = clipper.cpp; sourceTree = "<group>"; };
94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LocalizationManager.cpp; sourceTree = "<group>"; };
94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LocalizationManager.h; sourceTree = "<group>"; };
A045F6D41BA81577005076C7 /* CCTextureCube.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTextureCube.cpp; sourceTree = "<group>"; };
A045F6D51BA81577005076C7 /* CCTextureCube.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTextureCube.h; sourceTree = "<group>"; };
A045F6DA1BA816A1005076C7 /* CCCameraBackgroundBrush.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCCameraBackgroundBrush.cpp; sourceTree = "<group>"; };
@ -8368,6 +8376,8 @@
1A8C5946180E930E00EF57C3 /* cocostudio */ = {
isa = PBXGroup;
children = (
94A6DF031C7303FD0094AEF7 /* LocalizationManager.cpp */,
94A6DF041C7303FD0094AEF7 /* LocalizationManager.h */,
382384021A259005002C4610 /* CSParseBinary_generated.h */,
182C5CAD1A95961600C30D34 /* CSParse3DBinary_generated.h */,
382384051A25900F002C4610 /* FlatBuffersSerialize.cpp */,
@ -11142,6 +11152,7 @@
15AE187F19AAD33D00C27E9E /* CCBKeyframe.h in Headers */,
B665E2B41AA80A6500DDB1C5 /* CCPUForceField.h in Headers */,
1A570073180BC5A10088DEC7 /* CCActionGrid.h in Headers */,
94A6DF061C7303FD0094AEF7 /* LocalizationManager.h in Headers */,
15AE1BCC19AAE01E00C27E9E /* CCControlButton.h in Headers */,
B6CAB3D71AF9AA1A00B9B856 /* btSolve2LinearConstraint.h in Headers */,
C50306771B60B5B2001E6D43 /* CSBoneBinary_generated.h in Headers */,
@ -12036,6 +12047,7 @@
507B3D3A1C31BDD30067B53E /* CCEventListenerAssetsManagerEx.h in Headers */,
507B3D3B1C31BDD30067B53E /* btGpu3DGridBroadphase.h in Headers */,
507B3D3C1C31BDD30067B53E /* CCAllocatorGlobal.h in Headers */,
94A6DF0A1C7304120094AEF7 /* LocalizationManager.h in Headers */,
507B3D3D1C31BDD30067B53E /* btSolverConstraint.h in Headers */,
507B3D3E1C31BDD30067B53E /* SpuDoubleBuffer.h in Headers */,
507B3D3F1C31BDD30067B53E /* CCPUScriptCompiler.h in Headers */,
@ -13043,6 +13055,7 @@
15B3708319EE414C00ABE682 /* CCEventListenerAssetsManagerEx.h in Headers */,
B6CAB4361AF9AA1A00B9B856 /* btGpu3DGridBroadphase.h in Headers */,
D0FD03521A3B51AA00825BB5 /* CCAllocatorGlobal.h in Headers */,
94A6DF091C7304120094AEF7 /* LocalizationManager.h in Headers */,
B6CAB3DC1AF9AA1A00B9B856 /* btSolverConstraint.h in Headers */,
B6CAB4B61AF9AA1A00B9B856 /* SpuDoubleBuffer.h in Headers */,
B665E3D11AA80A6600DDB1C5 /* CCPUScriptCompiler.h in Headers */,
@ -14687,6 +14700,7 @@
1A570354180BD0B00088DEC7 /* ioapi.cpp in Sources */,
15B3707819EE414C00ABE682 /* AssetsManagerEx.cpp in Sources */,
1A570358180BD0B00088DEC7 /* unzip.cpp in Sources */,
94A6DF051C7303FD0094AEF7 /* LocalizationManager.cpp in Sources */,
B665E3861AA80A6500DDB1C5 /* CCPUPathFollowerTranslator.cpp in Sources */,
B29A7DCB19EE1B7700872B35 /* Skeleton.c in Sources */,
15AE196E19AAD35700C27E9E /* CCActionTimelineCache.cpp in Sources */,
@ -15530,6 +15544,7 @@
507B3C141C31BDD30067B53E /* CCPUBoxCollider.cpp in Sources */,
507B3C151C31BDD30067B53E /* CCPUMeshSurfaceEmitter.cpp in Sources */,
507B3C161C31BDD30067B53E /* CCPUOnQuotaObserverTranslator.cpp in Sources */,
94A6DF081C73040E0094AEF7 /* LocalizationManager.cpp in Sources */,
507B3C171C31BDD30067B53E /* UIPageView.cpp in Sources */,
507B3C181C31BDD30067B53E /* CCComponentContainer.cpp in Sources */,
507B3C191C31BDD30067B53E /* ccCArray.cpp in Sources */,
@ -16373,6 +16388,7 @@
B665E22B1AA80A6500DDB1C5 /* CCPUBoxCollider.cpp in Sources */,
B665E3031AA80A6500DDB1C5 /* CCPUMeshSurfaceEmitter.cpp in Sources */,
B665E3571AA80A6500DDB1C5 /* CCPUOnQuotaObserverTranslator.cpp in Sources */,
94A6DF071C73040D0094AEF7 /* LocalizationManager.cpp in Sources */,
15AE1B7619AADA9A00C27E9E /* UIPageView.cpp in Sources */,
1A570311180BCF190088DEC7 /* CCComponentContainer.cpp in Sources */,
50ABBE2C1925AB6F00A911A9 /* ccCArray.cpp in Sources */,

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -526,6 +526,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClCompile Include="..\editor-support\cocostudio\CocoStudio.cpp" />
<ClCompile Include="..\editor-support\cocostudio\DictionaryHelper.cpp" />
<ClCompile Include="..\editor-support\cocostudio\FlatBuffersSerialize.cpp" />
<ClCompile Include="..\editor-support\cocostudio\LocalizationManager.cpp" />
<ClCompile Include="..\editor-support\cocostudio\TriggerBase.cpp" />
<ClCompile Include="..\editor-support\cocostudio\TriggerMng.cpp" />
<ClCompile Include="..\editor-support\cocostudio\TriggerObj.cpp" />
@ -1130,6 +1131,7 @@ xcopy /Y /Q "$(ProjectDir)..\..\external\chipmunk\prebuilt\win32\release-lib\*.*
<ClInclude Include="..\editor-support\cocostudio\CSParse3DBinary_generated.h" />
<ClInclude Include="..\editor-support\cocostudio\DictionaryHelper.h" />
<ClInclude Include="..\editor-support\cocostudio\FlatBuffersSerialize.h" />
<ClInclude Include="..\editor-support\cocostudio\LocalizationManager.h" />
<ClInclude Include="..\editor-support\cocostudio\TriggerBase.h" />
<ClInclude Include="..\editor-support\cocostudio\TriggerMng.h" />
<ClInclude Include="..\editor-support\cocostudio\TriggerObj.h" />

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="physics">
@ -1941,6 +1941,9 @@
<Filter>network</Filter>
</ClCompile>
<ClCompile Include="..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.cpp" />
<ClCompile Include="..\editor-support\cocostudio\LocalizationManager.cpp">
<Filter>cocostudio\json</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\physics\CCPhysicsBody.h">
@ -3791,6 +3794,9 @@
<ClInclude Include="..\editor-support\cocostudio\CSLanguageDataBinary_generated.h">
<Filter>cocostudio\json</Filter>
</ClInclude>
<ClInclude Include="..\editor-support\cocostudio\LocalizationManager.h">
<Filter>cocostudio\json</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\math\Mat4.inl">

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
@ -399,6 +399,7 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CSParse3DBinary_generated.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\DictionaryHelper.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\FlatBuffersSerialize.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\LocalizationManager.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerBase.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerMng.h" />
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerObj.h" />
@ -1011,6 +1012,7 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\CocoStudio.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\DictionaryHelper.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\FlatBuffersSerialize.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\LocalizationManager.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerBase.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerMng.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\TriggerObj.cpp" />

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClInclude Include="$(MSBuildThisFileDirectory)targetver.h" />
@ -1877,6 +1877,9 @@
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.h">
<Filter>cocostudio\reader\WidgetReader\Light3DReader</Filter>
</ClInclude>
<ClInclude Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\LocalizationManager.h">
<Filter>cocostudio\components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\cocos2d.cpp">
@ -3589,6 +3592,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.cpp">
<Filter>cocostudio\reader\WidgetReader\Light3DReader</Filter>
</ClCompile>
<ClCompile Include="$(MSBuildThisFileDirectory)..\..\..\..\editor-support\cocostudio\LocalizationManager.cpp">
<Filter>cocostudio\components</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Filter Include="2d">

View File

@ -509,6 +509,7 @@
<ClCompile Include="..\..\editor-support\cocostudio\CocoStudio.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\DictionaryHelper.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\FlatBuffersSerialize.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\LocalizationManager.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\TriggerBase.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\TriggerMng.cpp" />
<ClCompile Include="..\..\editor-support\cocostudio\TriggerObj.cpp" />
@ -1127,6 +1128,7 @@
<ClInclude Include="..\..\editor-support\cocostudio\CSParseBinary_generated.h" />
<ClInclude Include="..\..\editor-support\cocostudio\DictionaryHelper.h" />
<ClInclude Include="..\..\editor-support\cocostudio\FlatBuffersSerialize.h" />
<ClInclude Include="..\..\editor-support\cocostudio\LocalizationManager.h" />
<ClInclude Include="..\..\editor-support\cocostudio\TriggerBase.h" />
<ClInclude Include="..\..\editor-support\cocostudio\TriggerMng.h" />
<ClInclude Include="..\..\editor-support\cocostudio\TriggerObj.h" />

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Resource Files">
@ -1978,6 +1978,9 @@
<ClCompile Include="..\..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.cpp">
<Filter>cocostudio\reader\WidgetReader\Light3DReader</Filter>
</ClCompile>
<ClCompile Include="..\..\editor-support\cocostudio\LocalizationManager.cpp">
<Filter>cocostudio\components</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\cocos2d.h" />
@ -3863,6 +3866,9 @@
<ClInclude Include="..\..\editor-support\cocostudio\WidgetReader\Light3DReader\Light3DReader.h">
<Filter>cocostudio\reader\WidgetReader\Light3DReader</Filter>
</ClInclude>
<ClInclude Include="..\..\editor-support\cocostudio\LocalizationManager.h">
<Filter>cocostudio\components</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="..\..\base\CCController-iOS.mm">

View File

@ -34,6 +34,7 @@ CCComController.cpp \
CCComRender.cpp \
CCInputDelegate.cpp \
DictionaryHelper.cpp \
LocalizationManager.cpp \
CCSGUIReader.cpp \
CCSSceneReader.cpp \
TriggerBase.cpp \

View File

@ -39,6 +39,7 @@ set(COCOS_CS_SRC
editor-support/cocostudio/CCUtilMath.cpp
editor-support/cocostudio/CocoLoader.cpp
editor-support/cocostudio/DictionaryHelper.cpp
editor-support/cocostudio/LocalizationManager.cpp
editor-support/cocostudio/TriggerBase.cpp
editor-support/cocostudio/TriggerMng.cpp
editor-support/cocostudio/TriggerObj.cpp

View File

@ -0,0 +1,99 @@
#include "LocalizationManager.h"
#include "CCPlatformMacros.h"
#include "platform/CCFileUtils.h"
#include "editor-support/cocostudio/CSLanguageDataBinary_generated.h"
using namespace cocostudio;
using namespace cocos2d;
JsonLocalizationManager::JsonLocalizationManager()
:languageData(nullptr)
{
}
JsonLocalizationManager::~JsonLocalizationManager()
{
CC_SAFE_DELETE(languageData);
}
bool JsonLocalizationManager::initLanguageData(std::string file)
{
bool result = false;
std::string data = FileUtils::getInstance()->getStringFromFile(file);
if (!data.empty())
{
if (!languageData)
languageData = new rapidjson::Document;
languageData->Parse(data.c_str());
if (languageData->IsObject())
result = true;
else
CC_SAFE_DELETE(languageData);
}
return result;
}
std::string JsonLocalizationManager::getLocalizationString(std::string key)
{
std::string result = key;
if (languageData && languageData->HasMember(key.c_str()) &&
(*languageData)[key.c_str()].IsString())
result = (*languageData)[key.c_str()].GetString();
return result;
}
BinLocalizationManager::BinLocalizationManager()
{
}
BinLocalizationManager::~BinLocalizationManager()
{
}
bool BinLocalizationManager::initLanguageData(std::string file)
{
bool result = false;
languageData.clear();
Data buf = FileUtils::getInstance()->getDataFromFile(file);
if (!buf.isNull())
{
auto lanSet = flatbuffers::GetLanguageSet(buf.getBytes());
if (lanSet && lanSet->languageItems()->size() > 0)
{
result = true;
auto items = lanSet->languageItems();
int count = items->size();
for (int i = 0; i < count; i++)
{
auto it = items->Get(i);
std::string key = it->key()->c_str();
std::string value = it->value()->c_str();
if (!key.empty())
languageData[key] = value;
}
}
}
return result;
}
std::string BinLocalizationManager::getLocalizationString(std::string key)
{
std::string result = key;
if (!languageData.empty())
{
auto it = languageData.find(key);
if (it != languageData.end())
result = it->second;
}
return result;
}

View File

@ -0,0 +1,74 @@
#ifndef __LOCALLIZATION_MANAGER_H__
#define __LOCALLIZATION_MANAGER_H__
#include <string>
#include <unordered_map>
#include "json/document.h"
#include "cocostudio/CocosStudioExport.h"
namespace cocostudio {
/**
*@brief Localization string manager interface template.
*/
class ILocalizationManager
{
public:
virtual bool initLanguageData(std::string file) = 0;
virtual std::string getLocalizationString(std::string key) = 0;
};
/**
*@brief Localization string manager for output Json data file by cocostudio localization editor.
* Note: If changed localization data file manually, please make sure the data file save as
* text file format with encoding as 'UTF8 no BOM', otherwise the localization data may
* not been parse successfully.
*/
class CC_STUDIO_DLL JsonLocalizationManager : ILocalizationManager
{
public:
JsonLocalizationManager();
~JsonLocalizationManager();
public:
/* Init manager with special localize json data file.
* @param file Name of localize file.
* @return If manager initialize success return true.
*/
virtual bool initLanguageData(std::string file);
/* Get localization string for special key.
* @param key Special key to search in localization data.
* @return If manager find the key in localization data, return value
* set to key, otherwise return key itself.
*/
virtual std::string getLocalizationString(std::string key);
protected:
rapidjson::Document * languageData;
};
class CC_STUDIO_DLL BinLocalizationManager : ILocalizationManager
{
public:
BinLocalizationManager();
~BinLocalizationManager();
/* Init manager with special localize binary data file.
* @param file Name of localize file.
* @return If manager initialize success return true.
*/
virtual bool initLanguageData(std::string file);
/* Get localization string for special key.
* @param key Special key to search in localization data.
* @return If manager find the key in localization data, return value
* set to key, otherwise return key itself.
*/
virtual std::string getLocalizationString(std::string key);
protected:
std::unordered_map<std::string, std::string> languageData;
};
}
#endif //__LOCALLIZATION_MANAGER_H__

View File

@ -105,6 +105,8 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelUnderlineMultiline);
ADD_TEST_CASE(LabelItalics);
ADD_TEST_CASE(LabelBold);
ADD_TEST_CASE(LabelLocalizationTest);
};
LabelFNTColorAndOpacity::LabelFNTColorAndOpacity()
@ -3053,3 +3055,109 @@ std::string LabelStrikethrough::subtitle() const
return "Strikethrough on TTF and BMfont with multiline";
}
LabelLocalizationTest::LabelLocalizationTest()
{
_localizationJson = new cocostudio::JsonLocalizationManager();
_localizationJson->initLanguageData("configs/en-US.lang.json");
_localizationBin = new cocostudio::BinLocalizationManager;
_localizationBin->initLanguageData("configs/ENGLISH.lang.csb");
const float BUTTON_WIDTH = 100;
float startPosX = 0;
Size winSize = Director::getInstance()->getVisibleSize();
// Create a radio button group
auto radioButtonGroup = RadioButtonGroup::create();
this->addChild(radioButtonGroup);
// Create the radio buttons
const int NUMBER_OF_BUTTONS = 3;
startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1) * 0.5 * BUTTON_WIDTH - 30;
std::vector<std::string> labelTypes = { "English", "Chinese", "Japanese" };
for (int i = 0; i < NUMBER_OF_BUTTONS; ++i)
{
RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");
float posX = startPosX + BUTTON_WIDTH * i;
radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
radioButton->setScale(1.2f);
radioButton->addEventListener(CC_CALLBACK_2(LabelLocalizationTest::onChangedRadioButtonSelect, this));
radioButton->setTag(i);
radioButtonGroup->addRadioButton(radioButton);
this->addChild(radioButton);
auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20);
label->setPosition(radioButton->getPosition() + Vec2(50, 0));
this->addChild(label);
}
_label1 = Label::createWithSystemFont(_localizationJson->getLocalizationString("Text Label"), "Arial", 24);
addChild(_label1, 0);
_label1->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 3));
Label * label = Label::createWithSystemFont("From json data :", "Arial", 24);
label->setAnchorPoint(Vec2(0, 0.5));
addChild(label, 0);
label->setPosition(Vec2(20, winSize.height * 1 / 3 + 24));
_label2 = Label::createWithSystemFont(_localizationBin->getLocalizationString("Text Label"), "Arial", 24);
addChild(_label2, 0);
_label2->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 2));
label = Label::createWithSystemFont("From binary data :", "Arial", 24);
label->setAnchorPoint(Vec2(0, 0.5));
addChild(label, 0);
label->setPosition(Vec2(20, winSize.height * 1 / 2 + 24));
}
std::string LabelLocalizationTest::title() const
{
return "Localization Test";
}
std::string LabelLocalizationTest::subtitle() const
{
return "Change language selected and see label change";
}
void LabelLocalizationTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type)
{
if (radioButton == nullptr)
{
return;
}
switch (type)
{
case RadioButton::EventType::SELECTED:
{
switch (radioButton->getTag()) {
case 0:
_localizationJson->initLanguageData("configs/en-US.lang.json");
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
_localizationBin->initLanguageData("configs/ENGLISH.lang.csb");
_label2->setString(_localizationJson->getLocalizationString("Text Label"));
break;
case 1:
_localizationJson->initLanguageData("configs/zh-CN.lang.json");
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
_localizationBin->initLanguageData("configs/CHINESE.lang.csb");
_label2->setString(_localizationJson->getLocalizationString("Text Label"));
break;
case 2:
_localizationJson->initLanguageData("configs/ja-JP.lang.json");
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
_localizationBin->initLanguageData("configs/JAPANESE.lang.csb");
_label2->setString(_localizationJson->getLocalizationString("Text Label"));
break;
default:
break;
}
break;
}
default:
break;
}
}

View File

@ -5,6 +5,7 @@
#include "renderer/CCCustomCommand.h"
#include "ui/CocosGUI.h"
#include "extensions/cocos-ext.h"
#include "editor-support/cocostudio/LocalizationManager.h"
DEFINE_TEST_SUITE(NewLabelTests);
@ -842,4 +843,21 @@ public:
cocos2d::Label* _label2a;
};
class LabelLocalizationTest : public AtlasDemoNew
{
public:
CREATE_FUNC(LabelLocalizationTest);
LabelLocalizationTest();
void onChangedRadioButtonSelect(cocos2d::ui::RadioButton* radioButton, cocos2d::ui::RadioButton::EventType type);
virtual std::string title() const override;
virtual std::string subtitle() const override;
cocos2d::Label* _label1;
cocos2d::Label* _label2;
cocostudio::JsonLocalizationManager* _localizationJson;
cocostudio::BinLocalizationManager* _localizationBin;
};
#endif

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,3 @@
{
"Text Label": "Text Label"
}

View File

@ -0,0 +1,3 @@
{
"Text Label": "テキストラベル"
}

View File

@ -0,0 +1,3 @@
{
"Text Label": "文本标签"
}