2009-04-18 19:00:33 +02:00
|
|
|
/* Copyright (C) 2009 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-08-21 13:45:01 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Stores sections of a translated string: constant strings, simple variables,
|
|
|
|
and JS function calls, allowing conversion to strings.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_I18N_TSCOMPONENT
|
|
|
|
#define INCLUDED_I18N_TSCOMPONENT
|
2004-08-21 13:45:01 +02:00
|
|
|
|
|
|
|
#include "StrImmutable.h"
|
|
|
|
#include "BufferVariable.h"
|
|
|
|
#include "ScriptInterface.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace I18n
|
|
|
|
{
|
|
|
|
class CLocale;
|
|
|
|
|
2007-02-01 15:46:14 +01:00
|
|
|
class TSComponent
|
2004-08-21 13:45:01 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const = 0;
|
|
|
|
virtual ~TSComponent() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-03 19:40:28 +01:00
|
|
|
class TSComponentString : public TSComponent
|
2007-02-01 15:46:14 +01:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(TSComponentString);
|
2004-08-21 13:45:01 +02:00
|
|
|
public:
|
2007-02-01 15:46:14 +01:00
|
|
|
TSComponentString(const wchar_t* s) : String(s) {}
|
2004-08-21 13:45:01 +02:00
|
|
|
|
|
|
|
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const StrImW String;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-03 19:40:28 +01:00
|
|
|
class TSComponentVariable : public TSComponent
|
2007-02-01 15:46:14 +01:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(TSComponentVariable);
|
2004-08-21 13:45:01 +02:00
|
|
|
public:
|
2007-02-01 15:46:14 +01:00
|
|
|
TSComponentVariable(unsigned char id) : ID(id) {}
|
2004-08-21 13:45:01 +02:00
|
|
|
|
|
|
|
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned char ID;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-03 19:40:28 +01:00
|
|
|
class TSComponentFunction : public TSComponent
|
2007-02-01 15:46:14 +01:00
|
|
|
{
|
2009-01-03 19:40:28 +01:00
|
|
|
NONCOPYABLE(TSComponentFunction);
|
2004-08-21 13:45:01 +02:00
|
|
|
public:
|
2007-02-01 15:46:14 +01:00
|
|
|
TSComponentFunction(const char* name) : Name(name) {}
|
2004-08-21 13:45:01 +02:00
|
|
|
~TSComponentFunction();
|
|
|
|
|
|
|
|
const StrImW ToString(CLocale* locale, std::vector<BufferVariable*>& vars) const;
|
|
|
|
|
|
|
|
// AddParam is called when loading the function, building up the
|
|
|
|
// internal list of parameters (strings / ints / variables)
|
|
|
|
void AddParam(ScriptValue* p);
|
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string Name;
|
|
|
|
std::vector<ScriptValue*> Params;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // INCLUDED_I18N_TSCOMPONENT
|