Commit e78d3fa0 authored by twanvl's avatar twanvl

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

All package specific locales are now under the 'package' key in locale files. Wildcards in package names are supported.
parent 3e0ee813
...@@ -798,8 +798,8 @@ type: ...@@ -798,8 +798,8 @@ type:
points: points points: points
############################################################## Magic ############################################################## Magic
game: package:
magic: magic.mse-game:
# Card fields # Card fields
name: Name name: Name
cc: CC cc: CC
...@@ -811,11 +811,8 @@ game: ...@@ -811,11 +811,8 @@ game:
# Set info # Set info
# descriptions/help text # descriptions/help text
stylesheet:
magic-new: magic-mana-*.mse-symbol-font:
symbol font:
magic-mana-small:
# note: reminder/shortcut must start with a space, otherwise it is used as a shortcut # 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) # so typing T *anywhere* would insert a symbol (which would be bad)
menu item T: &Tap symbol T menu item T: &Tap symbol T
...@@ -829,51 +826,7 @@ symbol font: ...@@ -829,51 +826,7 @@ symbol font:
menu item X: Variable mana &X X menu item X: Variable mana &X X
menu item Y: Variable mana &Y Y menu item Y: Variable mana &Y Y
menu item Z: Variable mana &Z Z menu item Z: Variable mana &Z Z
menu item colorless: &Colorless mana... menu item I: &Infinite mana I
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 colorless: &Colorless mana... menu item colorless: &Colorless mana...
title colorless: Colorless mana title colorless: Colorless mana
message colorless: Enter amount of colorless mana: message colorless: Enter amount of colorless mana:
......
...@@ -14,12 +14,15 @@ ...@@ -14,12 +14,15 @@
#include <util/io/package_manager.hpp> #include <util/io/package_manager.hpp>
#include <script/to_value.hpp> #include <script/to_value.hpp>
#include <wx/wfstream.h> #include <wx/wfstream.h>
#include <wx/regex.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#if defined(__WXMSW__) #if defined(__WXMSW__)
#include <wx/mstream.h> #include <wx/mstream.h>
#endif #endif
DECLARE_TYPEOF(map<String COMMA SubLocaleP>);
// ----------------------------------------------------------------------------- : Locale class // ----------------------------------------------------------------------------- : Locale class
LocaleP the_locale; LocaleP the_locale;
...@@ -42,15 +45,29 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Locale) { ...@@ -42,15 +45,29 @@ IMPLEMENT_REFLECTION_NO_SCRIPT(Locale) {
REFLECT_N("action", translations[LOCALE_CAT_ACTION]); REFLECT_N("action", translations[LOCALE_CAT_ACTION]);
REFLECT_N("error", translations[LOCALE_CAT_ERROR]); REFLECT_N("error", translations[LOCALE_CAT_ERROR]);
REFLECT_N("type", translations[LOCALE_CAT_TYPE]); REFLECT_N("type", translations[LOCALE_CAT_TYPE]);
REFLECT_N("game", game_translations); REFLECT_N("package", package_translations);
REFLECT_N("stylesheet", stylesheet_translations);
REFLECT_N("symbol font", symbol_font_translations);
} }
IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) { IMPLEMENT_REFLECTION_NO_GET_MEMBER(SubLocale) {
REFLECT_NAMELESS(translations); 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 // ----------------------------------------------------------------------------- : Translation
String warn_and_identity(const String& key) { String warn_and_identity(const String& key) {
...@@ -82,24 +99,23 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) { ...@@ -82,24 +99,23 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def) {
return the_locale->translations[cat].tr(key,def); return the_locale->translations[cat].tr(key,def);
} }
#define IMPLEMENT_TR_TYPE(Type, type_translations) \ String tr(const Package& pkg, const String& key, DefaultLocaleFun def) {
String tr(const Type& t, const String& key, DefaultLocaleFun def) { \ if (!the_locale) return def(key);
if (!the_locale) return def(key); \ SubLocaleP loc = the_locale->package_translations[pkg.relativeFilename()];
SubLocaleP loc = the_locale->type_translations[t.name()]; \ if (!loc) {
if (!loc) return def(key); \ loc = find_wildcard_and_set(the_locale->package_translations, pkg.relativeFilename());
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); \
} }
return loc->tr(key, def);
}
IMPLEMENT_TR_TYPE(Package, game_translations) //%% TODO! String tr(const Package& pkg, const String& subcat, const String& key, DefaultLocaleFun def) {
IMPLEMENT_TR_TYPE(Game, game_translations) if (!the_locale) return def(key);
IMPLEMENT_TR_TYPE(StyleSheet, stylesheet_translations) SubLocaleP loc = the_locale->package_translations[pkg.relativeFilename()];
IMPLEMENT_TR_TYPE(SymbolFont, symbol_font_translations) if (!loc) {
loc = find_wildcard_and_set(the_locale->package_translations, pkg.relativeFilename());
}
return loc->tr(subcat, key, def);
}
// ----------------------------------------------------------------------------- : Validation // ----------------------------------------------------------------------------- : Validation
......
...@@ -40,12 +40,8 @@ class Locale : public Packaged { ...@@ -40,12 +40,8 @@ class Locale : public Packaged {
public: public:
/// Translations of UI strings in each category /// Translations of UI strings in each category
SubLocale translations[LOCALE_CAT_MAX]; SubLocale translations[LOCALE_CAT_MAX];
/// Translations of Game specific texts, by game name /// Translations of Package specific texts, by relativeFilename
map<String,SubLocaleP> game_translations; map<String,SubLocaleP> package_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;
/// Open a locale with the given name /// Open a locale with the given name
static LocaleP byName(const String& name); static LocaleP byName(const String& name);
......
...@@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) { ...@@ -44,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
// draw label // draw label
dc.SetFont(*wxNORMAL_FONT); dc.SetFont(*wxNORMAL_FONT);
// TODO : tr using stylesheet or using game? // 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)); RealPoint(margin_left - s.left, 1));
// draw 3D border // draw 3D border
draw_control_border(this, dc.getDC(), dc.trRectStraight(s.getInternalRect().grow(1))); draw_control_border(this, dc.getDC(), dc.trRectStraight(s.getInternalRect().grow(1)));
...@@ -70,7 +70,7 @@ void NativeLookEditor::resizeViewers() { ...@@ -70,7 +70,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(*set->game, s.fieldP->name, capitalize_sentence); String text = tr(getStylePackage(), s.fieldP->name, capitalize_sentence);
dc.GetTextExtent(text,&w,nullptr); dc.GetTextExtent(text,&w,nullptr);
label_width = max(label_width, w + label_margin); label_width = max(label_width, w + label_margin);
} }
......
...@@ -49,19 +49,9 @@ String tr(LocaleCategory cat, const String& key, DefaultLocaleFun def = warn_and ...@@ -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 /// Translate 'key' in the for a Package using the current locale
String tr(const Package&, const String& key, DefaultLocaleFun def); 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 Package using the current locale
/// Translate 'key' in the for a StyleSheet using the current locale String tr(const Package&, const String& subcat, const String& key, DefaultLocaleFun def);
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);
/// A localized string for menus /// A localized string for menus
#define _MENU_(s) tr(LOCALE_CAT_MENU, _(s)) #define _MENU_(s) tr(LOCALE_CAT_MENU, _(s))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment