Clean up translator callback.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@6842 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Glenn Rice 2011-01-14 00:15:08 +00:00
parent 984b0d14d2
commit a747cb548c
3 changed files with 13 additions and 15 deletions

View File

@ -25,7 +25,7 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int S
static MsgAlertHandler msg_handler = DefaultMsgHandler; static MsgAlertHandler msg_handler = DefaultMsgHandler;
static bool AlertEnabled = true; static bool AlertEnabled = true;
const char* DefaultStringTranslator(const char* text); std::string DefaultStringTranslator(const char* text);
static StringTranslator str_translator = DefaultStringTranslator; static StringTranslator str_translator = DefaultStringTranslator;
/* Select which of these functions that are used for message boxes. If /* Select which of these functions that are used for message boxes. If
@ -62,9 +62,9 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...)
if (!info_caption.length()) if (!info_caption.length())
{ {
info_caption = std::string(str_translator(_trans("Information"))); info_caption = str_translator(_trans("Information"));
ques_caption = std::string(str_translator(_trans("Question"))); ques_caption = str_translator(_trans("Question"));
warn_caption = std::string(str_translator(_trans("Warning"))); warn_caption = str_translator(_trans("Warning"));
} }
switch(Style) switch(Style)
@ -80,11 +80,9 @@ bool MsgAlert(bool yes_no, int Style, const char* format, ...)
break; break;
} }
const char *tr_format = str_translator(format);
va_list args; va_list args;
va_start(args, format); va_start(args, format);
CharArrayFromFormatV(buffer, 2047, tr_format, args); CharArrayFromFormatV(buffer, 2047, str_translator(format).c_str(), args);
va_end(args); va_end(args);
ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer); ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer);
@ -113,7 +111,7 @@ bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int S
} }
// Default (non) translator // Default (non) translator
const char* DefaultStringTranslator(const char* text) std::string DefaultStringTranslator(const char* text)
{ {
return text; return text;
} }

View File

@ -17,6 +17,9 @@
#ifndef _MSGHANDLER_H_ #ifndef _MSGHANDLER_H_
#define _MSGHANDLER_H_ #define _MSGHANDLER_H_
#include <string>
// Message alerts // Message alerts
enum MSG_TYPE enum MSG_TYPE
{ {
@ -27,7 +30,7 @@ enum MSG_TYPE
typedef bool (*MsgAlertHandler)(const char* caption, const char* text, typedef bool (*MsgAlertHandler)(const char* caption, const char* text,
bool yes_no, int Style); bool yes_no, int Style);
typedef const char * (*StringTranslator)(const char* text); typedef std::string (*StringTranslator)(const char* text);
void RegisterMsgAlertHandler(MsgAlertHandler handler); void RegisterMsgAlertHandler(MsgAlertHandler handler);
void RegisterStringTranslator(StringTranslator translator); void RegisterStringTranslator(StringTranslator translator);

View File

@ -56,7 +56,7 @@ END_EVENT_TABLE()
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
bool wxMsgAlert(const char*, const char*, bool, int); bool wxMsgAlert(const char*, const char*, bool, int);
const char *wxStringTranslator(const char *); std::string wxStringTranslator(const char *);
CFrame* main_frame = NULL; CFrame* main_frame = NULL;
@ -471,12 +471,9 @@ bool wxMsgAlert(const char* caption, const char* text, bool yes_no, int /*Style*
#endif #endif
} }
const char *wxStringTranslator(const char *text) std::string wxStringTranslator(const char *text)
{ {
static char buffer[2048]; return (const char *)wxString(wxGetTranslation(wxString::From8BitData(text))).ToUTF8();
snprintf(buffer, 2048, "%s",
(const char *)wxString(wxGetTranslation(wxString::From8BitData(text))).ToUTF8());
return buffer;
} }
// Accessor for the main window class // Accessor for the main window class