mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
Merge pull request #43 from haganbmj/localized-strings-wildcard
feat: restore locale level translations for other packages (fixes #41)
This commit is contained in:
@@ -6,6 +6,8 @@ HEAD: new items added as changes are made
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
Features:
|
||||
* Restore reading of package translations from top level locale file. (haganbmj#43)
|
||||
* Bundle other locale files, provide English translations as fallback rather than just using the key name.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
|
||||
+17
-14
@@ -48,7 +48,7 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
}
|
||||
REFLECT(name);
|
||||
REFLECT_LOCALIZED(caption);
|
||||
REFLECT_LOCALIZED(description);
|
||||
REFLECT_LOCALIZED(description); // FIXME: This field is both unused and uninitialized.
|
||||
REFLECT_N("icon", icon_filename);
|
||||
REFLECT(editable);
|
||||
REFLECT(save_value);
|
||||
@@ -65,32 +65,35 @@ IMPLEMENT_REFLECTION(Field) {
|
||||
}
|
||||
|
||||
void Field::after_reading(Version ver) {
|
||||
name = canonical_name_form(name);
|
||||
if(caption.default_.empty()) caption.default_ = name_to_caption(name);
|
||||
if(card_list_name.default_.empty()) card_list_name.default_ = capitalize(caption.default_);
|
||||
name = canonical_name_form(name);
|
||||
if(caption.default_.empty()) caption.default_ = tr(package_relative_filename, name, name_to_caption);
|
||||
if(card_list_name.default_.empty()) card_list_name.default_ = tr(package_relative_filename, caption.default_, capitalize);
|
||||
}
|
||||
|
||||
template <>
|
||||
intrusive_ptr<Field> read_new<Field>(Reader& reader) {
|
||||
intrusive_ptr<Field> field;
|
||||
// there must be a type specified
|
||||
String type;
|
||||
reader.handle(_("type"), type);
|
||||
if (type == _("text")) return make_intrusive<TextField>();
|
||||
else if (type == _("choice")) return make_intrusive<ChoiceField>();
|
||||
else if (type == _("multiple choice")) return make_intrusive<MultipleChoiceField>();
|
||||
else if (type == _("boolean")) return make_intrusive<BooleanField>();
|
||||
else if (type == _("image")) return make_intrusive<ImageField>();
|
||||
else if (type == _("symbol")) return make_intrusive<SymbolField>();
|
||||
else if (type == _("color")) return make_intrusive<ColorField>();
|
||||
else if (type == _("info")) return make_intrusive<InfoField>();
|
||||
else if (type == _("package choice")) return make_intrusive<PackageChoiceField>();
|
||||
if (type == _("text")) field = make_intrusive<TextField>();
|
||||
else if (type == _("choice")) field = make_intrusive<ChoiceField>();
|
||||
else if (type == _("multiple choice")) field = make_intrusive<MultipleChoiceField>();
|
||||
else if (type == _("boolean")) field = make_intrusive<BooleanField>();
|
||||
else if (type == _("image")) field = make_intrusive<ImageField>();
|
||||
else if (type == _("symbol")) field = make_intrusive<SymbolField>();
|
||||
else if (type == _("color")) field = make_intrusive<ColorField>();
|
||||
else if (type == _("info")) field = make_intrusive<InfoField>();
|
||||
else if (type == _("package choice")) field = make_intrusive<PackageChoiceField>();
|
||||
else if (type.empty()) {
|
||||
reader.warning(_ERROR_1_("expected key", _("type")));
|
||||
throw ParseError(_ERROR_("aborting parsing"));
|
||||
} else {
|
||||
reader.warning(_ERROR_1_("unsupported field type", type));
|
||||
throw ParseError(_ERROR_("aborting parsing"));
|
||||
}
|
||||
}
|
||||
field->package_relative_filename = reader.getPackage()->relativeFilename().Clone();
|
||||
return field;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Style
|
||||
|
||||
+2
-1
@@ -59,7 +59,8 @@ public:
|
||||
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
|
||||
Dependencies dependent_scripts; ///< Scripts that depend on values of this field
|
||||
String package_relative_filename;
|
||||
|
||||
/// Creates a new Value corresponding to this Field
|
||||
virtual ValueP newValue() = 0;
|
||||
|
||||
@@ -118,6 +118,24 @@ String tr(const Package& pkg, const String& subcat, const String& key, DefaultLo
|
||||
loc = find_wildcard_and_set(the_locale->package_translations, pkg.relativeFilename());
|
||||
}
|
||||
return loc->tr(subcat, key, def);
|
||||
}
|
||||
|
||||
String tr(const String& pkg_relative_filename, const String& key, DefaultLocaleFun def) {
|
||||
if (!the_locale) return def(key);
|
||||
SubLocaleP loc = the_locale->package_translations[pkg_relative_filename];
|
||||
if (!loc) {
|
||||
loc = find_wildcard_and_set(the_locale->package_translations, pkg_relative_filename);
|
||||
}
|
||||
return loc->tr(key, def);
|
||||
}
|
||||
|
||||
String tr(const String& pkg_relative_filename, const String& subcat, const String& key, DefaultLocaleFun def) {
|
||||
if (!the_locale) return def(key);
|
||||
SubLocaleP loc = the_locale->package_translations[pkg_relative_filename];
|
||||
if (!loc) {
|
||||
loc = find_wildcard_and_set(the_locale->package_translations, pkg_relative_filename);
|
||||
}
|
||||
return loc->tr(subcat, key, def);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : LocalizedString
|
||||
|
||||
+6
-2
@@ -50,11 +50,15 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and
|
||||
|
||||
/// 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);
|
||||
[[deprecated]]
|
||||
String tr(const String&, const String& key, DefaultLocaleFun def);
|
||||
|
||||
/// 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);
|
||||
[[deprecated]]
|
||||
String tr(const String&, const String& subcat, const String& key, DefaultLocaleFun def);
|
||||
|
||||
/// A localized string for menus
|
||||
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
|
||||
|
||||
Reference in New Issue
Block a user