2

I've got a C++ Plug-in project that needs to be translatable. As such I've created a Dictionary class that can be used to access the strings. However, I'm not entirely sure what the best way of storing the strings is. I was thinking of creating an XML file and storing all the strings there with their different locales stored under one variable name, e.g.

<sHello>
  <en_GB>Hello</en_GB>
  <fr_FR>Bonjour</fr_FR>
  ...
</sHello>

However, I would prefer not to have to distribute the XML file along with the other distributables. The Plug-in needs to be cross platform so I'm developing the Windows version in Visual Studio and the Mac OS version in XCode. Preferably, the C++ code in my Dictionary class for accessing the XML values would be the same on both platforms, meaning I could just included the XML in the respective projects and not have to worry about maintaining 2 separate code bases.

Is it possible to embed the XML file as a compiled resource in such a way that it doesn't need to be distributed?

Dave Stott
  • 33
  • 5
  • Is this XML containing config like information compiled for each environment? Why XML over JSON? You will probably need to bring in a 3rd party library for parsing XML or JSON or either write one yourself. – Daniel Gale Feb 28 '18 at 15:36
  • This may give you some ideas: [How to load a custom binary resource in a VC++ static library as part of a dll?](https://stackoverflow.com/q/9240188/6610379) Don't be thrown off by this being noted as procedure for "binary resource" - you can adapt for your XML text as well. – Phil Brubaker Feb 28 '18 at 15:52
  • @PhilBrubaker he want's it to be platform independent. Otherwise for a Windows only app I'd go the way you suggested. – Jabberwocky Feb 28 '18 at 16:18
  • @MichaelWalz Ah thanks, skimmed too fast. :-) I like your answer then. – Phil Brubaker Feb 28 '18 at 16:30

1 Answers1

1

What's wrong with distributing the xml file?

If you really don't want to distribute the XML file, you could make a small utility program that converts the xml file to a C++ source file that would look e.g like this:

// autogenerated by <put your fancy name here>
// Don't hand edit this source file

const char xmlfile[] = "<sHello>\
  <en_GB>Hello</en_GB>\
  <fr_FR>Bonjour</fr_FR>\
  ...\
</sHello>";

Instead of XML you could use any other suitable format such as json or whatever you think fits best for your needs.

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
  • I'm just trying to make distribution easier for myself I guess. But I think creating a utility program is probably my best bet actually, sometimes the simplest solutions are the best. Cheers! – Dave Stott Mar 01 '18 at 09:15