mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Make templates localizable (Closes #100)
This commit is contained in:
+5
-5
@@ -47,8 +47,8 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
REFLECT(type);
|
||||
}
|
||||
REFLECT(name);
|
||||
REFLECT(caption);
|
||||
REFLECT(description);
|
||||
REFLECT_LOCALIZED(caption);
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT(editable);
|
||||
REFLECT(save_value);
|
||||
@@ -59,15 +59,15 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
REFLECT(card_list_width);
|
||||
REFLECT(card_list_visible);
|
||||
REFLECT(card_list_allow);
|
||||
REFLECT(card_list_name);
|
||||
REFLECT_LOCALIZED(card_list_name);
|
||||
REFLECT(sort_script);
|
||||
REFLECT_N("card_list_alignment", card_list_align);
|
||||
}
|
||||
|
||||
void Field::after_reading(Version ver) {
|
||||
name = canonical_name_form(name);
|
||||
if(caption.empty()) caption = name_to_caption(name);
|
||||
if(card_list_name.empty()) card_list_name = capitalize(caption);
|
||||
if(caption.default_.empty()) caption.default_ = name_to_caption(name);
|
||||
if(card_list_name.default_.empty()) card_list_name.default_ = capitalize(caption.default_);
|
||||
}
|
||||
|
||||
template <>
|
||||
|
||||
+4
-3
@@ -13,6 +13,7 @@
|
||||
#include <util/alignment.hpp>
|
||||
#include <util/age.hpp>
|
||||
#include <util/rotation.hpp>
|
||||
#include <data/localized_string.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <script/dependency.hpp>
|
||||
#include <script/image.hpp>
|
||||
@@ -43,8 +44,8 @@ public:
|
||||
|
||||
size_t index; ///< Used by IndexMap
|
||||
String name; ///< Name of the field, for refering to it from scripts and files
|
||||
String caption; ///< Caption for NativeLookEditor
|
||||
String description; ///< Description, used in status bar
|
||||
LocalizedString caption; ///< Caption for NativeLookEditor
|
||||
LocalizedString description;///< Description, used in status bar
|
||||
String icon_filename; ///< Filename for an icon (for list of fields)
|
||||
bool editable; ///< Can values of this field be edited?
|
||||
bool save_value; ///< Should values of this field be written to files? Can be false for script generated fields.
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
UInt card_list_width; ///< Width of the card list column (pixels).
|
||||
bool card_list_visible;///< Is this field shown in the card list?
|
||||
bool card_list_allow; ///< Is this field allowed to appear in the card list?
|
||||
String card_list_name; ///< Alternate name to use in card list.
|
||||
LocalizedString card_list_name; ///< Name to use in card list.
|
||||
Alignment card_list_align; ///< Alignment of the card list colummn.
|
||||
OptionalScript sort_script; ///< The script to use when sorting this, if not the value.
|
||||
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
|
||||
|
||||
@@ -64,7 +64,7 @@ String InfoValue::toString() const {
|
||||
return value;
|
||||
}
|
||||
bool InfoValue::update(Context& ctx) {
|
||||
if (value.empty()) value = field().caption;
|
||||
if (value.empty()) value = field().caption.get();
|
||||
bool change = field().script.invokeOn(ctx, value);
|
||||
Value::update(ctx);
|
||||
return change;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <data/locale.hpp>
|
||||
#include <data/localized_string.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <data/stylesheet.hpp>
|
||||
#include <data/symbol_font.hpp>
|
||||
@@ -118,3 +119,23 @@ String tr(const Package& pkg, const String& subcat, const String& key, DefaultLo
|
||||
}
|
||||
return loc->tr(subcat, key, def);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : LocalizedString
|
||||
|
||||
String const& LocalizedString::get(String const& locale) const {
|
||||
auto it = translations.find(locale);
|
||||
if (it != translations.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return default_;
|
||||
}
|
||||
}
|
||||
|
||||
String const& LocalizedString::get(Locale const& locale) const {
|
||||
return get(locale.name());
|
||||
}
|
||||
|
||||
String const& LocalizedString::get() const {
|
||||
if (translations.empty()) return default_;
|
||||
return get(the_locale->name());
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
@@ -64,7 +64,7 @@ StatsDimension::StatsDimension(const Field& field)
|
||||
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
|
||||
if (!automatic) {
|
||||
REFLECT(name);
|
||||
REFLECT(description);
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT(position_hint);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT(script);
|
||||
@@ -98,7 +98,7 @@ StatsCategory::StatsCategory(const StatsDimensionP& dim)
|
||||
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
|
||||
if (!automatic) {
|
||||
REFLECT(name);
|
||||
REFLECT(description);
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT(position_hint);
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT(type);
|
||||
|
||||
+11
-10
@@ -11,6 +11,7 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <util/reflect.hpp>
|
||||
#include <data/graph_type.hpp>
|
||||
#include <data/localized_string.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
|
||||
class Field;
|
||||
@@ -28,7 +29,7 @@ public:
|
||||
|
||||
const bool automatic; ///< Based on a card field?
|
||||
String name; ///< Name of this dimension
|
||||
String description; ///< Description, used in status bar
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
int position_hint; ///< Hint for the ordering
|
||||
String icon_filename; ///< Icon for lists
|
||||
Bitmap icon; ///< The loaded icon (optional of course)
|
||||
@@ -52,15 +53,15 @@ public:
|
||||
StatsCategory();
|
||||
StatsCategory(const StatsDimensionP&);
|
||||
|
||||
const bool automatic; ///< Automatically generated?
|
||||
String name; ///< Name/label
|
||||
String description; ///< Description, used in status bar
|
||||
int position_hint; ///< Hint for the ordering
|
||||
String icon_filename; ///< Icon for lists
|
||||
Bitmap icon; ///< The loaded icon (optional of course)
|
||||
vector<String> dimension_names;///< Names of the dimensions to use
|
||||
vector<StatsDimensionP> dimensions; ///< Actual dimensions
|
||||
GraphType type; ///< Type of graph to use
|
||||
const bool automatic; ///< Automatically generated?
|
||||
String name; ///< Name/label
|
||||
LocalizedString description; ///< Description, used in status bar
|
||||
int position_hint; ///< Hint for the ordering
|
||||
String icon_filename; ///< Icon for lists
|
||||
Bitmap icon; ///< The loaded icon (optional of course)
|
||||
vector<String> dimension_names; ///< Names of the dimensions to use
|
||||
vector<StatsDimensionP> dimensions; ///< Actual dimensions
|
||||
GraphType type; ///< Type of graph to use
|
||||
|
||||
/// Initialize dimensions from dimension_names
|
||||
void find_dimensions(const vector<StatsDimensionP>& available);
|
||||
|
||||
+21
-20
@@ -52,8 +52,8 @@ IMPLEMENT_REFLECTION(SymbolFont) {
|
||||
REFLECT_N("vertical_space", spacing.height);
|
||||
WITH_DYNAMIC_ARG(symbol_font_for_reading, this);
|
||||
REFLECT(symbols);
|
||||
REFLECT(scale_text);
|
||||
REFLECT(insert_symbol_menu);
|
||||
REFLECT(scale_text);
|
||||
REFLECT(insert_symbol_menu);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolInFont
|
||||
@@ -460,11 +460,11 @@ String InsertSymbolMenu::getCode(int id, const SymbolFont& font) const {
|
||||
} else if (id == 0 && type == Type::CODE) {
|
||||
return name;
|
||||
} else if (id == 0 && type == Type::CUSTOM) {
|
||||
String caption = tr(font, _("title"), name, capitalize_sentence);
|
||||
String message = tr(font, _("message"), name, capitalize_sentence);
|
||||
return wxGetTextFromUser(message, caption);
|
||||
String title = this->label.get();
|
||||
title.Replace(_("&"), _("")); // remove underlines
|
||||
return wxGetTextFromUser(prompt.get(), title);
|
||||
}
|
||||
return wxEmptyString;
|
||||
return String();
|
||||
}
|
||||
|
||||
wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
|
||||
@@ -478,17 +478,18 @@ wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolFont& font) const {
|
||||
wxString menu_name = tr(font, _("menu_item"), name, capitalize);
|
||||
String label = this->label.get();
|
||||
// ensure that there is not actually an accelerator string,
|
||||
menu_name.Replace(_("\t "),_("\t"));
|
||||
label.Replace(_("\t "), _("\t"));
|
||||
#ifdef __WXMSW__
|
||||
menu_name.Replace(_("\t"),_("\t ")); // by prepending " "
|
||||
label.Replace(_("\t"), _("\t ")); // by prepending " "
|
||||
#else
|
||||
menu_name.Replace(_("\t"),_(" ")); // by simply dropping the \t
|
||||
label.Replace(_("\t"), _(" ")); // by simply dropping the \t
|
||||
#endif
|
||||
if (type == Type::SUBMENU) {
|
||||
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, menu_name,
|
||||
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, label,
|
||||
wxEmptyString, wxITEM_NORMAL,
|
||||
makeMenu(first_id, font));
|
||||
item->SetBitmap(wxNullBitmap);
|
||||
@@ -497,7 +498,7 @@ wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolF
|
||||
wxMenuItem* item = new wxMenuItem(parent, wxID_SEPARATOR);
|
||||
return item;
|
||||
} else {
|
||||
wxMenuItem* item = new wxMenuItem(parent, first_id, menu_name);
|
||||
wxMenuItem* item = new wxMenuItem(parent, first_id, label);
|
||||
// Generate bitmap for use on this item
|
||||
SymbolInFont* symbol = nullptr;
|
||||
if (type == Type::CUSTOM) {
|
||||
@@ -527,24 +528,24 @@ IMPLEMENT_REFLECTION_ENUM(InsertSymbolMenu::Type) {
|
||||
VALUE_N("submenu", InsertSymbolMenu::Type::SUBMENU);
|
||||
}
|
||||
|
||||
IMPLEMENT_REFLECTION_NO_GET_MEMBER(InsertSymbolMenu) {
|
||||
IMPLEMENT_REFLECTION(InsertSymbolMenu) {
|
||||
REFLECT_IF_READING_SINGLE_VALUE_AND(items.empty()) {
|
||||
REFLECT_NAMELESS(name);
|
||||
} else {
|
||||
// complex values are groups
|
||||
REFLECT(type);
|
||||
REFLECT(name);
|
||||
REFLECT_LOCALIZED(label);
|
||||
REFLECT_LOCALIZED(prompt);
|
||||
REFLECT(items);
|
||||
if (Handler::isReading && !items.empty()) type = Type::SUBMENU;
|
||||
}
|
||||
}
|
||||
template <> void GetDefaultMember::handle(const InsertSymbolMenu& m) {
|
||||
handle(m.name);
|
||||
}
|
||||
template <> void GetMember::handle(const InsertSymbolMenu& m) {
|
||||
handle(_("type"), m.type);
|
||||
handle(_("name"), m.name);
|
||||
handle(_("items"), m.items);
|
||||
|
||||
void after_reading(InsertSymbolMenu& m, Version ver) {
|
||||
assert(symbol_font_for_reading());
|
||||
if (m.label.empty()) m.label.default_ = tr(*symbol_font_for_reading(), _("menu_item"), m.name, capitalize);
|
||||
if (m.prompt.empty()) m.prompt.default_ = tr(*symbol_font_for_reading(), _("message"), m.name, capitalize_sentence);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolFontRef
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <util/prec.hpp>
|
||||
#include <util/alignment.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
#include <data/localized_string.hpp>
|
||||
#include <data/font.hpp>
|
||||
#include <wx/regex.h>
|
||||
|
||||
@@ -124,6 +125,8 @@ public:
|
||||
};
|
||||
Type type;
|
||||
String name;
|
||||
LocalizedString label; // text of menu item
|
||||
LocalizedString prompt; // prompt for dialog box if type == CUSTOM
|
||||
vector<InsertSymbolMenuP> items;
|
||||
|
||||
/// Number of ids used (recursive)
|
||||
@@ -139,6 +142,8 @@ private:
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
void after_reading(InsertSymbolMenu&, Version ver);
|
||||
|
||||
// ----------------------------------------------------------------------------- : SymbolFontRef
|
||||
|
||||
/// A reference to an actual symbol font
|
||||
|
||||
Reference in New Issue
Block a user