All package specific locales are now under the 'package' key in locale files. Wildcards in package names are supported.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@971 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-06-04 00:57:29 +00:00
parent ae14784fd6
commit 83a0315211
5 changed files with 46 additions and 91 deletions
+5 -52
View File
@@ -798,8 +798,8 @@ type:
points: points
############################################################## Magic
game:
magic:
package:
magic.mse-game:
# Card fields
name: Name
cc: CC
@@ -811,11 +811,8 @@ game:
# Set info
# descriptions/help text
stylesheet:
magic-new:
symbol font:
magic-mana-small:
magic-mana-*.mse-symbol-font:
# note: reminder/shortcut must start with a space, otherwise it is used as a shortcut
# so typing T *anywhere* would insert a symbol (which would be bad)
menu item T: &Tap symbol T
@@ -829,51 +826,7 @@ symbol font:
menu item X: Variable mana &X X
menu item Y: Variable mana &Y Y
menu item Z: Variable mana &Z Z
menu item colorless: &Colorless mana...
title colorless: Colorless mana
message colorless: Enter amount of colorless mana:
menu item half: &Half mana
menu item |W: &White |W
menu item |U: Bl&ue |U
menu item |B: &Black |B
menu item |R: &Red |R
menu item |G: &Green |G
menu item |S: &Snow |S
menu item 1/2: &Colorless 1/2
menu item hybrid: H&ybrid mana (two color)
menu item W/U: White/Blue mana W/U
menu item U/B: Blue/Black mana U/B
menu item B/R: Black/Red mana B/R
menu item R/G: Red/Green mana R/G
menu item G/W: Green/White mana G/W
menu item W/B: White/Black mana W/B
menu item U/R: Blue/Red mana U/R
menu item B/G: Black/Green mana B/G
menu item R/W: Red/White mana R/W
menu item G/U: Green/Blue mana G/U
menu item hybrid 3: H&ybrid mana (three color)
menu item W/U/B: White/Blue/Black mana W/U/B
menu item U/B/R: Blue/Black/Red mana U/B/R
menu item B/R/G: Black/Red/Green mana B/R/G
menu item R/G/W: Red/Green/White mana R/G/W
menu item G/W/U: Green/White/Blue mana G/W/U
menu item W/B/R: White/Black/Red mana W/B/R
menu item U/R/G: Blue/Red/Green mana U/R/G
menu item B/G/W: Black/Green/White mana B/G/W
menu item R/W/U: Red/White/Blue mana R/W/U
menu item G/U/B: Green/Blue/Black mana G/U/B
magic-mana-large:
# Exactly the same
menu item T: &Tap symbol T
menu item W: &White mana W
menu item U: Bl&ue mana U
menu item B: &Black mana B
menu item R: &Red mana R
menu item G: &Green mana G
menu item S: &Snow mana S
menu item X: Variable mana &X X
menu item Y: Variable mana &Y Y
menu item Z: Variable mana &Z Z
menu item I: &Infinite mana I
menu item colorless: &Colorless mana...
title colorless: Colorless mana
message colorless: Enter amount of colorless mana:
+35 -19
View File
@@ -14,12 +14,15 @@
#include <util/io/package_manager.hpp>
#include <script/to_value.hpp>
#include <wx/wfstream.h>
#include <wx/regex.h>
#include <wx/stdpaths.h>
#if defined(__WXMSW__)
#include <wx/mstream.h>
#endif
DECLARE_TYPEOF(map<String COMMA SubLocaleP>);
// ----------------------------------------------------------------------------- : Locale class
LocaleP the_locale;
@@ -42,15 +45,29 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Locale) {
REFLECT_N("action", translations[LOCALE_CAT_ACTION]);
REFLECT_N("error", translations[LOCALE_CAT_ERROR]);
REFLECT_N("type", translations[LOCALE_CAT_TYPE]);
REFLECT_N("game", game_translations);
REFLECT_N("stylesheet", stylesheet_translations);
REFLECT_N("symbol font", symbol_font_translations);
REFLECT_N("package", package_translations);
}
IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
REFLECT_NAMELESS(translations);
}
// ----------------------------------------------------------------------------- : Wildcards
bool match_wildcard(const String& wildcard, const String& name) {
return wxRegEx(replace_all(replace_all(wildcard, _("."), _("\\.")), _("*"), _(".*"))).Matches(name);
}
SubLocaleP find_wildcard(map<String,SubLocaleP>& items, const String& name) {
FOR_EACH_CONST(i, items) {
if (i.second && match_wildcard(i.first, name)) return i.second;
}
return new_intrusive<SubLocale>(); // so we don't search again
}
SubLocaleP find_wildcard_and_set(map<String,SubLocaleP>& items, const String& name) {
return items[name] = find_wildcard(items, name);
}
// ----------------------------------------------------------------------------- : Translation
String warn_and_identity(const String& key) {
@@ -82,24 +99,23 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) {
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 Package& pkg, const String& key, DefaultLocaleFun def) {
if (!the_locale) return def(key);
SubLocaleP loc = the_locale->package_translations[pkg.relativeFilename()];
if (!loc) {
loc = find_wildcard_and_set(the_locale->package_translations, pkg.relativeFilename());
}
return loc->tr(key, def);
}
IMPLEMENT_TR_TYPE(Package, game_translations) //%% TODO!
IMPLEMENT_TR_TYPE(Game, game_translations)
IMPLEMENT_TR_TYPE(StyleSheet, stylesheet_translations)
IMPLEMENT_TR_TYPE(SymbolFont, symbol_font_translations)
String tr(const Package& pkg, const String& subcat, const String& key, DefaultLocaleFun def) {
if (!the_locale) return def(key);
SubLocaleP loc = the_locale->package_translations[pkg.relativeFilename()];
if (!loc) {
loc = find_wildcard_and_set(the_locale->package_translations, pkg.relativeFilename());
}
return loc->tr(subcat, key, def);
}
// ----------------------------------------------------------------------------- : Validation
+2 -6
View File
@@ -40,12 +40,8 @@ class Locale : public Packaged {
public:
/// Translations of UI strings in each category
SubLocale translations[LOCALE_CAT_MAX];
/// Translations of Game specific texts, by game name
map<String,SubLocaleP> game_translations;
/// Translations of StyleSheet specific texts, by stylesheet name
map<String,SubLocaleP> stylesheet_translations;
/// Translations of SymbolFont specific texts, by symbol font name
map<String,SubLocaleP> symbol_font_translations;
/// Translations of Package specific texts, by relativeFilename
map<String,SubLocaleP> package_translations;
/// Open a locale with the given name
static LocaleP byName(const String& name);
+2 -2
View File
@@ -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),
dc.DrawText(tr(getStylePackage(), 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);
String text = tr(getStylePackage(), s.fieldP->name, capitalize_sentence);
dc.GetTextExtent(text,&w,nullptr);
label_width = max(label_width, w + label_margin);
}
+2 -12
View File
@@ -49,19 +49,9 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and
/// Translate 'key' in the for a Package using the current locale
String tr(const Package&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Game using the current locale
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, DefaultLocaleFun def);
/// Translate 'key' in the for a SymbolFont using the current locale
String tr(const SymbolFont&, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Game using the current locale
String tr(const Game&, const String& subcat, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a StyleSheet using the current locale
String tr(const StyleSheet&, const String& subcat, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a SymbolFont using the current locale
String tr(const SymbolFont&, const String& subcat, const String& key, DefaultLocaleFun def);
/// Translate 'key' in the for a Package using the current locale
String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
/// A localized string for menus
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))