openclonk/src/c4group/C4LangStringTable.h

55 lines
1.8 KiB
C
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2005 Sven Eberhardt
* Copyright (c) 2009 Nicolas Hake
2009-05-08 13:28:41 +00:00
* Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de
*
* Portions might be copyrighted by other authors who have contributed
* to OpenClonk.
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
* See isc_license.txt for full license and disclaimer.
*
* "Clonk" is a registered trademark of Matthes Bender.
* See clonk_trademark_license.txt for full license.
*/
// Loads StringTbl* and replaces $..$-strings by localized versions
#ifndef INC_C4LangStringTable
#define INC_C4LangStringTable
#include "C4ComponentHost.h"
#include <map>
#include <string>
#include <stdexcept>
2009-05-08 13:28:41 +00:00
class C4LangStringTable : public C4ComponentHost
{
// Contains the localization string->string mapping. Populated lazily from PopulateStringTable, thus mutable.
typedef std::map<std::string, std::string> Table;
mutable Table strings;
void PopulateStringTable() const;
public:
C4LangStringTable();
std::string Translate(const std::string &text) const;
bool HasTranslation(const std::string &text) const;
// do replacement in buffer
// if any replacement is done, the buffer will be realloced
void ReplaceStrings(StdStrBuf &rBuf);
void ReplaceStrings(const StdStrBuf &rBuf, StdStrBuf &rTarget, const char *szParentFilePath = NULL);
class NoSuchTranslation : public std::runtime_error
2009-05-08 13:28:41 +00:00
{
public:
NoSuchTranslation(const std::string &text) : std::runtime_error("No such translation: \"" + text + "\"") {}
2009-05-08 13:28:41 +00:00
};
protected:
virtual void OnLoad() { strings.clear(); } // Make sure we re-populate when the string table is reloaded
};
2009-05-08 13:28:41 +00:00
#endif // INC_C4LangStringTable