MofileReader
|
This class is a gettext-replacement. More...
#include <moFileReader.hpp>
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 | |
moFileReader::eErrorCode | ParseData (const std::string &data) |
Reads a .mo-file. More... | |
eErrorCode | ReadFile (const char *filename) |
Reads a .mo-file. More... | |
template<typename T > | |
eErrorCode | ReadStream (T &stream) |
Reads data from a stream. More... | |
std::string | Lookup (const char *id) const |
Returns the searched translation or returns the input. More... | |
std::string | LookupWithContext (const char *context, const char *id) const |
Returns the searched translation or returns the input, restricted to the context given by context. See https://www.gnu.org/software/gettext/manual/html_node/Contexts.html for more info. More... | |
const std::string & | GetErrorDescription () const |
Returns the Error Description. More... | |
void | ClearTable () |
Empties the Lookup-Table. More... | |
unsigned int | GetNumStrings () const |
Returns the Number of Entries in our Lookup-Table. More... | |
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. More... | |
Static Public Attributes | |
static const unsigned int | MagicNumber = 0x950412DE |
The Magic Number describes the endianess of bytes on the system. More... | |
static const unsigned int | MagicReversed = 0xDE120495 |
If the Magic Number is Reversed, we need to swap the bytes. More... | |
static const char | ContextSeparator = '\x04' |
The character that is used to separate context strings. More... | |
Protected Types | |
typedef std::map< std::string, std::string > | moLookupList |
Type for the map which holds the translation-pairs later. More... | |
typedef std::map< std::string, moLookupList > | moContextLookupList |
Type for the 2D map which holds the translation-pairs later. More... | |
Protected Member Functions | |
unsigned long | SwapBytes (unsigned long in) |
Swap the endianness of a 4 byte WORD. More... | |
Protected Attributes | |
std::string | m_error |
Keeps the last error as String. More... | |
This class is a gettext-replacement.
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.
Definition at line 294 of file moFileReader.hpp.
|
protected |
Type for the 2D map which holds the translation-pairs later.
Definition at line 301 of file moFileReader.hpp.
|
protected |
Type for the map which holds the translation-pairs later.
Definition at line 298 of file moFileReader.hpp.
The possible errorcodes for methods of this class.
Enumerator | |
---|---|
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.
|
Definition at line 314 of file moFileReader.hpp.
|
inline |
Empties the Lookup-Table.
Definition at line 563 of file moFileReader.hpp.
|
inlinestatic |
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 ;). |
Definition at line 586 of file moFileReader.hpp.
|
inline |
Returns the Error Description.
Definition at line 557 of file moFileReader.hpp.
|
inline |
Returns the Number of Entries in our Lookup-Table.
Definition at line 574 of file moFileReader.hpp.
|
inline |
Returns the searched translation or returns the input.
[in] | id | The id of the translation to search for. |
Definition at line 531 of file moFileReader.hpp.
|
inline |
Returns the searched translation or returns the input, restricted to the context given by context. See https://www.gnu.org/software/gettext/manual/html_node/Contexts.html for more info.
[in] | context | Restrict to the context given. |
[in] | id | The id of the translation to search for. |
Definition at line 545 of file moFileReader.hpp.
|
inline |
Reads a .mo-file.
[in] | _filename | The path to the file to load. |
This is the core-feature. This method loads the .mo-file and stores all translation-pairs in a map. You can access this map via the method moFileReader::Lookup().
Definition at line 349 of file moFileReader.hpp.
|
inline |
Reads a .mo-file.
[in] | _filename | The path to the file to load. |
This is the core-feature. This method loads the .mo-file and stores all translation-pairs in a map. You can access this map via the method moFileReader::Lookup().
Definition at line 365 of file moFileReader.hpp.
|
inline |
Reads data from a stream.
[in] | stream |
Definition at line 386 of file moFileReader.hpp.
|
inlineprotected |
Swap the endianness of a 4 byte WORD.
[in] | in | The value to swap. |
Definition at line 687 of file moFileReader.hpp.
|
static |
The character that is used to separate context strings.
Definition at line 311 of file moFileReader.hpp.
|
protected |
Keeps the last error as String.
Definition at line 681 of file moFileReader.hpp.
|
static |
The Magic Number describes the endianess of bytes on the system.
Definition at line 305 of file moFileReader.hpp.
|
static |
If the Magic Number is Reversed, we need to swap the bytes.
Definition at line 308 of file moFileReader.hpp.