Browse Source

Internationalization -- initial step, make _ return a std::string to prevent memory leaks

miguelfreitas
Wladimir J. van der Laan 14 years ago
parent
commit
39cf857db9
  1. 1
      src/externui.h
  2. 8
      src/qt/bitcoin.cpp
  3. 1
      src/qt/transactiondesc.cpp
  4. 4
      src/rpc.cpp
  5. 10
      src/util.cpp
  6. 8
      src/util.h

1
src/externui.h

@ -41,5 +41,6 @@ extern bool ThreadSafeAskFee(int64 nFeeRequired, const std::string& strCaption,
extern void CalledSetStatusBar(const std::string& strText, int nField); extern void CalledSetStatusBar(const std::string& strText, int nField);
extern void UIThreadCall(boost::function0<void> fn); extern void UIThreadCall(boost::function0<void> fn);
extern void MainFrameRepaint(); extern void MainFrameRepaint();
extern std::string _(const char* psz);
#endif #endif

8
src/qt/bitcoin.cpp

@ -87,6 +87,14 @@ void MainFrameRepaint()
{ {
} }
/*
Translate string to current locale using Qt.
*/
std::string _(const char* psz)
{
return QCoreApplication::translate("bitcoin-core", psz).toStdString();
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication app(argc, argv); QApplication app(argc, argv);

1
src/qt/transactiondesc.cpp

@ -2,6 +2,7 @@
#include "guiutil.h" #include "guiutil.h"
#include "main.h" #include "main.h"
#include "externui.h"
#include <QString> #include <QString>

4
src/rpc.cpp

@ -40,13 +40,13 @@ Object JSONRPCError(int code, const string& message)
} }
void PrintConsole(const char* format, ...) void PrintConsole(const std::string &format, ...)
{ {
char buffer[50000]; char buffer[50000];
int limit = sizeof(buffer); int limit = sizeof(buffer);
va_list arg_ptr; va_list arg_ptr;
va_start(arg_ptr, format); va_start(arg_ptr, format);
int ret = _vsnprintf(buffer, limit, format, arg_ptr); int ret = _vsnprintf(buffer, limit, format.c_str(), arg_ptr);
va_end(arg_ptr); va_end(arg_ptr);
if (ret < 0 || ret >= limit) if (ret < 0 || ret >= limit)
{ {

10
src/util.cpp

@ -255,8 +255,7 @@ int my_snprintf(char* buffer, size_t limit, const char* format, ...)
return ret; return ret;
} }
string strprintf(const std::string &format, ...)
string strprintf(const char* format, ...)
{ {
char buffer[50000]; char buffer[50000];
char* p = buffer; char* p = buffer;
@ -266,7 +265,7 @@ string strprintf(const char* format, ...)
{ {
va_list arg_ptr; va_list arg_ptr;
va_start(arg_ptr, format); va_start(arg_ptr, format);
ret = _vsnprintf(p, limit, format, arg_ptr); ret = _vsnprintf(p, limit, format.c_str(), arg_ptr);
va_end(arg_ptr); va_end(arg_ptr);
if (ret >= 0 && ret < limit) if (ret >= 0 && ret < limit)
break; break;
@ -283,14 +282,13 @@ string strprintf(const char* format, ...)
return str; return str;
} }
bool error(const std::string &format, ...)
bool error(const char* format, ...)
{ {
char buffer[50000]; char buffer[50000];
int limit = sizeof(buffer); int limit = sizeof(buffer);
va_list arg_ptr; va_list arg_ptr;
va_start(arg_ptr, format); va_start(arg_ptr, format);
int ret = _vsnprintf(buffer, limit, format, arg_ptr); int ret = _vsnprintf(buffer, limit, format.c_str(), arg_ptr);
va_end(arg_ptr); va_end(arg_ptr);
if (ret < 0 || ret >= limit) if (ret < 0 || ret >= limit)
{ {

8
src/util.h

@ -140,14 +140,14 @@ inline int myclosesocket(SOCKET& hSocket)
return ret; return ret;
} }
#define closesocket(s) myclosesocket(s) #define closesocket(s) myclosesocket(s)
#if 0
#ifndef GUI #ifndef GUI
inline const char* _(const char* psz) inline const char* _(const char* psz)
{ {
return psz; return psz;
} }
#endif #endif
#endif
@ -177,8 +177,8 @@ void RandAddSeed();
void RandAddSeedPerfmon(); void RandAddSeedPerfmon();
int OutputDebugStringF(const char* pszFormat, ...); int OutputDebugStringF(const char* pszFormat, ...);
int my_snprintf(char* buffer, size_t limit, const char* format, ...); int my_snprintf(char* buffer, size_t limit, const char* format, ...);
std::string strprintf(const char* format, ...); std::string strprintf(const std::string &format, ...);
bool error(const char* format, ...); bool error(const std::string &format, ...);
void LogException(std::exception* pex, const char* pszThread); void LogException(std::exception* pex, const char* pszThread);
void PrintException(std::exception* pex, const char* pszThread); void PrintException(std::exception* pex, const char* pszThread);
void PrintExceptionContinue(std::exception* pex, const char* pszThread); void PrintExceptionContinue(std::exception* pex, const char* pszThread);

Loading…
Cancel
Save