25 #include <unordered_map>
29 #include "eng3d/string.hpp"
39 if(this->
id ==
static_cast<size_t>(-1))
return "";
57 static std::unordered_map<std::string, std::string> trans_msg;
58 static std::mutex trans_lock;
60 std::unique_ptr<FILE, decltype(&fclose)> fp(fopen(filename.c_str(),
"rt"), fclose);
62 while(fgets(tmp,
sizeof tmp, fp.get()) !=
nullptr) {
63 if(!strncmp(tmp,
"msgid", 5)) {
65 sscanf(tmp + 5,
" %*c%[^\"]s%*c ", msgid);
66 fgets(tmp,
sizeof tmp, fp.get());
67 if(!strncmp(tmp,
"msgstr", 6)) {
69 sscanf(tmp + 6,
" %*c%[^\"]s%*c ", msgstr);
70 trans_msg[msgid] = msgstr;
77 std::scoped_lock lock(trans_lock);
78 if(trans_msg[str.data()].empty())
79 return std::string(str);
80 return trans_msg[str.data()];
The string pool manager (singleton), used mainly for translation purpouses. But also helps to reduce ...
const std::string_view get_by_id(const Eng3D::StringRef ref) const
static StringManager & get_instance()
StringManager(Eng3D::State &_s)
Eng3D::StringRef insert(const std::string &str)
void from_file(const std::string &filename)
std::string translate(const std::string_view str)
constexpr StringRef()=default
const std::string_view get_string() const