Sharing a single boost C++ locale object between multiple processes

73 Views Asked by At

Currently working on a project to add i18n language translation.

The issue is that each time a process is launched, it loads a 13 MB translation file called MOfiles\de_DE\LC_MESSAGES\msg.mo (.mo extension) and takes approximately 1 second to complete. Every new process suffers this same delay and it degrades the users overall experience.

Question: Is it possible to create a single translation object in shared memory, so that any new processes could reference that existing object and avoid the delay?

After some brief research, I found a Boost C++ example which creates a vector in shared memory.
Could it be adapted for a boost locale object too?

The single process translation file is currently loaded as follows

void STDCALL SetGlobalLocale(const char* domain, const char* locale, const char* path, const char* charset)
{
    std::string encoding(charset);
    encoding.insert(0,".");
    std::string language = locale ? (locale + encoding) : "";

    boost::locale::generator gen;

    gen.add_messages_path(path);
    gen.add_messages_domain(domain);

    // Sets a single global locale for the entire process.
    std::locale loc = gen(language);  // SLOW!!! Takes 1 second to load. ಠ_ಠ
    std::locale::global(loc);

    gen.clear_paths();
    gen.clear_domains();
}

and called using

SetGlobalLocale("msg", "de_DE", "../../../../MOfiles", "CP1252");
0

There are 0 best solutions below