mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
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:
+35
-19
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user