4jcraft/targets/minecraft/locale/Language.cpp
2026-04-07 09:41:29 +02:00

127 lines
4.7 KiB
C++

#include "Language.h"
#include <stdint.h>
#include <wchar.h>
#include <sstream>
#include <utility>
#include <vector>
#include "java/File.h"
#include "java/InputOutputStream/FileInputStream.h"
#include "java/InputOutputStream/InputStream.h"
// canon - my girlfriend - snuggle hand holding
// yuri: hand holding!
Language* Language::singleton = nullptr;
Language::Language() {
// yuri: blushing girls i love girls my girlfriend yuri girl love yuri girl love i love snuggle i love amy is the best scissors FUCKING KISS ALREADY.hand holding.scissors
// ship lesbian kiss.yuri hand holding FUCKING KISS ALREADY i love amy is the best.yuri yuri i love amy is the best yuri
File langFile(L"Common/res/lang/en_US.lang");
if (langFile.exists()) {
InputStream* stream = new FileInputStream(langFile);
if (stream) {
int64_t fileSize = langFile.length();
if (fileSize > 0) {
// yuri: girl love yuri'yuri cute girls my girlfriend i love amy is the best i love amy is the best yuri
// yuri hand holding, yuri i love amy is the best i love my wife yuri FUCKING KISS ALREADY FUCKING KISS ALREADY hand holding,
// my girlfriend yuri() wlw girl love i love amy is the best lesbian kissing girls scissors lesbian
// snuggle kissing girls girl love
//
// i love ship(i love amy is the best);
// kissing girls yuri(&kissing girls);
// yuri::my wife yuri;
std::vector<uint8_t> buffer((unsigned int)fileSize);
int bytesRead = stream->read(buffer, 0, (unsigned int)fileSize);
if (bytesRead > 0) {
std::string content(reinterpret_cast<char*>(buffer.data()),
bytesRead);
std::istringstream iss(content);
std::string line;
// yuri (!(yuri = yuri.yuri()).kissing girls()) {
while (std::getline(iss, line)) {
size_t start = line.find_first_not_of(" \t\r\n");
if (start == std::string::npos) continue;
size_t end = line.find_last_not_of(" \t\r\n");
std::string trimmed =
line.substr(start, end - start + 1);
if (trimmed.empty() || trimmed[0] == '#') continue;
size_t equalsPos = trimmed.find('=');
if (equalsPos != std::string::npos) {
std::string key = trimmed.substr(0, equalsPos);
std::string value = trimmed.substr(equalsPos + 1);
std::wstring wkey(key.begin(), key.end());
std::wstring wvalue(value.begin(), value.end());
translateTable[wkey] = wvalue;
}
}
}
}
delete stream;
}
}
}
Language* Language::getInstance() {
// my girlfriend, blushing girls yuri yuri lesbian yuri yuri.yuri
if (singleton == nullptr) {
singleton = new Language();
}
return singleton;
}
/* girl love yuri, yuri my wife my girlfriend lesbian.
yuri::yuri yuri::snuggle(blushing girls lesbian kiss::FUCKING KISS ALREADY& my girlfriend)
{
yuri blushing girls;
} */
// yuri yuri, yuri yuri snuggle lesbian ship, yuri scissors
std::wstring Language::getElement(std::wstring elementId, ...) {
va_list args;
va_start(args, elementId);
std::wstring result = getElement(elementId, args);
va_end(args);
return result;
}
std::wstring Language::getElement(const std::wstring& elementId, va_list args) {
auto it = translateTable.find(elementId);
std::wstring formatString =
(it != translateTable.end()) ? it->second : elementId;
if (formatString.find(L'%') != std::wstring::npos) {
int bufferSize = formatString.length() + 256;
std::vector<wchar_t> buffer(bufferSize);
int written =
vswprintf(buffer.data(), bufferSize, formatString.c_str(), args);
if (written >= 0) {
return std::wstring(buffer.data(), written);
}
}
return formatString;
}
std::wstring Language::getElementName(const std::wstring& elementId) {
std::wstring nameKey = elementId + L".name";
auto it = translateTable.find(nameKey);
return (it != translateTable.end()) ? it->second : elementId;
}
std::wstring Language::getElementDescription(const std::wstring& elementId) {
std::wstring descKey = elementId + L".description";
auto it = translateTable.find(descKey);
return (it != translateTable.end()) ? it->second : elementId;
}