user3763991
user3763991

Reputation: 1

C++ reading from .lang files with locales

I am creating an OpenGL game and I would like to make it open to more languages than just English for obvious reasons. From looking around and fiddling around with the games installed on my computer I can see that locales play a big part in this and that .lang files, such as en-US.lang that is shipped with minecraft, are basically text documents with a language code, "item.iron.ingot" for example, an equal sign, and then what it means for that given language, English as per en-US, so in this case would be, "Iron Ingot". Well I created a file that I named en-US.lang and this is its contents:

item.iron.ingot=Iron Ingot

In my C++ main method I put:

setlocale(LC_ALL, "en-US");

After including the locale header file. So I suppose the part that I am confused by is how to use the locales to read from the .lang file? Please help SO and some example code would be appreciated.

Upvotes: 0

Views: 293

Answers (1)

odedsh
odedsh

Reputation: 2624

C++ Does not come with a built-in support for resource files / internationalization. However there is a huge variety of solutions.

To support multi-language messages, you should have some basic understanding of how such strings are encoded in files and read to memory. Here is a basic introduction if you are not familiar: "http://www.joelonsoftware.com/articles/Unicode.html"

To keep and load the correct text at runtime you need to use a third party library: GNU gettext http://www.gnu.org/software/gettext/ is one such example. However there are other solutions out there.

Upvotes: 1

Related Questions