Make templates localizable (Closes #100)

This commit is contained in:
Twan van Laarhoven
2020-10-03 14:38:39 +02:00
parent f2ae3ae43b
commit c7377303cf
23 changed files with 155 additions and 63 deletions
+37
View File
@@ -0,0 +1,37 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) Twan van Laarhoven and the other MSE developers |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#pragma once
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
class Locale;
// ----------------------------------------------------------------------------- : LocalizedString
/// Translations of a text in a template
class LocalizedString {
public:
String default_; //< Value in all other locales
unordered_map<String, String> translations;
/// Translate
String const& get(Locale const& locale) const;
String const& get(String const& locale) const;
String const& get() const;
bool empty() const { return default_.empty(); }
};
#define REFLECT_LOCALIZED_N(name, var) \
do { \
handler.handle(name, var.default_); \
handler.handle(_("localized_") name, var.translations); \
} while (0)
#define REFLECT_LOCALIZED(var) REFLECT_LOCALIZED_N(_(#var), var)