1

I have some localization going on in the PO format. Is it possible to get the contents of this file within your C++ application? Instead of calling gettext("id here") I want to read the complete file within C++ (on linux and windows)

Baklap4
  • 3,914
  • 2
  • 29
  • 56
  • It is possible but the PO file format is not that rigorously specified, (i.e. much less rigorous than the RFC that defined HTTP) which makes it a bit fiddly. Shameless plug, I made a C++11 header-only library that does this, which is available under boost license here: https://github.com/cbeck88/spirit-po – Chris Beck Jun 16 '16 at 23:15
  • 1
    You could also use a C library called `libgettext-po` if you want to fully parse all the kinds of things that the GNU tools like `msgfmt` uses. My lib only is targeting the final part that's in your application. – Chris Beck Jun 17 '16 at 00:58
  • @ChrisBeck how would one use those functions from the library? I'm getting errors while linking the executable: `undefined reference to 'po_file_read_v3'` I did include the file as following: `#include ` – Baklap4 Jun 17 '16 at 15:51
  • `libgettext-po` is a C library, did you put `extern "C"` around the includes? Did you put the compiled lib in your linker path? – Chris Beck Jun 18 '16 at 00:02

1 Answers1

1

Yes, definitely you can do this. PO file format is described in gettext's documentation: https://www.gnu.org/software/gettext/manual/gettext.html#PO-Files . You can use it to write your own parser for these files.

Gettext has also Windows version, you can use it if you are looking any gettext implementtaion for Windows: http://gnuwin32.sourceforge.net/packages/gettext.htm

Is there any other reason why you want to do this? Please give us more details.

Daniel Frużyński
  • 2,091
  • 19
  • 28