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
+3
View File
@@ -4,6 +4,9 @@ Magic Set Editor changelog, for the details see `git log`
HEAD: new items added as changes are made HEAD: new items added as changes are made
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
Template features:
* Localization of game/stylesheet/symbol_font names is now done in those templates, instead of via the program-wide locale file. (#100)
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
version 2.1.2, 2020-09-28 version 2.1.2, 2020-09-28
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
+2 -2
View File
@@ -27,7 +27,7 @@ Fields are part of the [[file:style triangle]]:
* @color@ * @color@
* @info@ * @info@
| @name@ [[type:string]] ''required'' Name of the field. | @name@ [[type:string]] ''required'' Name of the field.
| @description@ [[type:string]] @""@ Description of the field, shown in the status bar when the mouse is over the field. | @description@ [[type:localized string]] @""@ Description of the field, shown in the status bar when the mouse is over the field.
| @icon@ [[type:filename]] Filename of an icon for this field, used for automatically generated [[type:statistics category]]s. | @icon@ [[type:filename]] Filename of an icon for this field, used for automatically generated [[type:statistics category]]s.
| @editable@ [[type:boolean]] @true@ Can values of this field be edited? | @editable@ [[type:boolean]] @true@ Can values of this field be edited?
| @save value@ [[type:boolean]] @true@ Should values of this field be saved to files? Should be disabled for values that are generated by scripts. | @save value@ [[type:boolean]] @true@ Should values of this field be saved to files? Should be disabled for values that are generated by scripts.
@@ -38,7 +38,7 @@ Fields are part of the [[file:style triangle]]:
| @card list width@ [[type:int]] @100@ Width of the card list column in pixels. | @card list width@ [[type:int]] @100@ Width of the card list column in pixels.
| @card list visible@ [[type:boolean]] @false@ Should this field be shown in the card list by default? | @card list visible@ [[type:boolean]] @false@ Should this field be shown in the card list by default?
| @card list allow@ [[type:boolean]] @true@ Should this field be allowed in the card list at all? | @card list allow@ [[type:boolean]] @true@ Should this field be allowed in the card list at all?
| @card list name@ [[type:string]] field name Alternate name to use for the card list, for example an abbreviation. | @card list name@ [[type:localized string]] field name Alternate name to use for the card list, for example an abbreviation.
| @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column. | @card list alignment@ [[type:alignment]] @left@ Alignment of the card list column.
| @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list. | @sort script@ [[type:script]] Alternate way to sort the card list when using this column to sort the list.
+8 -4
View File
@@ -14,18 +14,19 @@ The menu consists of a number of entries, either items, separators or submenus.
* @line@, a separating line. * @line@, a separating line.
* @submenu@, a submenu. * @submenu@, a submenu.
| @name@ [[type:string]] ''required'' Name of this menu item, corresponding to the code to insert. | @name@ [[type:string]] ''required'' Name of this menu item, corresponding to the code to insert.
| @label@ [[type:localized string]] name Label to show in the menu.
| @prompt@ [[type:localized string]] Prompt to use for the pop up box with @custom@ type
| @items@ [[type:list]] of [[type:insert symbol menu|submenu items]] Items in the submenu, when items are present the @type@ is set to @"submenu"@. | @items@ [[type:list]] of [[type:insert symbol menu|submenu items]] Items in the submenu, when items are present the @type@ is set to @"submenu"@.
In the user interface the items are shown as @"menu item {name}"@, the [[type:locale]] should be used to give a beter label. For custom items the dialog will be titled with the @label@ and have message text @prompt@.
For custom items the dialog will be titled @"title {name}"@ and have message text @"message {name}"@, again this should be changed in the locale.
--Examples-- --Examples--
A menu for magic mana symbols (simplified). Containing all types of items. A menu for magic mana symbols (simplified). Containing all types of items.
>insert symbol menu: >insert symbol menu:
> item: > item:
> type: custom > type: custom
> name: colorless > name: Generic
> prompt: How much generic mana?
> item: > item:
> type: line > type: line
> item: W > item: W
@@ -34,6 +35,9 @@ A menu for magic mana symbols (simplified). Containing all types of items.
> item: R > item: R
> item: G > item: G
> item: > item:
> label: Complex
> name: cplx
> item:
> type: line > type: line
> item: > item:
> name: hybrid > name: hybrid
+3
View File
@@ -35,12 +35,15 @@ There are usually no other files in the package.
| @error@ [[type:map]] of [[type:string]]s Error messages. | @error@ [[type:map]] of [[type:string]]s Error messages.
| @type@ [[type:map]] of [[type:string]]s Types of objects for error messages. | @type@ [[type:map]] of [[type:string]]s Types of objects for error messages.
| @game@ [[type:map]] of [[type:map]] of [[type:string]]s | @game@ [[type:map]] of [[type:map]] of [[type:string]]s
Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:game]]s.<br/> Translations for specific [[type:game]]s.<br/>
Field names and field descriptions are looked up in the locale, if they are found the translation is used, otherwise the value from the game file.<br/> Field names and field descriptions are looked up in the locale, if they are found the translation is used, otherwise the value from the game file.<br/>
Extra keys not present in the English locale can be added here. Extra keys not present in the English locale can be added here.
| @stylesheet@ [[type:map]] of [[type:map]] of [[type:string]]s | @stylesheet@ [[type:map]] of [[type:map]] of [[type:string]]s
Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:stylesheet]]s. Translations for specific [[type:stylesheet]]s.
| @symbol font@ [[type:map]] of [[type:map]] of [[type:string]]s | @symbol font@ [[type:map]] of [[type:map]] of [[type:string]]s
Deprecated since MSE 2.1.3, use @localized_...@ instead.<br/>
Translations for specific [[type:symbol font]]s, in particular the "insert symbol" menu. Translations for specific [[type:symbol font]]s, in particular the "insert symbol" menu.
Some of the items can contain placeholders for other values, for example: Some of the items can contain placeholders for other values, for example:
+14
View File
@@ -0,0 +1,14 @@
Localized strings
A 'localized string' is a [[type:map]] of [[type::string]]s, indexed by locale name.
It is used to translate games and stylesheets to other user interface languages.
Localized strings can be given with a @localized@ prefix on the property name.
For example, a field has a @description@ which is a [[type::string]], and a @localized_description@ for localized variants. So
>field:
> name: cost
> description: How much this card costs
> localized description:
> en_US: How much this card costs
> nl_NL: Hoeveel deze kaart kost
+1 -1
View File
@@ -12,7 +12,7 @@ Statistics dimensions are automatically generated for all [[type:statistics dime
--Properties-- --Properties--
! Property Type Default Description ! Property Type Default Description
| @name@ [[type:string]] ''required'' Name of this category. | @name@ [[type:string]] ''required'' Name of this category.
| @description@ [[type:string]] @""@ A description of the category, currently not used. | @description@ [[type:localized string]] @""@ A description of the category, currently not used.
| @position hint@ [[type:string]] @0@ Hint for ordering category, lower numbers are at the top of the list. | @position hint@ [[type:string]] @0@ Hint for ordering category, lower numbers are at the top of the list.
| @icon@ [[type:filename]] Filename of an icon for this category, the image should be 21x21 pixels. | @icon@ [[type:filename]] Filename of an icon for this category, the image should be 21x21 pixels.
| @type@ [[type:graph type]] @"bar"@ Type of graph to use. | @type@ [[type:graph type]] @"bar"@ Type of graph to use.
+1 -1
View File
@@ -13,7 +13,7 @@ Categories are also automatically generated from dimensions.
--Properties-- --Properties--
! Property Type Default Description ! Property Type Default Description
| @name@ [[type:string]] ''required'' Name of this dimension, used as an axis label and a label for automatically generated categories. | @name@ [[type:string]] ''required'' Name of this dimension, used as an axis label and a label for automatically generated categories.
| @description@ [[type:string]] @""@ A description of the dimension, currently not used. | @description@ [[type:localized string]] @""@ A description of the dimension, currently not used.
| @position hint@ [[type:string]] @0@ Hint for ordering dimensions. | @position hint@ [[type:string]] @0@ Hint for ordering dimensions.
| @icon@ [[type:filename]] Filename of an icon for this dimension. | @icon@ [[type:filename]] Filename of an icon for this dimension.
| @script@ [[type:script]] ''required'' Script that generates a value for each card in the set. | @script@ [[type:script]] ''required'' Script that generates a value for each card in the set.
+5 -5
View File
@@ -47,8 +47,8 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(type); REFLECT(type);
} }
REFLECT(name); REFLECT(name);
REFLECT(caption); REFLECT_LOCALIZED(caption);
REFLECT(description); REFLECT_LOCALIZED(description);
REFLECT_N("icon", icon_filename); REFLECT_N("icon", icon_filename);
REFLECT(editable); REFLECT(editable);
REFLECT(save_value); REFLECT(save_value);
@@ -59,15 +59,15 @@ IMPLEMENT_REFLECTION(Field) {
REFLECT(card_list_width); REFLECT(card_list_width);
REFLECT(card_list_visible); REFLECT(card_list_visible);
REFLECT(card_list_allow); REFLECT(card_list_allow);
REFLECT(card_list_name); REFLECT_LOCALIZED(card_list_name);
REFLECT(sort_script); REFLECT(sort_script);
REFLECT_N("card_list_alignment", card_list_align); REFLECT_N("card_list_alignment", card_list_align);
} }
void Field::after_reading(Version ver) { void Field::after_reading(Version ver) {
name = canonical_name_form(name); name = canonical_name_form(name);
if(caption.empty()) caption = name_to_caption(name); if(caption.default_.empty()) caption.default_ = name_to_caption(name);
if(card_list_name.empty()) card_list_name = capitalize(caption); if(card_list_name.default_.empty()) card_list_name.default_ = capitalize(caption.default_);
} }
template <> template <>
+4 -3
View File
@@ -13,6 +13,7 @@
#include <util/alignment.hpp> #include <util/alignment.hpp>
#include <util/age.hpp> #include <util/age.hpp>
#include <util/rotation.hpp> #include <util/rotation.hpp>
#include <data/localized_string.hpp>
#include <script/scriptable.hpp> #include <script/scriptable.hpp>
#include <script/dependency.hpp> #include <script/dependency.hpp>
#include <script/image.hpp> #include <script/image.hpp>
@@ -43,8 +44,8 @@ public:
size_t index; ///< Used by IndexMap size_t index; ///< Used by IndexMap
String name; ///< Name of the field, for refering to it from scripts and files String name; ///< Name of the field, for refering to it from scripts and files
String caption; ///< Caption for NativeLookEditor LocalizedString caption; ///< Caption for NativeLookEditor
String description; ///< Description, used in status bar LocalizedString description;///< Description, used in status bar
String icon_filename; ///< Filename for an icon (for list of fields) String icon_filename; ///< Filename for an icon (for list of fields)
bool editable; ///< Can values of this field be edited? 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. 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). 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_visible;///< Is this field shown in the card list?
bool card_list_allow; ///< Is this field allowed to appear 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. Alignment card_list_align; ///< Alignment of the card list colummn.
OptionalScript sort_script; ///< The script to use when sorting this, if not the value. 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 Dependencies dependent_scripts; ///< Scripts that depend on values of this field
+1 -1
View File
@@ -64,7 +64,7 @@ String InfoValue::toString() const {
return value; return value;
} }
bool InfoValue::update(Context& ctx) { 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); bool change = field().script.invokeOn(ctx, value);
Value::update(ctx); Value::update(ctx);
return change; return change;
+21
View File
@@ -8,6 +8,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <data/locale.hpp> #include <data/locale.hpp>
#include <data/localized_string.hpp>
#include <data/game.hpp> #include <data/game.hpp>
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <data/symbol_font.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); 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());
}
+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)
+2 -2
View File
@@ -64,7 +64,7 @@ StatsDimension::StatsDimension(const Field& field)
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) { IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsDimension) {
if (!automatic) { if (!automatic) {
REFLECT(name); REFLECT(name);
REFLECT(description); REFLECT_LOCALIZED(description);
REFLECT(position_hint); REFLECT(position_hint);
REFLECT_N("icon", icon_filename); REFLECT_N("icon", icon_filename);
REFLECT(script); REFLECT(script);
@@ -98,7 +98,7 @@ StatsCategory::StatsCategory(const StatsDimensionP& dim)
IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) { IMPLEMENT_REFLECTION_NO_GET_MEMBER(StatsCategory) {
if (!automatic) { if (!automatic) {
REFLECT(name); REFLECT(name);
REFLECT(description); REFLECT_LOCALIZED(description);
REFLECT(position_hint); REFLECT(position_hint);
REFLECT_N("icon", icon_filename); REFLECT_N("icon", icon_filename);
REFLECT(type); REFLECT(type);
+11 -10
View File
@@ -11,6 +11,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/reflect.hpp> #include <util/reflect.hpp>
#include <data/graph_type.hpp> #include <data/graph_type.hpp>
#include <data/localized_string.hpp>
#include <script/scriptable.hpp> #include <script/scriptable.hpp>
class Field; class Field;
@@ -28,7 +29,7 @@ public:
const bool automatic; ///< Based on a card field? const bool automatic; ///< Based on a card field?
String name; ///< Name of this dimension 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 int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course) Bitmap icon; ///< The loaded icon (optional of course)
@@ -52,15 +53,15 @@ public:
StatsCategory(); StatsCategory();
StatsCategory(const StatsDimensionP&); StatsCategory(const StatsDimensionP&);
const bool automatic; ///< Automatically generated? const bool automatic; ///< Automatically generated?
String name; ///< Name/label String name; ///< Name/label
String description; ///< Description, used in status bar LocalizedString description; ///< Description, used in status bar
int position_hint; ///< Hint for the ordering int position_hint; ///< Hint for the ordering
String icon_filename; ///< Icon for lists String icon_filename; ///< Icon for lists
Bitmap icon; ///< The loaded icon (optional of course) Bitmap icon; ///< The loaded icon (optional of course)
vector<String> dimension_names;///< Names of the dimensions to use vector<String> dimension_names; ///< Names of the dimensions to use
vector<StatsDimensionP> dimensions; ///< Actual dimensions vector<StatsDimensionP> dimensions; ///< Actual dimensions
GraphType type; ///< Type of graph to use GraphType type; ///< Type of graph to use
/// Initialize dimensions from dimension_names /// Initialize dimensions from dimension_names
void find_dimensions(const vector<StatsDimensionP>& available); void find_dimensions(const vector<StatsDimensionP>& available);
+21 -20
View File
@@ -52,8 +52,8 @@ IMPLEMENT_REFLECTION(SymbolFont) {
REFLECT_N("vertical_space", spacing.height); REFLECT_N("vertical_space", spacing.height);
WITH_DYNAMIC_ARG(symbol_font_for_reading, this); WITH_DYNAMIC_ARG(symbol_font_for_reading, this);
REFLECT(symbols); REFLECT(symbols);
REFLECT(scale_text); REFLECT(scale_text);
REFLECT(insert_symbol_menu); REFLECT(insert_symbol_menu);
} }
// ----------------------------------------------------------------------------- : SymbolInFont // ----------------------------------------------------------------------------- : SymbolInFont
@@ -460,11 +460,11 @@ String InsertSymbolMenu::getCode(int id, const SymbolFont& font) const {
} else if (id == 0 && type == Type::CODE) { } else if (id == 0 && type == Type::CODE) {
return name; return name;
} else if (id == 0 && type == Type::CUSTOM) { } else if (id == 0 && type == Type::CUSTOM) {
String caption = tr(font, _("title"), name, capitalize_sentence); String title = this->label.get();
String message = tr(font, _("message"), name, capitalize_sentence); title.Replace(_("&"), _("")); // remove underlines
return wxGetTextFromUser(message, caption); return wxGetTextFromUser(prompt.get(), title);
} }
return wxEmptyString; return String();
} }
wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const { wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
@@ -478,17 +478,18 @@ wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
} }
return nullptr; return nullptr;
} }
wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolFont& font) const { 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, // ensure that there is not actually an accelerator string,
menu_name.Replace(_("\t "),_("\t")); label.Replace(_("\t "), _("\t"));
#ifdef __WXMSW__ #ifdef __WXMSW__
menu_name.Replace(_("\t"),_("\t ")); // by prepending " " label.Replace(_("\t"), _("\t ")); // by prepending " "
#else #else
menu_name.Replace(_("\t"),_(" ")); // by simply dropping the \t label.Replace(_("\t"), _(" ")); // by simply dropping the \t
#endif #endif
if (type == Type::SUBMENU) { if (type == Type::SUBMENU) {
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, menu_name, wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, label,
wxEmptyString, wxITEM_NORMAL, wxEmptyString, wxITEM_NORMAL,
makeMenu(first_id, font)); makeMenu(first_id, font));
item->SetBitmap(wxNullBitmap); item->SetBitmap(wxNullBitmap);
@@ -497,7 +498,7 @@ wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolF
wxMenuItem* item = new wxMenuItem(parent, wxID_SEPARATOR); wxMenuItem* item = new wxMenuItem(parent, wxID_SEPARATOR);
return item; return item;
} else { } 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 // Generate bitmap for use on this item
SymbolInFont* symbol = nullptr; SymbolInFont* symbol = nullptr;
if (type == Type::CUSTOM) { if (type == Type::CUSTOM) {
@@ -527,24 +528,24 @@ IMPLEMENT_REFLECTION_ENUM(InsertSymbolMenu::Type) {
VALUE_N("submenu", InsertSymbolMenu::Type::SUBMENU); VALUE_N("submenu", InsertSymbolMenu::Type::SUBMENU);
} }
IMPLEMENT_REFLECTION_NO_GET_MEMBER(InsertSymbolMenu) { IMPLEMENT_REFLECTION(InsertSymbolMenu) {
REFLECT_IF_READING_SINGLE_VALUE_AND(items.empty()) { REFLECT_IF_READING_SINGLE_VALUE_AND(items.empty()) {
REFLECT_NAMELESS(name); REFLECT_NAMELESS(name);
} else { } else {
// complex values are groups // complex values are groups
REFLECT(type); REFLECT(type);
REFLECT(name); REFLECT(name);
REFLECT_LOCALIZED(label);
REFLECT_LOCALIZED(prompt);
REFLECT(items); REFLECT(items);
if (Handler::isReading && !items.empty()) type = Type::SUBMENU; if (Handler::isReading && !items.empty()) type = Type::SUBMENU;
} }
} }
template <> void GetDefaultMember::handle(const InsertSymbolMenu& m) {
handle(m.name); void after_reading(InsertSymbolMenu& m, Version ver) {
} assert(symbol_font_for_reading());
template <> void GetMember::handle(const InsertSymbolMenu& m) { if (m.label.empty()) m.label.default_ = tr(*symbol_font_for_reading(), _("menu_item"), m.name, capitalize);
handle(_("type"), m.type); if (m.prompt.empty()) m.prompt.default_ = tr(*symbol_font_for_reading(), _("message"), m.name, capitalize_sentence);
handle(_("name"), m.name);
handle(_("items"), m.items);
} }
// ----------------------------------------------------------------------------- : SymbolFontRef // ----------------------------------------------------------------------------- : SymbolFontRef
+5
View File
@@ -11,6 +11,7 @@
#include <util/prec.hpp> #include <util/prec.hpp>
#include <util/alignment.hpp> #include <util/alignment.hpp>
#include <util/io/package.hpp> #include <util/io/package.hpp>
#include <data/localized_string.hpp>
#include <data/font.hpp> #include <data/font.hpp>
#include <wx/regex.h> #include <wx/regex.h>
@@ -124,6 +125,8 @@ public:
}; };
Type type; Type type;
String name; String name;
LocalizedString label; // text of menu item
LocalizedString prompt; // prompt for dialog box if type == CUSTOM
vector<InsertSymbolMenuP> items; vector<InsertSymbolMenuP> items;
/// Number of ids used (recursive) /// Number of ids used (recursive)
@@ -139,6 +142,8 @@ private:
DECLARE_REFLECTION(); DECLARE_REFLECTION();
}; };
void after_reading(InsertSymbolMenu&, Version ver);
// ----------------------------------------------------------------------------- : SymbolFontRef // ----------------------------------------------------------------------------- : SymbolFontRef
/// A reference to an actual symbol font /// A reference to an actual symbol font
+1 -1
View File
@@ -355,7 +355,7 @@ void DataEditor::onMotion(wxMouseEvent& ev) {
// set status text // set status text
wxFrame* frame = dynamic_cast<wxFrame*>( wxGetTopLevelParent(this) ); wxFrame* frame = dynamic_cast<wxFrame*>( wxGetTopLevelParent(this) );
if (frame) { if (frame) {
frame->SetStatusText(hovered_viewer ? hovered_viewer->getField()->description : String()); frame->SetStatusText(hovered_viewer ? hovered_viewer->getField()->description.get() : String());
} }
} }
} }
+1 -3
View File
@@ -225,9 +225,7 @@ void CardListBase::rebuild() {
if (f.second->card_list_align & ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT; if (f.second->card_list_align & ALIGN_RIGHT) align = wxLIST_FORMAT_RIGHT;
else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE; else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE;
else align = wxLIST_FORMAT_LEFT; else align = wxLIST_FORMAT_LEFT;
InsertColumn((long)column_fields.size(), InsertColumn((long)column_fields.size(), f.second->card_list_name.get(), align, cs.width);
tr(*set->game, f.second->card_list_name, identity),
align, cs.width);
column_fields.push_back(f.second); column_fields.push_back(f.second);
} }
// determine sort settings // determine sort settings
+2 -2
View File
@@ -67,7 +67,7 @@ void CardListColumnSelectDialog::initList() {
// Init items // Init items
Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
FOR_EACH(c, columns) { FOR_EACH(c, columns) {
list->Append(tr(*game, c.field->card_list_name, identity)); list->Append(c.field->card_list_name.get());
// check // check
int i = list->GetCount() - 1; int i = list->GetCount() - 1;
list->Check(i, c.settings.visible); list->Check(i, c.settings.visible);
@@ -80,7 +80,7 @@ void CardListColumnSelectDialog::initList() {
void CardListColumnSelectDialog::refreshItem(int i) { void CardListColumnSelectDialog::refreshItem(int i) {
list->Check (i, columns[i].settings.visible); list->Check (i, columns[i].settings.visible);
list->SetString(i, tr(*game, columns[i].field->card_list_name, identity) ); list->SetString(i, columns[i].field->card_list_name.get());
} }
// ----------------------------------------------------------------------------- : Events // ----------------------------------------------------------------------------- : Events
+2 -5
View File
@@ -39,9 +39,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
// draw label // draw label
dc.SetFont(*wxNORMAL_FONT); dc.SetFont(*wxNORMAL_FONT);
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT));
// TODO : tr using stylesheet or using game? dc.DrawText(v.getField()->caption.get(), RealPoint(margin_left - v.bounding_box.x, 1));
dc.DrawText(tr(getStylePackage(), v.getField()->caption, identity),
RealPoint(margin_left - v.bounding_box.x, 1));
} }
// draw viewer // draw viewer
v.draw(dc); v.draw(dc);
@@ -64,8 +62,7 @@ void NativeLookEditor::resizeViewers() {
// width of the label string // width of the label string
int w; int w;
Style& s = *v->getStyle(); Style& s = *v->getStyle();
String text = tr(getStylePackage(), s.fieldP->caption, identity); dc.GetTextExtent(s.fieldP->caption.get(), &w, nullptr);
dc.GetTextExtent(text,&w,nullptr);
label_width = max(label_width, w + label_margin); label_width = max(label_width, w + label_margin);
} }
} }
+7 -3
View File
@@ -145,9 +145,9 @@ private:
// ----------------------------------------------------------------------------- : Collections : maps // ----------------------------------------------------------------------------- : Collections : maps
template <typename V> template <typename Container>
ScriptValueP get_member(const map<String,V>& m, const String& name) { ScriptValueP get_member(const Container& m, const String& name) {
typename map<String,V>::const_iterator it = m.find(name); auto it = m.find(name);
if (it != m.end()) { if (it != m.end()) {
return to_script(it->second); return to_script(it->second);
} else { } else {
@@ -403,6 +403,10 @@ inline ScriptValueP to_script(const map<K,V>* v) {
return make_intrusive<ScriptMap<map<K,V>>>(v); return make_intrusive<ScriptMap<map<K,V>>>(v);
} }
template <typename K, typename V> template <typename K, typename V>
inline ScriptValueP to_script(const unordered_map<K,V>* v) {
return make_intrusive<ScriptMap<unordered_map<K,V>>>(v);
}
template <typename K, typename V>
inline ScriptValueP to_script(const IndexMap<K,V>* v) { inline ScriptValueP to_script(const IndexMap<K,V>* v) {
return make_intrusive<ScriptMap<IndexMap<K,V>>>(v); return make_intrusive<ScriptMap<IndexMap<K,V>>>(v);
} }
+1
View File
@@ -56,6 +56,7 @@ public:
template <typename T> void handle(const Scriptable<T>& ); template <typename T> void handle(const Scriptable<T>& );
template <typename T> void handle(const vector<T>& c) { value = to_script(&c); } template <typename T> void handle(const vector<T>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const map<K,V>& c) { value = to_script(&c); } template <typename K, typename V> void handle(const map<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const unordered_map<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const IndexMap<K,V>& c) { value = to_script(&c); } template <typename K, typename V> void handle(const IndexMap<K,V>& c) { value = to_script(&c); }
template <typename K, typename V> void handle(const DelayedIndexMaps<K,V>&) {} template <typename K, typename V> void handle(const DelayedIndexMaps<K,V>&) {}
template <typename K, typename V> void handle(const DelayedIndexMapsData<K,V>& c); template <typename K, typename V> void handle(const DelayedIndexMapsData<K,V>& c);
+2
View File
@@ -49,9 +49,11 @@ String identity(const String&);
String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity); String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity);
/// Translate 'key' in the for a Package using the current locale /// Translate 'key' in the for a Package using the current locale
[[deprecated]]
String tr(const Package&, const String& key, DefaultLocaleFun def); String tr(const Package&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Package using the current locale /// Translate 'key' in the for a Package using the current locale
[[deprecated]]
String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def); String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
/// A localized string for menus /// A localized string for menus