2020-12-31 07:32:16 -08:00
|
|
|
// Copyright © 2008-2021 Pioneer Developers. See AUTHORS.txt for details
|
2012-09-15 17:59:15 -07:00
|
|
|
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
|
2012-09-12 04:38:30 -07:00
|
|
|
|
2011-07-26 15:31:19 -07:00
|
|
|
#ifndef _LANG_H
|
|
|
|
#define _LANG_H
|
|
|
|
|
2014-02-22 09:13:00 -08:00
|
|
|
#include "IterationProxy.h"
|
2019-01-02 08:59:07 -08:00
|
|
|
#include <SDL_stdinc.h>
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2011-07-27 05:39:13 -07:00
|
|
|
|
2011-07-26 15:31:19 -07:00
|
|
|
namespace Lang {
|
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
class Resource {
|
|
|
|
public:
|
|
|
|
Resource(const std::string &name, const std::string &langCode) :
|
|
|
|
m_name(name),
|
|
|
|
m_langCode(langCode),
|
|
|
|
m_loaded(false) {}
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
const std::string &GetName() const { return m_name; }
|
|
|
|
const std::string &GetLangCode() const { return m_langCode; }
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
bool Load();
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
Uint32 GetNumStrings() const { return static_cast<Uint32>(m_strings.size()); }
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
const std::string &Get(const std::string &token) const;
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
static std::vector<std::string> GetAvailableLanguages(const std::string &resourceName);
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
IterationProxy<std::map<std::string, std::string>> GetStrings() { return MakeIterationProxy(m_strings); }
|
|
|
|
const IterationProxy<const std::map<std::string, std::string>> GetStrings() const { return MakeIterationProxy(m_strings); }
|
2013-10-22 14:48:36 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
private:
|
|
|
|
std::string m_name;
|
|
|
|
std::string m_langCode;
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
bool m_loaded;
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
std::map<std::string, std::string> m_strings;
|
|
|
|
};
|
2011-07-26 15:31:19 -07:00
|
|
|
|
2012-02-17 13:19:39 -08:00
|
|
|
// declare all strings
|
|
|
|
#define DECLARE_STRING(x) extern char x[];
|
|
|
|
#include "LangStrings.inc.h"
|
|
|
|
#undef DECLARE_STRING
|
2011-07-26 15:31:19 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
void MakeCore(Resource &res);
|
|
|
|
const Resource &GetCore();
|
2013-10-22 13:59:57 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
Resource GetResource(const std::string &name, const std::string &langCode);
|
2013-10-22 14:26:11 -07:00
|
|
|
|
2019-01-02 08:59:07 -08:00
|
|
|
} // namespace Lang
|
2011-07-26 15:31:19 -07:00
|
|
|
|
|
|
|
#endif
|