Removed my previous PanicAlert translation hack. Fixed with a better method suggested by BhaaL. The translation is done by a callback in the MsgHandler routine that is set at program start. Added macros PanicAlertT, SuccessAlertT, PanicYesNoT, and AskYesNoT that are identical to the non T versions except those strings will be added by gettext to the po files to be translated. These can and should be used anywhere in the code for strings that should be translated.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6838 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice
2011-01-13 02:05:58 +00:00
parent be5c732254
commit c6e0ea59b9
78 changed files with 17744 additions and 3451 deletions

View File

@ -117,14 +117,6 @@ private:
#include "config.h" // SCons autoconfiguration defines
#endif
#if defined(HAVE_WX) && HAVE_WX
// This should be used to mark c strings as translatable in PanicAlerts but only in
// wxWidgets portions of the code.
#define _wxt(a) (std::string(wxString(wxGetTranslation(wxT(a))).To8BitData()).c_str())
#else
#define _wxt(a) a
#endif
// Windows compatibility
#ifndef _WIN32
#include <limits.h>

View File

@ -25,15 +25,25 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int S
static MsgAlertHandler msg_handler = DefaultMsgHandler;
static bool AlertEnabled = true;
const char* DefaultStringTranslator(const char* text);
static StringTranslator str_translator = DefaultStringTranslator;
/* Select which of these functions that are used for message boxes. If
wxWidgets is enabled we will use wxMsgAlert() that is defined in main.cpp */
wxWidgets is enabled we will use wxMsgAlert() that is defined in Main.cpp */
void RegisterMsgAlertHandler(MsgAlertHandler handler)
{
msg_handler = handler;
}
// Select translation function. For wxWidgets use wxStringTranslator in Main.cpp
void RegisterStringTranslator(StringTranslator translator)
{
str_translator = translator;
}
// enable/disable the alert handler
void SetEnableAlert(bool enable) {
void SetEnableAlert(bool enable)
{
AlertEnabled = enable;
}
@ -45,9 +55,11 @@ bool MsgAlert(const char* caption, bool yes_no, int Style, const char* format, .
char buffer[2048];
bool ret = true;
const char *tr_format = str_translator(format);
va_list args;
va_start(args, format);
CharArrayFromFormatV(buffer, 2047, format, args);
CharArrayFromFormatV(buffer, 2047, tr_format, args);
va_end(args);
ERROR_LOG(MASTER_LOG, "%s: %s", caption, buffer);
@ -74,3 +86,10 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int S
return true;
#endif
}
// Default (non) translator
const char* DefaultStringTranslator(const char* text)
{
return text;
}

View File

@ -27,7 +27,11 @@ enum MSG_TYPE
typedef bool (*MsgAlertHandler)(const char* caption, const char* text,
bool yes_no, int Style);
typedef const char * (*StringTranslator)(const char* text);
void RegisterMsgAlertHandler(MsgAlertHandler handler);
void RegisterStringTranslator(StringTranslator translator);
extern bool MsgAlert(const char* caption, bool yes_no, int Style, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 4, 5)))
@ -41,11 +45,21 @@ void SetEnableAlert(bool enable);
#define PanicAlert(format, ...) MsgAlert("Warning", false, WARNING, format, __VA_ARGS__)
#define PanicYesNo(format, ...) MsgAlert("Warning", true, WARNING, format, __VA_ARGS__)
#define AskYesNo(format, ...) MsgAlert("Question", true, QUESTION, format, __VA_ARGS__)
// Use these macros (that do the same thing) if the message should be translated.
#define SuccessAlertT(format, ...) MsgAlert("Information", false, INFORMATION, format, __VA_ARGS__)
#define PanicAlertT(format, ...) MsgAlert("Warning", false, WARNING, format, __VA_ARGS__)
#define PanicYesNoT(format, ...) MsgAlert("Warning", true, WARNING, format, __VA_ARGS__)
#define AskYesNoT(format, ...) MsgAlert("Question", true, QUESTION, format, __VA_ARGS__)
#else
#define SuccessAlert(format, ...) MsgAlert("Information", false, INFORMATION, format, ##__VA_ARGS__)
#define PanicAlert(format, ...) MsgAlert("Warning", false, WARNING, format, ##__VA_ARGS__)
#define PanicYesNo(format, ...) MsgAlert("Warning", true, WARNING, format, ##__VA_ARGS__)
#define AskYesNo(format, ...) MsgAlert("Question", true, QUESTION, format, ##__VA_ARGS__)
// Use these macros (that do the same thing) if the message should be translated.
#define SuccessAlertT(format, ...) MsgAlert("Information", false, INFORMATION, format, ##__VA_ARGS__)
#define PanicAlertT(format, ...) MsgAlert("Warning", false, WARNING, format, ##__VA_ARGS__)
#define PanicYesNoT(format, ...) MsgAlert("Warning", true, WARNING, format, ##__VA_ARGS__)
#define AskYesNoT(format, ...) MsgAlert("Question", true, QUESTION, format, ##__VA_ARGS__)
#endif
#else
// GEKKO
@ -53,6 +67,10 @@ void SetEnableAlert(bool enable);
#define PanicAlert(format, ...) ;
#define PanicYesNo(format, ...) ;
#define AskYesNo(format, ...) ;
#define SuccessAlertT(format, ...) ;
#define PanicAlertT(format, ...) ;
#define PanicYesNoT(format, ...) ;
#define AskYesNoT(format, ...) ;
#endif
#endif // _MSGHANDLER_H_

View File

@ -47,7 +47,7 @@ bool SysConf::LoadFromFile(const char *filename)
return false; //most likely: file does not exist
if (size != SYSCONF_SIZE)
{
PanicAlert("Your SYSCONF file is the wrong size - should be 0x%04x (but is 0x%04llx)",
PanicAlertT("Your SYSCONF file is the wrong size - should be 0x%04x (but is 0x%04llx)",
SYSCONF_SIZE, size);
return false;
}
@ -117,7 +117,7 @@ bool SysConf::LoadFromFileInternal(FILE *f)
curEntry.dataLength = 4;
break;
default:
PanicAlert("Unknown entry type %i in SYSCONF (%s@%x)!",
PanicAlertT("Unknown entry type %i in SYSCONF (%s@%x)!",
curEntry.type, curEntry.name, curEntry.offset);
return false;
}

View File

@ -95,7 +95,7 @@ public:
{
if (!m_IsValid)
{
PanicAlert("Trying to read from invalid SYSCONF");
PanicAlertT("Trying to read from invalid SYSCONF");
return 0;
}
@ -107,7 +107,7 @@ public:
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
PanicAlertT("Section %s not found in SYSCONF", sectionName);
return 0;
}
@ -118,7 +118,7 @@ public:
{
if (!m_IsValid)
{
PanicAlert("Trying to read from invalid SYSCONF");
PanicAlertT("Trying to read from invalid SYSCONF");
return 0;
}
@ -130,7 +130,7 @@ public:
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
PanicAlertT("Section %s not found in SYSCONF", sectionName);
return 0;
}
@ -150,7 +150,7 @@ public:
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
PanicAlertT("Section %s not found in SYSCONF", sectionName);
return false;
}
@ -171,7 +171,7 @@ public:
}
if (index == m_Entries.size() - 1)
{
PanicAlert("Section %s not found in SYSCONF", sectionName);
PanicAlertT("Section %s not found in SYSCONF", sectionName);
return false;
}