Skip to content

Commit

Permalink
Add feature to switch between different locales within a same code ba…
Browse files Browse the repository at this point in the history
…se (#158)

Fixes #153
  • Loading branch information
ankitk20 authored and mathewnik90 committed Aug 2, 2019
1 parent e647bed commit 98c8e60
Show file tree
Hide file tree
Showing 219 changed files with 7,597 additions and 751 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -132,10 +132,13 @@ proj.win32/*.opendb
# Keystore files
*.jks
*.keystore

**/goa/firebase_cpp_sdk
**/goa/Classes/firebase
**/goa/cocos2d/cocos/firebase

google-services.json

# Generated documentation, it can be regenerated using doxygen #
######################
docs/html/*
docs/html/*
Binary file removed Chimple-Privacy-Policy.pdf
Binary file not shown.
Binary file added SimpleClass-Privacy-Policy.pdf
Binary file not shown.
Binary file removed goa/.vscode/ipch/1d93d47ff5935787/mmap_address.bin
Binary file not shown.
96 changes: 57 additions & 39 deletions goa/Classes/lang/EnglishUtil.cpp
Expand Up @@ -7,123 +7,141 @@
//

#include "EnglishUtil.h"
#include "../menu/LevelHelpScene.h"
#include "ctype.h"

USING_NS_CC;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
static const char* audioExt = ".wav";
static const char *audioExt = ".wav";
#else
static const char* audioExt = ".m4a";
static const char *audioExt = ".m4a";
#endif

static const char* pronounciationAudioExt = ".ogg";
static const char *pronounciationAudioExt = ".ogg";

static const wchar_t* const allCharacters = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
static const wchar_t* const allLowerCaseCharacters = L"abcdefghijklmnopqrstuvwxyz" ;
static const wchar_t* const allNumbers = L"0123456789" ;
static const wchar_t *const allCharacters = L"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static const wchar_t *const allLowerCaseCharacters = L"abcdefghijklmnopqrstuvwxyz";
static const wchar_t *const allNumbers = L"0123456789";

const wchar_t* EnglishUtil::getAllLowerCaseCharacters() {
const wchar_t *EnglishUtil::getAllLowerCaseCharacters()
{
return allLowerCaseCharacters;
}

const wchar_t* EnglishUtil::getAllNumbers() {
const wchar_t *EnglishUtil::getAllNumbers()
{
return allNumbers;
}

const wchar_t* EnglishUtil::getAllCharacters() {
const wchar_t *EnglishUtil::getAllCharacters()
{
return allCharacters;
}

int EnglishUtil::getNumberOfCharacters() {
int EnglishUtil::getNumberOfCharacters()
{
return 26;
}

const std::vector<int> EnglishUtil::getNumCharsInRows() {
const std::vector<int> EnglishUtil::getNumCharsInRows()
{
static const int en[] = {26};
static const std::vector<int> englishNumCharsInRows(en, en + 1);
return englishNumCharsInRows;
}

std::string EnglishUtil::getMonsterAnimationFileName(std::string alpha) {
return std::string("lang/eng/") + alpha +".csb";
std::string EnglishUtil::getMonsterAnimationFileName(std::string alpha)
{
return std::string("lang/eng/") + alpha + ".csb";
}

std::string EnglishUtil::getSpecialAnimationFileName(wchar_t alpha, std::string suffix) {
return std::string("lang/eng/") + suffix + "/" + convertUTF16CharToString(alpha) +".csb";
std::string EnglishUtil::getSpecialAnimationFileName(wchar_t alpha, std::string suffix)
{
return std::string("lang/eng/") + suffix + "/" + convertUTF16CharToString(alpha) + ".csb";
}

std::string EnglishUtil::getBMFontFileName() {
std::string EnglishUtil::getBMFontFileName()
{
return "lang/eng/baloo_bhai_common.fnt";
}

std::string EnglishUtil::getAlphabetSoundFileName(wchar_t alpha) {
auto lowerCase = tolower(alpha);
auto someString = convertUTF16CharToString(lowerCase);
std::string EnglishUtil::getAlphabetSoundFileName(wchar_t alpha)
{
auto lowerCase = tolower(alpha);
auto someString = convertUTF16CharToString(lowerCase);
auto fileName = std::string("lang/eng/sounds/") + someString + audioExt;
return fileName;
return fileName;
}

std::string EnglishUtil::getPhoneticSoundFileName(wchar_t alpha) {
std::string EnglishUtil::getPhoneticSoundFileName(wchar_t alpha)
{
auto fileName = std::string("lang/eng/sounds/") + convertUTF16CharToString(tolower(alpha)) + audioExt;
return fileName;
}

std::string EnglishUtil::getAlphabetSoundFileNameForString(std::string alpha) {
std::string EnglishUtil::getAlphabetSoundFileNameForString(std::string alpha)
{
std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower);
auto fileName = std::string("lang/eng/sounds/") + alpha + audioExt;
return fileName;
}

std::string EnglishUtil::getPhoneticSoundFileNameForString(std::string alpha) {
std::string EnglishUtil::getPhoneticSoundFileNameForString(std::string alpha)
{
std::transform(alpha.begin(), alpha.end(), alpha.begin(), ::tolower);
auto fileName = std::string("lang/eng/audio/phonetic/") + alpha + pronounciationAudioExt;
return fileName;
}

bool EnglishUtil::isGraphemeStart(uint32_t prevCodePoint, uint32_t currentCodePoint) {
bool EnglishUtil::isGraphemeStart(uint32_t prevCodePoint, uint32_t currentCodePoint)
{
return true;
}


std::string EnglishUtil::getPronounciationFileNameForWord(std::string word) {
std::string EnglishUtil::getPronounciationFileNameForWord(std::string word)
{
std::replace(word.begin(), word.end(), ' ', '_');
std::transform(word.begin(), word.end(), word.begin(), ::tolower);

char ch = word.back();
if(ch == '.')
if (ch == '.')
{
word = word.substr(0, word.size()-1);
}
word = word.substr(0, word.size() - 1);
}

auto fileName = std::string("lang/eng/audio/words/") + word + pronounciationAudioExt;
return fileName;
}


bool EnglishUtil::isTextToSpeechSupported() {
bool EnglishUtil::isTextToSpeechSupported()
{
return true;
}

std::string EnglishUtil::getDir() {
std::string EnglishUtil::getDir()
{
return "lang/eng";
}

std::string EnglishUtil::getLang() {
std::string EnglishUtil::getLang()
{
return "eng";
}

EnglishUtil::EnglishUtil() {
EnglishUtil::EnglishUtil()
{
this->initializeWordManager();
Data moData = FileUtils::getInstance()->getDataFromFile("res/lang/eng/eng.mo");
Data moData = FileUtils::getInstance()->getDataFromFile("res/lang/eng/eng_" + localeCode + ".mo");
I18N::I18nUtils::getInstance()->removeAllMO();
I18N::I18nUtils::getInstance()->addMO(moData.getBytes());
}

EnglishUtil::~EnglishUtil() {
EnglishUtil::~EnglishUtil()
{
}


void EnglishUtil::initializeWordManager() {
void EnglishUtil::initializeWordManager()
{
this->wordManager = WordManager::getInstance();
}
2 changes: 1 addition & 1 deletion goa/Classes/menu/LevelHelpScene.cpp
Expand Up @@ -84,7 +84,7 @@ bool LevelHelpScene::initWithGame(std::string gameName)
gameName = "story-catalogue";
}

std::string contents = FileUtils::getInstance()->getStringFromFile("config/game_levels.json");
std::string contents = FileUtils::getInstance()->getStringFromFile("config/game_levels_" + localeCode + ".json");

rapidjson::Document d;

Expand Down
22 changes: 11 additions & 11 deletions goa/Classes/menu/LevelHelpScene.h
Expand Up @@ -12,22 +12,23 @@
#include "cocos2d.h"
#include "ui/CocosGUI.h"

class LevelHelpScene: public cocos2d::Node {
const static std::string localeCode = "hi"; // en/hi to set English/Hindi locale
class LevelHelpScene : public cocos2d::Node
{
public:
static cocos2d::Scene *createScene(std::string gameName);
static LevelHelpScene *create(std::string gameName);
cocos2d::ui::Button *_resumeButton;
cocos2d::ui::Button *_resumeButton;
cocos2d::ui::ListView *listviewScroll;
void onEnterTransitionDidFinish() override;
void onExitTransitionDidStart() override;
void ResumeButtonAction(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType eEventType);
CC_CONSTRUCTOR_ACCESS:
LevelHelpScene();
void ResumeButtonAction(cocos2d::Ref *pSender, cocos2d::ui::Widget::TouchEventType eEventType);
CC_CONSTRUCTOR_ACCESS : LevelHelpScene();
virtual ~LevelHelpScene();
virtual bool init() override;
bool initWithGame(std::string gameName);
std::vector<std::string> split(std::string s, char delim);

protected:
int _currentLevel;
std::string _gameName;
Expand All @@ -36,17 +37,16 @@ class LevelHelpScene: public cocos2d::Node {
std::vector<std::string> _videos;
std::vector<std::string> _videoNames;
int _currentVideo;
virtual void gotoGame(Ref* pSender, cocos2d::ui::Widget::TouchEventType eEventType);
virtual void gotoGame(Ref *pSender, cocos2d::ui::Widget::TouchEventType eEventType);
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID || CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
cocos2d::experimental::ui::VideoPlayer* _vp;
void videoEventCallback(Ref* sender, cocos2d::experimental::ui::VideoPlayer::EventType eventType);
cocos2d::experimental::ui::VideoPlayer *_vp;
void videoEventCallback(Ref *sender, cocos2d::experimental::ui::VideoPlayer::EventType eventType);

#endif
void playNextVideo(float dt);
virtual void decideIndexOfVideo();
void videoPlayStart();
void videoPlayOverCallback();

};

#endif /* LevelHelpScene_h */
76 changes: 59 additions & 17 deletions goa/Classes/menu/MainMenuHome.cpp
Expand Up @@ -10,6 +10,7 @@
#include "MapScene.h"
#include "../misc/ScaleGuiElements.cpp"
#include "misc/FirebaseHelper.hpp"
#include "LevelHelpScene.h"

USING_NS_CC;

Expand Down Expand Up @@ -79,7 +80,7 @@ bool MainMenuHome::init()
// }

cocos2d::ui::Button *backButton = createBackButton();
ScaleUIElement<cocos2d::ui::Button*>::scaleGuiElements(backButton);
ScaleUIElement<cocos2d::ui::Button *>::scaleGuiElements(backButton);

backButton->setPosition(Vec2(origin.x + 150, origin.y + visibleSize.height - 150));
this->addChild(backButton);
Expand Down Expand Up @@ -175,11 +176,11 @@ void MainMenuHome::bindEvents(cocos2d::Node *rootNode)

if (button->getName() == "alphabet" || button->getName() == "writing" || button->getName() == "grammar")
{
button->setPosition(Vec2 (buttonPosition.x, buttonPosition.y - 40));
button->setPosition(Vec2(buttonPosition.x, buttonPosition.y - 40));
}
else if (button->getName() == "map" || button->getName() == "library" || button->getName() == "shapes")
{
button->setPosition(Vec2 (buttonPosition.x, buttonPosition.y - 70));
button->setPosition(Vec2(buttonPosition.x, buttonPosition.y - 70));
}

if (button->getName() == "library")
Expand All @@ -203,21 +204,42 @@ void MainMenuHome::bindEvents(cocos2d::Node *rootNode)

if (textTitle)
{
std::string translatedString = this->currentLangUtil->translateString(textTitle->getName());
std::string translatedString;
std::string fileName = "config/main_menu_title.json";
bool isBilingual = localeCode != "en";
string gameName = textTitle->getName().c_str();
string mainMenuEnglishText = "";
int engLabelOffset = isBilingual ? 0 : 50; // to remove the extra space between image and text
if (gameName == "alphabet")
mainMenuEnglishText = "Alphabet";
{
mainMenuEnglishText = readTitleFromJson(fileName, 0, false);
translatedString = readTitleFromJson(fileName, 0, isBilingual);
}
else if (gameName == "shapes")
mainMenuEnglishText = "Numbers";
{
mainMenuEnglishText = readTitleFromJson(fileName, 1, false);
translatedString = readTitleFromJson(fileName, 1, isBilingual);
}
else if (gameName == "writing")
mainMenuEnglishText = "Writing";
{
mainMenuEnglishText = readTitleFromJson(fileName, 2, false);
translatedString = readTitleFromJson(fileName, 2, isBilingual);
}
else if (gameName == "library")
mainMenuEnglishText = "Library";
{
mainMenuEnglishText = readTitleFromJson(fileName, 3, false);
translatedString = readTitleFromJson(fileName, 3, isBilingual);
}
else if (gameName == "grammar")
mainMenuEnglishText = "Grammar";
{
mainMenuEnglishText = readTitleFromJson(fileName, 4, false);
translatedString = readTitleFromJson(fileName, 4, isBilingual);
}
else if (gameName == "map")
mainMenuEnglishText = "Map";
{
mainMenuEnglishText = readTitleFromJson(fileName, 5, false);
translatedString = readTitleFromJson(fileName, 5, isBilingual);
}

textTitle->setText(mainMenuEnglishText);
textTitle->setTextHorizontalAlignment(TextHAlignment::CENTER);
Expand All @@ -232,24 +254,44 @@ void MainMenuHome::bindEvents(cocos2d::Node *rootNode)

if (gameName == "alphabet" || gameName == "writing" || gameName == "grammar")
{
textTitle->setPosition(Vec2 (englishTextPosition.x, englishTextPosition.y + 130));
textTitle->setPosition(Vec2(englishTextPosition.x, englishTextPosition.y + 130 - engLabelOffset));
}
else if (gameName == "map" || gameName == "library" || gameName == "shapes")
{
textTitle->setPosition(Vec2 (englishTextPosition.x, englishTextPosition.y + 100));
textTitle->setPosition(Vec2(englishTextPosition.x, englishTextPosition.y + 100 - engLabelOffset));
}


Label *mainMenuHindiText = Label::createWithSystemFont(translatedString, "arial", 70);
mainMenuHindiText->setPosition(Vec2(textTitle->getPositionX(), textTitle->getPositionY() - 90));
mainMenuHindiText->setColor(Color3B::WHITE);
this->addChild(mainMenuHindiText);
if (isBilingual)
{
Label *mainMenuLocaleText = Label::createWithSystemFont(translatedString, "arial", 70);
mainMenuLocaleText->setPosition(Vec2(textTitle->getPositionX(), textTitle->getPositionY() - 90));
mainMenuLocaleText->setColor(Color3B::WHITE);
this->addChild(mainMenuLocaleText);
}
}
}
}
}
}

std::string MainMenuHome::readTitleFromJson(std::string fileName, int pos, bool isBilingual)
{
std::string contents = FileUtils::getInstance()->getStringFromFile(fileName);
rapidjson::Document mapPlaces;
if (!mapPlaces.Parse<0>(contents.c_str()).HasParseError()) // to validate the structure of JSON file
{
if (isBilingual)
{
const rapidjson::Value &placeNameLoc = mapPlaces[localeCode.c_str()]; // get the list of locale specific strings
assert(placeNameLoc.IsArray());
return placeNameLoc[pos].GetString();
}
const rapidjson::Value &placeNameEng = mapPlaces["en"];
assert(placeNameEng.IsArray());
return placeNameEng[pos].GetString();
}
}

void MainMenuHome::mainMenuSelected(Ref *pSender, ui::Widget::TouchEventType eEventType)
{
cocos2d::ui::Button *clickedButton = dynamic_cast<cocos2d::ui::Button *>(pSender);
Expand Down

0 comments on commit 98c8e60

Please sign in to comment.