mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
nicer options for defaults in localization tr() functions
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@808 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+29
-46
@@ -53,18 +53,23 @@ IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Translation
|
||||
|
||||
String SubLocale::tr(const String& key) {
|
||||
String warn_and_identity(const String& key) {
|
||||
handle_warning(_("Missing key in locale: ") + key, false);
|
||||
return key;
|
||||
}
|
||||
|
||||
String SubLocale::tr(const String& key, DefaultLocaleFun def) {
|
||||
map<String,String>::const_iterator it = translations.find(key);
|
||||
if (it == translations.end()) {
|
||||
return _("missing:") + key;
|
||||
return def(key);
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
String SubLocale::tr(const String& key, const String& def) {
|
||||
map<String,String>::const_iterator it = translations.find(key);
|
||||
String SubLocale::tr(const String& subcat, const String& key, DefaultLocaleFun def) {
|
||||
map<String,String>::const_iterator it = translations.find(subcat + _(" ") + key);
|
||||
if (it == translations.end()) {
|
||||
return def;
|
||||
return def(key);
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
@@ -72,50 +77,28 @@ String SubLocale::tr(const String& key, const String& def) {
|
||||
|
||||
// from util/locale.hpp
|
||||
|
||||
String tr(LocaleCategory cat, const String& key) {
|
||||
if (!the_locale) return key; // no locale loaded (yet)
|
||||
return the_locale->translations[cat].tr(key);
|
||||
String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) {
|
||||
if (!the_locale) return def(key); // no locale loaded (yet)
|
||||
return the_locale->translations[cat].tr(key,def);
|
||||
}
|
||||
|
||||
#define IMPLEMENT_TR_TYPE(Type, type_translations) \
|
||||
String tr(const Type& t, const String& key, DefaultLocaleFun def) { \
|
||||
if (!the_locale) return def(key); \
|
||||
SubLocaleP loc = the_locale->type_translations[t.name()]; \
|
||||
if (!loc) return def(key); \
|
||||
return loc->tr(key, def); \
|
||||
} \
|
||||
String tr(const Type& t, const String& subcat, const String& key, DefaultLocaleFun def) { \
|
||||
if (!the_locale) return def(key); \
|
||||
SubLocaleP loc = the_locale->type_translations[t.name()]; \
|
||||
if (!loc) return def(key); \
|
||||
return loc->tr(subcat, key, def); \
|
||||
}
|
||||
|
||||
String tr(const Game& g, const String& key) {
|
||||
if (!the_locale) return key; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->game_translations[g.name()];
|
||||
if (!loc) return key; // no information on this game
|
||||
return loc->tr(key);
|
||||
}
|
||||
String tr(const StyleSheet& s, const String& key) {
|
||||
if (!the_locale) return key; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->stylesheet_translations[s.name()];
|
||||
if (!loc) return key; // no information on this stylesheet
|
||||
return loc->tr(key);
|
||||
}
|
||||
String tr(const SymbolFont& f, const String& key) {
|
||||
if (!the_locale) return key; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->symbol_font_translations[f.name()];
|
||||
if (!loc) return key; // no information on this symbol font
|
||||
return loc->tr(key);
|
||||
}
|
||||
|
||||
|
||||
String tr(const Game& g, const String& key, const String& def) {
|
||||
if (!the_locale) return def; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->game_translations[g.name()];
|
||||
if (!loc) return def; // no information on this game
|
||||
return loc->tr(key, def);
|
||||
}
|
||||
String tr(const StyleSheet& s, const String& key, const String& def) {
|
||||
if (!the_locale) return def; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->stylesheet_translations[s.name()];
|
||||
if (!loc) return def; // no information on this stylesheet
|
||||
return loc->tr(key, def);
|
||||
}
|
||||
String tr(const SymbolFont& f, const String& key, const String& def) {
|
||||
if (!the_locale) return def; // no locale loaded (yet)
|
||||
SubLocaleP loc = the_locale->symbol_font_translations[f.name()];
|
||||
if (!loc) return def; // no information on this symbol font
|
||||
return loc->tr(key, def);
|
||||
}
|
||||
IMPLEMENT_TR_TYPE(Game, game_translations)
|
||||
IMPLEMENT_TR_TYPE(StyleSheet, stylesheet_translations)
|
||||
IMPLEMENT_TR_TYPE(SymbolFont, symbol_font_translations)
|
||||
|
||||
// ----------------------------------------------------------------------------- : Validation
|
||||
|
||||
|
||||
+3
-4
@@ -25,10 +25,9 @@ class SubLocale : public IntrusivePtrBase<SubLocale> {
|
||||
public:
|
||||
map<String,String> translations;
|
||||
|
||||
/// Translate a key
|
||||
String tr(const String& key);
|
||||
/// Translate a key with a default value
|
||||
String tr(const String& key, const String& def);
|
||||
/// Translate a key, if not found, apply the default function to the key
|
||||
String tr(const String& key, DefaultLocaleFun def);
|
||||
String tr(const String& subcat, const String& key, DefaultLocaleFun def);
|
||||
|
||||
/// Is this a valid sublocale? Returns errors
|
||||
String validate(const String& name, const SubLocaleValidatorP&) const;
|
||||
|
||||
@@ -481,8 +481,8 @@ String InsertSymbolMenu::getCode(int id, const SymbolFont& font) const {
|
||||
} else if (id == 0 && type == ITEM_CODE) {
|
||||
return name;
|
||||
} else if (id == 0 && type == ITEM_CUSTOM) {
|
||||
String caption = tr(font,_("title ") + name, capitalize_sentence(name));
|
||||
String message = tr(font,_("message ") + name, capitalize_sentence(name));
|
||||
String caption = tr(font,_("title"), name, capitalize_sentence);
|
||||
String message = tr(font,_("message"), name, capitalize_sentence);
|
||||
return wxGetTextFromUser(message, caption);
|
||||
}
|
||||
return wxEmptyString;
|
||||
@@ -501,7 +501,7 @@ wxMenu* InsertSymbolMenu::makeMenu(int id, SymbolFont& font) const {
|
||||
}
|
||||
wxMenuItem* InsertSymbolMenu::makeMenuItem(wxMenu* parent, int first_id, SymbolFont& font) const {
|
||||
if (type == ITEM_SUBMENU) {
|
||||
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, tr(font, _("menu item ") + name, name),
|
||||
wxMenuItem* item = new wxMenuItem(parent, wxID_ANY, tr(font, _("menu item"), name, capitalize),
|
||||
wxEmptyString, wxITEM_NORMAL,
|
||||
makeMenu(first_id, font));
|
||||
item->SetBitmap(wxNullBitmap);
|
||||
@@ -510,7 +510,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, tr(font, _("menu item ") + name, name));
|
||||
wxMenuItem* item = new wxMenuItem(parent, first_id, tr(font, _("menu item"), name, capitalize));
|
||||
// Generate bitmap for use on this item
|
||||
SymbolInFont* symbol = nullptr;
|
||||
if (type == ITEM_CUSTOM) {
|
||||
|
||||
@@ -204,7 +204,7 @@ void CardListBase::rebuild() {
|
||||
else if (f.second->card_list_align & ALIGN_CENTER) align = wxLIST_FORMAT_CENTRE;
|
||||
else align = wxLIST_FORMAT_LEFT;
|
||||
InsertColumn((long)column_fields.size(),
|
||||
tr(*set->game, f.second->card_list_name, capitalize(f.second->card_list_name)),
|
||||
tr(*set->game, f.second->card_list_name, capitalize),
|
||||
align, cs.width);
|
||||
column_fields.push_back(f.second);
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ void CardListColumnSelectDialog::initList() {
|
||||
// Init items
|
||||
Color window_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
|
||||
FOR_EACH(c, columns) {
|
||||
list->Append(tr(*game, c.field->card_list_name, capitalize(c.field->card_list_name)));
|
||||
list->Append(tr(*game, c.field->card_list_name, capitalize));
|
||||
// check
|
||||
int i = list->GetCount() - 1;
|
||||
list->Check(i, c.settings.visible);
|
||||
@@ -89,7 +89,7 @@ void CardListColumnSelectDialog::initList() {
|
||||
|
||||
void CardListColumnSelectDialog::refreshItem(int i) {
|
||||
list->Check (i, columns[i].settings.visible);
|
||||
list->SetString(i, tr(*game, columns[i].field->card_list_name, capitalize(columns[i].field->card_list_name)) );
|
||||
list->SetString(i, tr(*game, columns[i].field->card_list_name, capitalize) );
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Events
|
||||
|
||||
@@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
|
||||
// draw label
|
||||
dc.SetFont(*wxNORMAL_FONT);
|
||||
// TODO : tr using stylesheet or using game?
|
||||
dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)),
|
||||
dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence),
|
||||
RealPoint(margin_left - s.left, 1));
|
||||
// draw 3D border
|
||||
draw_control_border(this, dc.getDC(), dc.trRectStraight(s.getInternalRect().grow(1)));
|
||||
@@ -70,7 +70,7 @@ void NativeLookEditor::resizeViewers() {
|
||||
// width of the label string
|
||||
int w;
|
||||
Style& s = *v->getStyle();
|
||||
String text = tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name));
|
||||
String text = tr(*set->game, s.fieldP->name, capitalize_sentence);
|
||||
dc.GetTextExtent(text,&w,nullptr);
|
||||
label_width = max(label_width, w + label_margin);
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ void draw_choice_viewer(RotatedDC& dc, DataViewer& viewer, ChoiceStyle& style, c
|
||||
}
|
||||
}
|
||||
if (style.render_style & RENDER_TEXT) {
|
||||
String text = tr(*viewer.stylesheet, value, capitalize(value));
|
||||
String text = tr(*viewer.stylesheet, value, capitalize_sentence);
|
||||
dc.SetFont(style.font, 1.0);
|
||||
RealPoint pos = align_in_rect(ALIGN_MIDDLE_LEFT, RealSize(0, dc.GetCharHeight()), dc.getInternalRect()) + RealSize(margin, 0);
|
||||
dc.DrawTextWithShadow(text, style.font, pos);
|
||||
|
||||
@@ -74,7 +74,7 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
|
||||
}
|
||||
if (style().render_style & RENDER_TEXT) {
|
||||
// draw text
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize_sentence(choice));
|
||||
String text = tr(*viewer.stylesheet, choice, capitalize_sentence);
|
||||
RealSize text_size = dc.GetTextExtent(text);
|
||||
dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
|
||||
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
|
||||
|
||||
+11
-11
@@ -39,26 +39,26 @@ enum LocaleCategory
|
||||
, LOCALE_CAT_MAX
|
||||
};
|
||||
|
||||
typedef String (*DefaultLocaleFun)(const String&);
|
||||
/// Return the input and issue a warning
|
||||
String warn_and_identity(const String&);
|
||||
|
||||
/// Translate 'key' in the category 'cat' using the current locale
|
||||
String tr(LocaleCategory cat, const String& key);
|
||||
String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and_identity);
|
||||
|
||||
/// Translate 'key' in the for a Game using the current locale
|
||||
String tr(const Game&, const String& key);
|
||||
String tr(const Game&, const String& key, DefaultLocaleFun def);
|
||||
/// Translate 'key' in the for a StyleSheet using the current locale
|
||||
String tr(const StyleSheet&, const String& key);
|
||||
String tr(const StyleSheet&, const String& key, DefaultLocaleFun def);
|
||||
/// Translate 'key' in the for a SymbolFont using the current locale
|
||||
String tr(const SymbolFont&, const String& key);
|
||||
String tr(const SymbolFont&, const String& key, DefaultLocaleFun def);
|
||||
|
||||
/// Translate 'key' in the for a Game using the current locale
|
||||
/** If the key is not found, use the default value */
|
||||
String tr(const Game&, const String& key, const String& def);
|
||||
String tr(const Game&, const String& subcat, const String& key, DefaultLocaleFun def);
|
||||
/// Translate 'key' in the for a StyleSheet using the current locale
|
||||
/** If the key is not found, use the default value */
|
||||
String tr(const StyleSheet&, const String& key, const String& def);
|
||||
String tr(const StyleSheet&, const String& subcat, const String& key, DefaultLocaleFun def);
|
||||
/// Translate 'key' in the for a SymbolFont using the current locale
|
||||
/** If the key is not found, use the default value */
|
||||
String tr(const SymbolFont&, const String& key, const String& def);
|
||||
|
||||
String tr(const SymbolFont&, 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