#include <moFileReader.h>
Public Types | |
enum | eErrorCode { EC_SUCCESS = 0, EC_ERROR, EC_FILENOTFOUND, EC_FILEINVALID, EC_TABLEEMPTY, EC_MAGICNUMBER_NOMATCH, EC_MAGICNUMBER_REVERSED } |
The possible errorcodes for methods of this class. More... | |
Public Member Functions | |
virtual eErrorCode | ReadFile (const char *_filename) |
Reads a .mo-file. | |
virtual std::string | Lookup (const char *_id) const |
Returns the searched translation or returns the input. | |
virtual const std::string & | GetErrorDescription () const |
Returns the Error Description. | |
virtual void | ClearTable () |
Empties the Lookup-Table. | |
virtual unsigned int | GetNumStrings () const |
Returns the Number of Entries in our Lookup-Table. | |
Static Public Member Functions | |
static eErrorCode | ExportAsHTML (const std::string _infile, const std::string _filename="", const std::string _css=g_css) |
Exports the whole content of the .mo-File as .html. | |
Static Public Attributes | |
static const long | _MagicNumber = 0x950412DE |
The Magic Number describes the endianess of bytes on the system. | |
static const long | _MagicReversed = 0xDE120495 |
If the Magic Number is Reversed, we need to swap the bytes. | |
Protected Types | |
typedef std::map< std::string, std::string > | moLookupList |
Type for the map which holds the translation-pairs later. | |
Protected Member Functions | |
unsigned long | SwapBytes (unsigned long _in) |
Swap the endianness of a 4 byte WORD. | |
Protected Attributes | |
std::string | m_error |
Keeps the last error as String. |
The usage is quite simple:
Tell the class which .mo-file it shall load via moFileReader::ReadFile(). The method will attempt to load the file, all translations will be stored in memory. Afterwards you can lookup the strings with moFileReader::Lookup() just like you would do with gettext. Additionally, you can call moFileReader::ReadFile() for as much files as you like. But please be aware, that if there are duplicated keys (original strings), that they will replace each other in the lookup-table. There is no check done, if a key already exists.
I strongly recommend poEdit from Vaclav Slavik for editing .po-Files, get it at http://poedit.net for various systems :).
typedef std::map<std::string, std::string> moFileLib::moFileReader::moLookupList [protected] |
Type for the map which holds the translation-pairs later.
The possible errorcodes for methods of this class.
EC_SUCCESS | Indicated success. |
EC_ERROR | Indicates an error. |
EC_FILENOTFOUND | The given File was not found. |
EC_FILEINVALID | The file is invalid. |
EC_TABLEEMPTY | Empty Lookup-Table (returned by ExportAsHTML()). |
EC_MAGICNUMBER_NOMATCH | The magic number did not match. |
EC_MAGICNUMBER_REVERSED |
The magic number is reversed.
|
virtual void moFileLib::moFileReader::ClearTable | ( | ) | [virtual] |
Empties the Lookup-Table.
static eErrorCode moFileLib::moFileReader::ExportAsHTML | ( | const std::string | _infile, | |
const std::string | _filename = "" , |
|||
const std::string | _css = g_css | |||
) | [static] |
Exports the whole content of the .mo-File as .html.
[in] | _infile | The .mo-File to export. |
[in] | _filename | Where to store the .html-file. If empty, the path and filename of the _infile with .html appended. |
[in,out] | _css | The css-script for the visual style of the file, in case you don't like mine ;). |
virtual const std::string& moFileLib::moFileReader::GetErrorDescription | ( | ) | const [virtual] |
Returns the Error Description.
virtual unsigned int moFileLib::moFileReader::GetNumStrings | ( | ) | const [virtual] |
Returns the Number of Entries in our Lookup-Table.
virtual std::string moFileLib::moFileReader::Lookup | ( | const char * | _id | ) | const [virtual] |
Returns the searched translation or returns the input.
[in,out] | _id | The id of the translation to search for. |
virtual eErrorCode moFileLib::moFileReader::ReadFile | ( | const char * | _filename | ) | [virtual] |
Reads a .mo-file.
[in] | _filename | The path to the file to load. |
unsigned long moFileLib::moFileReader::SwapBytes | ( | unsigned long | _in | ) | [protected] |
Swap the endianness of a 4 byte WORD.
[in] | _in | The value to swap. |
const long moFileLib::moFileReader::_MagicNumber = 0x950412DE [static] |
The Magic Number describes the endianess of bytes on the system.
const long moFileLib::moFileReader::_MagicReversed = 0xDE120495 [static] |
If the Magic Number is Reversed, we need to swap the bytes.
std::string moFileLib::moFileReader::m_error [protected] |
Keeps the last error as String.