Localisation, using Locale class

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@113 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2006-12-12 16:09:05 +00:00
parent c2a03bc445
commit ca42f31ccc
24 changed files with 540 additions and 40 deletions
+1 -1
View File
@@ -19,7 +19,7 @@
// ----------------------------------------------------------------------------- : ValueAction
String ValueAction::getName(bool to_undo) const {
return _("Change ") + valueP->fieldP->name;
return String::Format(_ACTION_("change"), valueP->fieldP->name);
}
// ----------------------------------------------------------------------------- : Simple
+49
View File
@@ -0,0 +1,49 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
// ----------------------------------------------------------------------------- : Includes
#include <data/locale.hpp>
#include <util/io/package_manager.hpp>
#include <script/value.hpp>
// ----------------------------------------------------------------------------- : Locale class
LocaleP the_locale;
String Locale::typeName() const { return _("locale"); }
LocaleP Locale::byName(const String& name) {
return packages.open<Locale>(name + _(".mse-locale"));
}
IMPLEMENT_REFLECTION(Locale) {
REFLECT(full_name);
REFLECT_N("menu", translations[LOCALE_CAT_MENU]);
REFLECT_N("help", translations[LOCALE_CAT_HELP]);
REFLECT_N("tool", translations[LOCALE_CAT_TOOL]);
REFLECT_N("label", translations[LOCALE_CAT_LABEL]);
REFLECT_N("button", translations[LOCALE_CAT_BUTTON]);
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);
}
IMPLEMENT_REFLECTION_NAMELESS(GameLocale) {
REFLECT_NAMELESS(translations);
}
// ----------------------------------------------------------------------------- : Translation
// from util/locale.hpp
String tr(LocaleCategory cat, const String& key) {
if (!the_locale) return key; // no locale loaded (yet)
map<String,String>::const_iterator it = the_locale->translations[cat].find(key);
if (it == the_locale->translations[cat].end()) return _("missing:") + key;
return it->second;
}
+51
View File
@@ -0,0 +1,51 @@
//+----------------------------------------------------------------------------+
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
//| License: GNU General Public License 2 or later (see file COPYING) |
//+----------------------------------------------------------------------------+
#ifndef HEADER_DATA_LOCALE
#define HEADER_DATA_LOCALE
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <util/locale.hpp>
#include <util/reflect.hpp>
#include <util/io/package.hpp>
DECLARE_POINTER_TYPE(Locale);
DECLARE_POINTER_TYPE(GameLocale);
// ----------------------------------------------------------------------------- : Locale class
/// Translations of the texts of a game
class GameLocale {
public:
map<String,String> translations;
DECLARE_REFLECTION();
};
/// A collection of translations of messages
class Locale : public Packaged {
public:
/// Name of this locale
String full_name;
/// Translations of UI strings in each category
map<String,String> translations[LOCALE_CAT_MAX];
/// Translations of game specific texts, by game name
map<String,GameLocaleP> game_translations;
/// Open a locale with the given name
static LocaleP byName(const String& name);
protected:
String typeName() const;
DECLARE_REFLECTION();
};
/// The global locale object
extern LocaleP the_locale;
// ----------------------------------------------------------------------------- : EOF
#endif
+3 -3
View File
@@ -77,14 +77,14 @@ void fix_value_207(const ValueP& value) {
void Set::validate(Version file_app_version) {
// are the
if (!game) {
throw Error(_("No game specified for the set"));
throw Error(_ERROR_("no game specified for the set"));
}
if (!stylesheet) {
// TODO : Allow user to select a different style
throw Error(_("No stylesheet specified for the set"));
throw Error(_ERROR_("no stylesheet specified for the set"));
}
if (stylesheet->game != game) {
throw Error(_("stylesheet and set don't refer to the same game, this is an error in the stylesheet file"));
throw Error(_ERROR_("stylesheet and set refer to different game"));
}
// This is our chance to fix version incompatabilities
+2
View File
@@ -89,6 +89,7 @@ Settings::Settings()
, card_notes_height (40)
, updates_url (_("http://magicseteditor.sourceforge.net/updates"))
, check_updates (CHECK_IF_CONNECTED)
, locale (_("en"))
{}
void Settings::addRecentFile(const String& filename) {
@@ -147,6 +148,7 @@ String Settings::settingsFile() {
IMPLEMENT_REFLECTION(Settings) {
tag.addAlias(300, _("style settings"), _("stylesheet settings"));
tag.addAlias(300, _("default style settings"), _("default stylesheet settings"));
REFLECT(locale);
REFLECT(recent_sets);
REFLECT(set_window_maximized);
REFLECT(set_window_width);
+4
View File
@@ -83,6 +83,10 @@ class Settings {
/// Default constructor initializes default settings
Settings();
// --------------------------------------------------- : Locale
String locale;
// --------------------------------------------------- : Recently opened sets
vector<String> recent_sets;
static const UInt max_recent_sets = 4; // store this many recent sets