void StTranslations::setLanguage(const int32_t theNewLang) { if(size_t(theNewLang) >= params.language->getValues().size()) { return; } // save global setting const StString& aFolderName = myLangFolderList[theNewLang]; StSettings aGlobalSettings(myResMgr, ST_GLOBAL_SETTINGS_GROUP); aGlobalSettings.saveString(ST_SETTING_LANGUAGE, aFolderName); updateLangCode(theNewLang); // reload translation file StLangMap::clear(); const StString aResName = StString() + "lang" ST_FILE_SPLITTER + aFolderName + SYS_FS_SPLITTER + myModuleName + StTranslations::DEFAULT_SUFFIX; StHandle<StResource> aRes = myResMgr->getResource(aResName); if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const int aLen = aRes->getSize(); read(aSrc, aLen); } myWasReloaded = true; }
/** * Copy OCCT resource file. */ ST_LOCAL bool copyResource(const StHandle<StResourceManager>& theResMgr, const StString& theResFolder, const StString& theDestFolder, const StString& theFileName) { StString aFileResPath = theResFolder + SYS_FS_SPLITTER + theFileName; StHandle<StResource> aRes = theResMgr->getResource(aFileResPath); if( aRes.isNull() || !aRes->read()) { ST_ERROR_LOG(StString("Can not read resource file ") + aFileResPath); return false; } StRawFile aFileOut; StString aFileOutPath = theDestFolder + SYS_FS_SPLITTER + theFileName; if(!aFileOut.openFile(StRawFile::WRITE, aFileOutPath)) { ST_ERROR_LOG(StString("Can not create resource file ") + aFileOutPath); return false; } if(!aFileOut.write((const char* )aRes->getData(), aRes->getSize()) != aRes->getSize()) { ST_ERROR_LOG(StString("Can not write resource file ") + aFileOutPath); return false; } return true; }
void StTranslations::reload() { params.language->changeValues().clear(); // detect available translations StArrayList<StString> aFolders; myResMgr->listSubFolders("lang", aFolders); for(size_t aNodeId = 0; aNodeId < aFolders.size(); ++aNodeId) { myLangFolderList.add(aFolders[aNodeId]); const StString aNameFile = StString("lang" ST_FILE_SPLITTER) + aFolders[aNodeId] + ST_FILE_SPLITTER "language.lng"; StHandle<StResource> aRes = myResMgr->getResource(aNameFile); StString aName; if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const size_t aLen = (size_t )aRes->getSize(); aName = StString(aSrc, aLen); } params.language->changeValues().add(aName.isEmpty() ? aFolders[aNodeId] : aName); } #if defined(__ANDROID__) if(params.language->getValues().isEmpty()) { // no way to list sub-folder on Android - check known translations if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "English" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("English"); myLangFolderList.add("English"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Russian" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("русский"); myLangFolderList.add("Russian"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "French" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("français"); myLangFolderList.add("French"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "German" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("Deutsch"); myLangFolderList.add("German"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Korean" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("한국어"); myLangFolderList.add("Korean"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "ChineseS" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("简体中文"); myLangFolderList.add("ChineseS"); } if(myResMgr->isResourceExist(StString("lang" ST_FILE_SPLITTER "Czech" ST_FILE_SPLITTER) + myModuleName + StTranslations::DEFAULT_SUFFIX)) { params.language->changeValues().add("Čeština"); myLangFolderList.add("Czech"); } } #endif if(params.language->getValues().isEmpty()) { // add built-in language params.language->changeValues().add("English"); myLangFolderList.add("English"); } size_t anIdInList = 0; StString aLangParam("English"); StSettings aGlobalSettings(myResMgr, ST_GLOBAL_SETTINGS_GROUP); bool isLangSet = false; if(!aGlobalSettings.loadString(ST_SETTING_LANGUAGE, aLangParam)) { // try to use system-wide language settings const StString& aLang = myResMgr->getSystemLanguage(); if(aLang.isEqualsIgnoreCase(stCString("ru"))) { if(myLangFolderList.contains(stCString("Russian"), anIdInList) || myLangFolderList.contains(stCString("русский"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("de"))) { if(myLangFolderList.contains(stCString("German"), anIdInList) || myLangFolderList.contains(stCString("Deutsch"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("fr"))) { if(myLangFolderList.contains(stCString("French"), anIdInList) || myLangFolderList.contains(stCString("français"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("ko"))) { if(myLangFolderList.contains(stCString("Korean"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("zh"))) { if(myLangFolderList.contains(stCString("ChineseS"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } else if(aLang.isEqualsIgnoreCase(stCString("cs"))) { if(myLangFolderList.contains(stCString("Čeština"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); isLangSet = true; } } } if(!isLangSet) { if(myLangFolderList.contains(aLangParam, anIdInList) || myLangFolderList.contains(stCString("English"), anIdInList)) { params.language->setValue(int32_t(anIdInList)); } } updateLangCode(int32_t(anIdInList)); const StString& aFolderName = myLangFolderList[anIdInList]; const StString aResName = StString() + "lang" + SYS_FS_SPLITTER + aFolderName + SYS_FS_SPLITTER + myModuleName + StTranslations::DEFAULT_SUFFIX; StHandle<StResource> aRes = myResMgr->getResource(aResName); if(!aRes.isNull() && aRes->read()) { const char* aSrc = (const char* )aRes->getData(); const int aLen = aRes->getSize(); read(aSrc, aLen); } // connect signal params.language->signals.onChanged.connect(this, &StTranslations::setLanguage); }
bool StOutIZ3D::create() { StWindow::show(); if(!StWindow::create()) { return false; } // initialize GL context myContext = StWindow::getContext(); myContext->setMessagesQueue(myMsgQueue); const StHandle<StResourceManager>& aResMgr = getResourceManager(); if(!myContext->isGlGreaterEqual(2, 0)) { myMsgQueue->pushError(stCString("OpenGL 2.0 is required by iZ3D Output")); myIsBroken = true; return true; } StWindow::stglMakeCurrent(ST_WIN_MASTER); myContext->stglSetVSync((StGLContext::VSync_Mode )StWindow::params.VSyncMode->getValue()); StWindow::params.VSyncMode->signals.onChanged += stSlot(this, &StOutIZ3D::doSwitchVSync); // INIT iZ3D tables textures StAVImage aTableImg; StHandle<StResource> aTableOld = aResMgr->getResource(StString("textures") + SYS_FS_SPLITTER + "iz3dTableOld.png"); uint8_t* aData = NULL; int aDataSize = 0; if(!aTableOld.isNull() && !aTableOld->isFile() && aTableOld->read()) { aData = (uint8_t* )aTableOld->getData(); aDataSize = aTableOld->getSize(); } if(!aTableImg.load(!aTableOld.isNull() ? aTableOld->getPath() : StString(), StImageFile::ST_TYPE_PNG, aData, aDataSize)) { myMsgQueue->pushError(StString("iZ3D output - critical error:\n") + aTableImg.getState()); myIsBroken = true; return true; } myTexTableOld.setMinMagFilter(*myContext, GL_NEAREST); // we need not linear filtrating for lookup-table! if(!myTexTableOld.init(*myContext, aTableImg.getPlane())) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nLookup-table initalization failed!")); myIsBroken = true; return true; } StHandle<StResource> aTableNew = aResMgr->getResource(StString("textures") + SYS_FS_SPLITTER + "iz3dTableNew.png"); aData = NULL; aDataSize = 0; if(!aTableNew.isNull() && !aTableNew->isFile() && aTableNew->read()) { aData = (uint8_t* )aTableNew->getData(); aDataSize = aTableNew->getSize(); } if(!aTableImg.load(!aTableNew.isNull() ? aTableNew->getPath() : StString(), StImageFile::ST_TYPE_PNG, aData, aDataSize)) { myMsgQueue->pushError(StString("iZ3D output - critical error:\n") + aTableImg.getState()); myIsBroken = true; return true; } myTexTableNew.setMinMagFilter(*myContext, GL_NEAREST); // we need not linear filtrating for lookup-table! if(!myTexTableNew.init(*myContext, aTableImg.getPlane())) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nLookup-table initalization failed!")); myIsBroken = true; return true; } // INIT shaders if(!myShaders.init(*myContext)) { myMsgQueue->pushError(stCString("iZ3D output - critical error:\nShaders initialization failed!")); myIsBroken = true; return true; } myIsBroken = false; return true; }