File: pingus-po-extract.cpp

package info (click to toggle)
pingus 0.7.6-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,672 kB
  • sloc: cpp: 42,080; xml: 2,319; lisp: 521; ruby: 455; ansic: 365; objc: 248; sh: 247; makefile: 140; python: 15
file content (63 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>

#include "pingus/pingus_level.hpp"
#include "util/pathname.hpp"
#include "util/raise_exception.hpp"

void
emit_msgid(const std::string& str)
{
  std::cout
    << "#: " << "filename" << ":" << "lineno\n"
    << "msgid \"" << str << "\"\n"
    << "msgstr \"\"\n" << std::endl;
}

int main(int argc, char** argv)
{
  std::vector<Pathname> files;

  for(int i = 1; i < argc; ++i)
  {
    Pathname filename(argv[i], Pathname::SYSTEM_PATH);
    if (filename.has_extension(".pingus"))
    {
      PingusLevel plf(filename);

      emit_msgid(plf.get_levelname());
      emit_msgid(plf.get_description());
    }
    else if (filename.has_extension(".worldmap"))
    {
      // worldmaps don't contain translatable strings at the moment
    }
    else if (filename.has_extension(".story"))
    {
      FileReader reader = FileReader::parse(filename);
      std::string tmp;
      if (reader.read_string("title", tmp))
      {
        emit_msgid(tmp);
      }

      FileReader all_pages = reader.read_section("pages");
      const auto& childs = all_pages.get_sections();
      for(auto it = childs.begin(); it != childs.end(); ++it)
      {
        if (it->read_string("text", tmp))
        {
          emit_msgid(tmp);
        }
      }
    }
    else
    {
      raise_exception(std::runtime_error, "unknown file type: " << filename);
    }
  }

  return 0;
}

/* EOF */