2009-05-08 13:28:41 +00:00
|
|
|
/*
|
|
|
|
* OpenClonk, http://www.openclonk.org
|
|
|
|
*
|
2009-06-05 13:41:20 +00:00
|
|
|
* Copyright (c) 2005 Sven Eberhardt
|
2010-12-23 00:01:24 +00:00
|
|
|
* 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"
|
|
|
|
|
2009-11-12 15:57:37 +00:00
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2009-11-25 15:04:32 +00:00
|
|
|
#include <stdexcept>
|
2009-11-12 15:57:37 +00:00
|
|
|
|
2009-05-08 13:28:41 +00:00
|
|
|
class C4LangStringTable : public C4ComponentHost
|
2009-11-12 15:57:37 +00:00
|
|
|
{
|
|
|
|
// 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:
|
2009-11-12 15:57:37 +00:00
|
|
|
NoSuchTranslation(const std::string &text) : std::runtime_error("No such translation: \"" + text + "\"") {}
|
2009-05-08 13:28:41 +00:00
|
|
|
};
|
2010-09-04 20:41:59 +00:00
|
|
|
protected:
|
|
|
|
virtual void OnLoad() { strings.clear(); } // Make sure we re-populate when the string table is reloaded
|
2009-11-12 15:57:37 +00:00
|
|
|
};
|
2009-05-08 13:28:41 +00:00
|
|
|
|
|
|
|
#endif // INC_C4LangStringTable
|