Add fallback to English.json
This commit is contained in:
parent
3b9f4d0541
commit
7dc0e2b859
@ -208,7 +208,7 @@ void CheatMenu::Init()
|
||||
m_fMenuSize.y = gConfig.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f);
|
||||
srand(CTimer::m_snTimeInMilliseconds);
|
||||
|
||||
Locale::Init("CheatMenu/locale/");
|
||||
Locale::Init("CheatMenu/locale/", "English", "English");
|
||||
|
||||
CheatMenu::GenHeaderList();
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#include "locale.h"
|
||||
#include <filesystem>
|
||||
|
||||
Locale::eReturnCodes Locale::Init(const char* path, const char* def)
|
||||
Locale::eReturnCodes Locale::Init(const char* path, const char* def, const char* callback)
|
||||
{
|
||||
std::string localePath = path;
|
||||
if (localePath.back() != '/')
|
||||
@ -36,10 +36,23 @@ Locale::eReturnCodes Locale::Init(const char* path, const char* def)
|
||||
{
|
||||
if (entry.path().extension() == ".json")
|
||||
{
|
||||
std::string fileName = entry.path().stem().string();
|
||||
#ifdef _GTA_
|
||||
gLog << "Found locale: " << entry.path().stem().string() << std::endl;
|
||||
gLog << "Found locale: " << fileName << std::endl;
|
||||
#endif
|
||||
m_locales.push_back(entry.path().stem().string());
|
||||
m_locales.push_back(fileName);
|
||||
|
||||
if (!strcmp(callback, fileName.c_str()))
|
||||
{
|
||||
std::string localePath = m_path + fileName + ".json";
|
||||
|
||||
if(m_pCallbackJson)
|
||||
{
|
||||
delete m_pCallbackJson;
|
||||
m_pCallbackJson = nullptr;
|
||||
}
|
||||
m_pCallbackJson = new CJson(localePath.c_str(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
12
src/locale.h
12
src/locale.h
@ -14,6 +14,7 @@ private:
|
||||
static inline std::vector<std::string> m_locales;
|
||||
static inline std::string m_path;
|
||||
static inline CJson *m_pJson = nullptr;
|
||||
static inline CJson *m_pCallbackJson = nullptr;
|
||||
static inline size_t localeIndex;
|
||||
|
||||
public:
|
||||
@ -35,7 +36,7 @@ public:
|
||||
Loads json files from the locale directory
|
||||
Calling it multiple times will unload previous data
|
||||
*/
|
||||
static eReturnCodes Init(const char* path, const char* def = "English");
|
||||
static eReturnCodes Init(const char* path, const char* def = "English", const char* callback = "");
|
||||
|
||||
// Returns a vector of available languages
|
||||
static std::vector<std::string>& GetLocaleList();
|
||||
@ -60,7 +61,14 @@ public:
|
||||
// But VS Code complains about it so..
|
||||
defaultValue += "##" + key;
|
||||
#endif
|
||||
return m_pJson->GetValueStr(key, defaultValue);
|
||||
std::string rtn = m_pJson->GetValueStr(key, defaultValue);
|
||||
|
||||
if (rtn == defaultValue)
|
||||
{
|
||||
return m_pCallbackJson->GetValueStr(key, defaultValue);
|
||||
}
|
||||
|
||||
return rtn;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2,5 +2,5 @@
|
||||
#define MENU_NAME "Cheat Menu"
|
||||
#define MENU_VERSION_NUMBER "3.2"
|
||||
#define MENU_VERSION MENU_VERSION_NUMBER"-beta"
|
||||
#define BUILD_NUMBER "20220226"
|
||||
#define BUILD_NUMBER "20220304"
|
||||
#define MENU_TITLE MENU_NAME " v" MENU_VERSION
|
||||
|
Loading…
Reference in New Issue
Block a user