From 8ca4c1dec5c821c238c55563acc9fb9057329264 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Mon, 22 Sep 2014 12:54:26 +0200 Subject: [PATCH] Make sure user visible strings are translated --- vncviewer/CConn.cxx | 10 +-- vncviewer/DesktopWindow.cxx | 6 +- vncviewer/FLTKPixelBuffer.cxx | 3 +- vncviewer/OSXPixelBuffer.cxx | 3 +- vncviewer/Win32PixelBuffer.cxx | 9 +-- vncviewer/X11PixelBuffer.cxx | 9 +-- vncviewer/parameters.cxx | 126 ++++++++++++++++++--------------- vncviewer/vncviewer.cxx | 8 +-- 8 files changed, 96 insertions(+), 78 deletions(-) diff --git a/vncviewer/CConn.cxx b/vncviewer/CConn.cxx index 858840c7..23f07b4d 100644 --- a/vncviewer/CConn.cxx +++ b/vncviewer/CConn.cxx @@ -381,7 +381,7 @@ void CConn::framebufferUpdateEnd() void CConn::setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs) { - vlog.error("Invalid SetColourMapEntries from server!"); + vlog.error(_("Invalid SetColourMapEntries from server!")); } void CConn::bell() @@ -426,15 +426,15 @@ void CConn::dataRect(const Rect& r, int encoding) lastServerEncoding = encoding; if (!Decoder::supported(encoding)) { - fprintf(stderr, "Unknown rect encoding %d\n", encoding); - throw Exception("Unknown rect encoding"); + vlog.error(_("Unknown rect encoding %d"), encoding); + throw Exception(_("Unknown rect encoding")); } if (!decoders[encoding]) { decoders[encoding] = Decoder::createDecoder(encoding, this); if (!decoders[encoding]) { - fprintf(stderr, "Unknown rect encoding %d\n", encoding); - throw Exception("Unknown rect encoding"); + vlog.error(_("Unknown rect encoding %d"), encoding); + throw Exception(_("Unknown rect encoding")); } } decoders[encoding]->readRect(r, desktop->getFramebuffer()); diff --git a/vncviewer/DesktopWindow.cxx b/vncviewer/DesktopWindow.cxx index d57d57ad..3579618e 100644 --- a/vncviewer/DesktopWindow.cxx +++ b/vncviewer/DesktopWindow.cxx @@ -103,7 +103,7 @@ DesktopWindow::DesktopWindow(int w, int h, const char *name, break; default: geom_x = geom_y = 0; - vlog.error("Invalid geometry specified!"); + vlog.error(_("Invalid geometry specified!")); } } } @@ -324,7 +324,7 @@ void DesktopWindow::resize(int x, int y, int w, int h) Fl::screen_xywh(sx, sy, sw, sh, i); if ((sx == x) && (sy == y) && (sw == w) && (sh == h)) { - vlog.info("Adjusting window size to avoid accidental full screen request"); + vlog.info(_("Adjusting window size to avoid accidental full screen request")); // Assume a panel of some form and adjust the height y += 20; h -= 40; @@ -794,7 +794,7 @@ void DesktopWindow::remoteResize(int width, int height) cc->cp.width, cc->cp.height, width, height, layout.num_screens()); if (!layout.validate(width, height)) { - vlog.error("Invalid screen layout computed for resize request!"); + vlog.error(_("Invalid screen layout computed for resize request!")); return; } diff --git a/vncviewer/FLTKPixelBuffer.cxx b/vncviewer/FLTKPixelBuffer.cxx index 588e2f83..1eafe103 100644 --- a/vncviewer/FLTKPixelBuffer.cxx +++ b/vncviewer/FLTKPixelBuffer.cxx @@ -20,6 +20,7 @@ #include +#include "i18n.h" #include "FLTKPixelBuffer.h" FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) : @@ -29,7 +30,7 @@ FLTKPixelBuffer::FLTKPixelBuffer(int width, int height) : { data = new rdr::U8[width * height * format.bpp/8]; if (data == NULL) - throw rfb::Exception("Error: Not enough memory for framebuffer"); + throw rfb::Exception(_("Error: Not enough memory for framebuffer")); } FLTKPixelBuffer::~FLTKPixelBuffer() diff --git a/vncviewer/OSXPixelBuffer.cxx b/vncviewer/OSXPixelBuffer.cxx index d196497f..df82c86f 100644 --- a/vncviewer/OSXPixelBuffer.cxx +++ b/vncviewer/OSXPixelBuffer.cxx @@ -30,6 +30,7 @@ #include #include +#include "i18n.h" #include "OSXPixelBuffer.h" using namespace rfb; @@ -46,7 +47,7 @@ OSXPixelBuffer::OSXPixelBuffer(int width, int height) : data = new rdr::U8[width * height * format.bpp/8]; if (data == NULL) - throw rfb::Exception("Error: Not enough memory for framebuffer"); + throw rfb::Exception(_("Error: Not enough memory for framebuffer")); lut = CGColorSpaceCreateDeviceRGB(); assert(lut); diff --git a/vncviewer/Win32PixelBuffer.cxx b/vncviewer/Win32PixelBuffer.cxx index 9fb04145..48718165 100644 --- a/vncviewer/Win32PixelBuffer.cxx +++ b/vncviewer/Win32PixelBuffer.cxx @@ -31,6 +31,7 @@ #include #include +#include "i18n.h" #include "Win32PixelBuffer.h" using namespace rfb; @@ -59,7 +60,7 @@ Win32PixelBuffer::Win32PixelBuffer(int width, int height) : DIB_RGB_COLORS, (void**)&data, NULL, 0); if (!bitmap) { int err = GetLastError(); - throw rdr::SystemException("unable to create DIB section", err); + throw rdr::SystemException(_("unable to create DIB section"), err); } } @@ -76,10 +77,10 @@ void Win32PixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) dc = CreateCompatibleDC(fl_gc); if (!dc) - throw rdr::SystemException("CreateCompatibleDC failed", GetLastError()); + throw rdr::SystemException(_("CreateCompatibleDC failed"), GetLastError()); if (!SelectObject(dc, bitmap)) - throw rdr::SystemException("SelectObject failed", GetLastError()); + throw rdr::SystemException(_("SelectObject failed"), GetLastError()); if (!BitBlt(fl_gc, x, y, w, h, dc, src_x, src_y, SRCCOPY)) { // If the desktop we're rendering to is inactive (like when the screen @@ -88,7 +89,7 @@ void Win32PixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) // with it. For now, we've only seen this error and for this function // so only ignore this combination. if (GetLastError() != ERROR_INVALID_HANDLE) - throw rdr::SystemException("BitBlt failed", GetLastError()); + throw rdr::SystemException(_("BitBlt failed"), GetLastError()); } DeleteDC(dc); diff --git a/vncviewer/X11PixelBuffer.cxx b/vncviewer/X11PixelBuffer.cxx index c709984b..b729e800 100644 --- a/vncviewer/X11PixelBuffer.cxx +++ b/vncviewer/X11PixelBuffer.cxx @@ -29,6 +29,7 @@ #include #include +#include "i18n.h" #include "X11PixelBuffer.h" using namespace rfb; @@ -56,7 +57,7 @@ static PixelFormat display_pf() if (format[i].depth == fl_visual->depth) break; if (i == nformats) - throw rfb::Exception("Error: display lacks pixmap format for default depth"); + throw rfb::Exception(_("Error: display lacks pixmap format for default depth")); switch (format[i].bits_per_pixel) { case 8: @@ -65,7 +66,7 @@ static PixelFormat display_pf() bpp = format[i].bits_per_pixel; break; default: - throw rfb::Exception("Error: couldn't find suitable pixmap format"); + throw rfb::Exception(_("Error: couldn't find suitable pixmap format")); } XFree(format); @@ -74,9 +75,9 @@ static PixelFormat display_pf() trueColour = (fl_visual->c_class == TrueColor); if (!trueColour) - throw rfb::Exception("Error: only true colour displays supported"); + throw rfb::Exception(_("Error: only true colour displays supported")); - vlog.info("Using default colormap and visual, %sdepth %d.", + vlog.info(_("Using default colormap and visual, %sdepth %d."), (fl_visual->c_class == TrueColor) ? "TrueColor, " : ((fl_visual->c_class == PseudoColor) ? "PseudoColor, " : ""), fl_visual->depth); diff --git a/vncviewer/parameters.cxx b/vncviewer/parameters.cxx index b7b33b50..9297a165 100644 --- a/vncviewer/parameters.cxx +++ b/vncviewer/parameters.cxx @@ -44,6 +44,8 @@ #include #include +#include "i18n.h" + using namespace rfb; static LogWriter vlog("Parameters"); @@ -195,8 +197,9 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { strncpy(dest+pos, "\\\\", 2); pos++; if (pos >= destSize) { - vlog.error("Encoding backslash: The size of the buffer dest is to small, " - "it needs to be more than %d bytes bigger.", (destSize - 1 - i)); + vlog.error(_("Encoding backslash: The size of the buffer dest " + "is to small, it needs to be more than %d bytes bigger."), + (destSize - 1 - i)); return false; } @@ -208,8 +211,9 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { dest[pos] = '\\'; pos++; if (pos >= destSize) { - vlog.error("Encoding escape sequence: The size of the buffer dest is to small, " - "it needs to be more than %d bytes bigger.", (destSize - 1 - i)); + vlog.error(_("Encoding escape sequence: The size of the buffer " + "dest is to small, it needs to be more than %d bytes " + "bigger."), (destSize - 1 - i)); return false; } @@ -226,8 +230,9 @@ bool encodeValue(const char* val, char* dest, size_t destSize) { pos++; if (pos >= destSize) { - vlog.error("Encoding normal character: The size of the buffer dest is to small, " - "it needs to be more than %d bytes bigger.", (destSize - 1 - i)); + vlog.error(_("Encoding normal character: The size of the buffer dest " + "is to small, it needs to be more than %d bytes bigger."), + (destSize - 1 - i)); return false; } @@ -262,7 +267,7 @@ bool decodeValue(const char* val, char* dest, size_t destSize) { dest[pos] = val[i]; i++; } else { - vlog.error("Unknown escape sequence at character %d", i); + vlog.error(_("Unknown escape sequence at character %d"), i); return false; } } @@ -274,8 +279,8 @@ bool decodeValue(const char* val, char* dest, size_t destSize) { escapedCharacter = false; // Reset for next loop pos++; if (pos >= destSize) { - vlog.error("Decoding: The size of the buffer dest is to small, " - "it needs to be 1 byte bigger."); + vlog.error(_("Decoding: The size of the buffer dest is to small, " + "it needs to be 1 byte bigger.")); return false; } } @@ -293,29 +298,31 @@ void setKeyString(const char *_name, const char *_value, HKEY* hKey) { wchar_t name[buffersize]; unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) { - vlog.error("Could not convert the parameter-name %s to wchar_t* when " - "writing to the Registry, the buffersize is to small.", _name); + vlog.error(_("Could not convert the parameter-name %s to wchar_t* when " + "writing to the Registry, the buffersize is to small."), + _name); return; } char encodingBuffer[buffersize]; if (!encodeValue(_value, encodingBuffer, buffersize)) { - vlog.error("Could not encode the parameter-value %s when " - "writing to the Registry.", _value); + vlog.error(_("Could not encode the parameter-value %s when " + "writing to the Registry."), _value); return; } wchar_t value[buffersize]; size = fl_utf8towc(encodingBuffer, strlen(encodingBuffer)+1, value, buffersize); if (size >= buffersize) { - vlog.error("Could not convert the parameter-value %s to wchar_t* when " - "writing to the Registry, the buffersize is to small.", _value); + vlog.error(_("Could not convert the parameter-value %s to wchar_t* when " + "writing to the Registry, the buffersize is to small."), + _value); return; } LONG res = RegSetValueExW(*hKey, name, 0, REG_SZ, (BYTE*)&value, (wcslen(value)+1)*2); if (res != ERROR_SUCCESS) { - vlog.error("Error(%d) writing %s(REG_SZ) to Registry.", res, _value); + vlog.error(_("Error(%d) writing %s(REG_SZ) to Registry."), res, _value); return; } } @@ -329,14 +336,15 @@ void setKeyInt(const char *_name, const int _value, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) { - vlog.error("Could not convert the parameter-name %s to wchar_t* when " - "writing to the Registry, the buffersize is to small.", _name); + vlog.error(_("Could not convert the parameter-name %s to wchar_t* when " + "writing to the Registry, the buffersize is to small."), + _name); return; } LONG res = RegSetValueExW(*hKey, name, 0, REG_DWORD, (BYTE*)&value, sizeof(DWORD)); if (res != ERROR_SUCCESS) { - vlog.error("Error(%d) writing %d(REG_DWORD) to Registry.", res, _value); + vlog.error(_("Error(%d) writing %d(REG_DWORD) to Registry."), res, _value); return; } } @@ -350,8 +358,9 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) { - vlog.error("Could not convert the parameter-name %s to wchar_t* when " - "reading from the Registry, the buffersize is to small.", _name); + vlog.error(_("Could not convert the parameter-name %s to wchar_t* when " + "reading from the Registry, the buffersize is to small."), + _name); return false; } @@ -360,7 +369,7 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { if (res == ERROR_FILE_NOT_FOUND) { // The value does not exist, defaults will be used. } else { - vlog.error("Error(%d) reading %s from Registry.", res, _name); + vlog.error(_("Error(%d) reading %s from Registry."), res, _name); } return false; } @@ -368,9 +377,9 @@ bool getKeyString(const char* _name, char* dest, size_t destSize, HKEY* hKey) { char utf8val[destSize]; size = fl_utf8fromwc(utf8val, sizeof(utf8val), value, wcslen(value)+1); if (size >= sizeof(utf8val)) { - vlog.error("Could not convert the parameter-value for %s to utf8 char* " - "when reading from the Registry, the buffer dest is to small.", - _name); + vlog.error(_("Could not convert the parameter-value for %s to utf8 " + "char* when reading from the Registry, the buffer dest is " + "to small."), _name); return false; } const char *ret = utf8val; @@ -391,8 +400,9 @@ bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { unsigned size = fl_utf8towc(_name, strlen(_name)+1, name, buffersize); if (size >= buffersize) { - vlog.error("Could not convert the parameter-name %s to wchar_t* when " - "reading from the Registry, the buffersize is to small.", _name); + vlog.error(_("Could not convert the parameter-name %s to wchar_t* when " + "reading from the Registry, the buffersize is to small."), + _name); return false; } @@ -401,7 +411,7 @@ bool getKeyInt(const char* _name, int* dest, HKEY* hKey) { if (res == ERROR_FILE_NOT_FOUND) { // The value does not exist, defaults will be used. } else { - vlog.error("Error(%d) reading %s from Registry.", res, _name); + vlog.error(_("Error(%d) reading %s from Registry."), res, _name); } return false; } @@ -418,7 +428,7 @@ void saveToReg(const char* servername) { LONG res = RegCreateKeyExW(HKEY_CURRENT_USER, L"Software\\TigerVNC\\vncviewer", 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL); if (res != ERROR_SUCCESS) { - vlog.error("Error(%d) creating key: Software\\TigerVNC\\vncviewer", res); + vlog.error(_("Error(%d) creating key: Software\\TigerVNC\\vncviewer"), res); return; } @@ -432,13 +442,14 @@ void saveToReg(const char* servername) { } else if (dynamic_cast(parameterArray[i]) != NULL) { setKeyInt(parameterArray[i]->getName(), (int)*(BoolParameter*)parameterArray[i], &hKey); } else { - vlog.info("The parameterArray contains a object of a invalid type at line %d.", i); + vlog.info(_("The parameterArray contains a object of a invalid type " + "at line %d."), i); } } res = RegCloseKey(hKey); if (res != ERROR_SUCCESS) { - vlog.error("Error(%d) closing key: Software\\TigerVNC\\vncviewer", res); + vlog.error(_("Error(%d) closing key: Software\\TigerVNC\\vncviewer"), res); } } @@ -453,7 +464,7 @@ char* loadFromReg() { if (res == ERROR_FILE_NOT_FOUND) { // The key does not exist, defaults will be used. } else { - vlog.error("Error(%d) opening key: Software\\TigerVNC\\vncviewer", res); + vlog.error(_("Error(%d) opening key: Software\\TigerVNC\\vncviewer"), res); } return NULL; } @@ -479,13 +490,13 @@ char* loadFromReg() { if (getKeyInt(parameterArray[i]->getName(), &intValue, &hKey)) ((BoolParameter*)parameterArray[i])->setParam(intValue); } else { - vlog.info("The parameterArray contains a object of a invalid type at line %d.", i); + vlog.info(_("The parameterArray contains a object of a invalid type at line %d."), i); } } res = RegCloseKey(hKey); if (res != ERROR_SUCCESS){ - vlog.error("Error(%d) closing key: Software\\TigerVNC\\vncviewer", res); + vlog.error(_("Error(%d) closing key: Software\\TigerVNC\\vncviewer"), res); } return servername; @@ -510,8 +521,8 @@ void saveViewerParameters(const char *filename, const char *servername) { char* homeDir = NULL; if (getvnchomedir(&homeDir) == -1) { - vlog.error("Failed to write configuration file, " - "can't obtain home directory path."); + vlog.error(_("Failed to write configuration file, can't obtain home " + "directory path.")); return; } @@ -524,7 +535,7 @@ void saveViewerParameters(const char *filename, const char *servername) { FILE* f = fopen(filepath, "w+"); if (!f) { snprintf(write_error, sizeof(write_error), - "Failed to write configuration file, can't open %s", filepath); + _("Failed to write configuration file, can't open %s"), filepath); throw Exception(write_error); } @@ -543,7 +554,8 @@ void saveViewerParameters(const char *filename, const char *servername) { } else if (dynamic_cast(parameterArray[i]) != NULL) { fprintf(f, "%s=%d\n", ((BoolParameter*)parameterArray[i])->getName(), (int)*(BoolParameter*)parameterArray[i]); } else { - vlog.info("The parameterArray contains a object of a invalid type at line %d.", i); + vlog.info(_("The parameterArray contains a object of a invalid type " + "at line %d."), i); } } fclose(f); @@ -569,8 +581,8 @@ char* loadViewerParameters(const char *filename) { char* homeDir = NULL; if (getvnchomedir(&homeDir) == -1) - throw Exception("Failed to read configuration file, " - "can't obtain home directory path."); + throw Exception(_("Failed to read configuration file, " + "can't obtain home directory path.")); snprintf(filepath, sizeof(filepath), "%sdefault.tigervnc", homeDir); } else { @@ -582,8 +594,8 @@ char* loadViewerParameters(const char *filename) { if (!f) { if (!filename) return NULL; // Use defaults. - snprintf(readError, sizeof(readError), "Failed to read configuration file, " - "can't open %s", filepath); + snprintf(readError, sizeof(readError), + _("Failed to read configuration file, can't open %s"), filepath); throw Exception(readError); } @@ -594,15 +606,15 @@ char* loadViewerParameters(const char *filename) { lineNr++; if (!fgets(line, sizeof(line), f)) { if (line[sizeof(line) -1] != '\0') { - vlog.error("Could not read the line(%d) in the configuration file," - "the buffersize is to small.", lineNr); + vlog.error(_("Could not read the line(%d) in the configuration file," + "the buffersize is to small."), lineNr); return NULL; } if (feof(f)) break; - snprintf(readError, sizeof(readError), "Failed to read line %d in file %s", - lineNr, filepath); + snprintf(readError, sizeof(readError), + _("Failed to read line %d in file %s"), lineNr, filepath); throw Exception(readError); } @@ -611,9 +623,10 @@ char* loadViewerParameters(const char *filename) { if(strncmp(line, IDENTIFIER_STRING, strlen(IDENTIFIER_STRING)) == 0) { continue; } else { - snprintf(readError, sizeof(readError), "Line 1 in file %s\n" - "must contain the TigerVNC configurationfile identifier string:\n" - "\"%s\"", filepath, IDENTIFIER_STRING); + snprintf(readError, sizeof(readError), + _("Line 1 in file %s\nmust contain the TigerVNC " + "configuration file identifier string:\n" + "\"%s\""), filepath, IDENTIFIER_STRING); throw Exception(readError); } } @@ -631,7 +644,7 @@ char* loadViewerParameters(const char *filename) { // Find the parameter value char *value = strchr(line, '='); if (value == NULL) { - vlog.info("Bad Name/Value pair on line: %d in file: %s", + vlog.info(_("Bad Name/Value pair on line: %d in file: %s"), lineNr, filepath); continue; } @@ -644,8 +657,8 @@ char* loadViewerParameters(const char *filename) { if (strcasecmp(line, "ServerName") == 0) { if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) { - vlog.info("The value of the parameter %s on line %d in file %s is invalid.", - line, lineNr, filepath); + vlog.info(_("The value of the parameter %s on line %d in file %s " + "is invalid."), line, lineNr, filepath); continue; } snprintf(servername, sizeof(decodingBuffer), "%s", decodingBuffer); @@ -660,8 +673,8 @@ char* loadViewerParameters(const char *filename) { if (strcasecmp(line, ((StringParameter*)parameterArray[i])->getName()) == 0) { if(!decodeValue(value, decodingBuffer, sizeof(decodingBuffer))) { - vlog.info("The value of the parameter %s on line %d in file %s is invalid.", - line, lineNr, filepath); + vlog.info(_("The value of the parameter %s on line %d in file %s " + "is invalid."), line, lineNr, filepath); continue; } ((StringParameter*)parameterArray[i])->setParam(decodingBuffer); @@ -681,13 +694,14 @@ char* loadViewerParameters(const char *filename) { } } else { - vlog.info("The parameterArray contains a object of a invalid type at line %d.", lineNr); + vlog.info(_("The parameterArray contains a object of a invalid type " + "at line %d."), lineNr); } } } if (invalidParameterName) - vlog.info("Invalid parameter name on line: %d in file: %s", + vlog.info(_("Invalid parameter name on line: %d in file: %s"), lineNr, filepath); } fclose(f); f=0; diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx index 8e249377..c818d335 100644 --- a/vncviewer/vncviewer.cxx +++ b/vncviewer/vncviewer.cxx @@ -115,7 +115,7 @@ static void CleanupSignalHandler(int sig) { // CleanupSignalHandler allows C++ object cleanup to happen because it calls // exit() rather than the default which is to abort. - vlog.info("CleanupSignalHandler called"); + vlog.info(_("CleanupSignalHandler called")); exit(1); } @@ -461,8 +461,8 @@ int main(int argc, char** argv) #ifndef WIN32 /* Specifying -via and -listen together is nonsense */ if (listenMode && strlen(via.getValueStr()) > 0) { - vlog.error("Parameters -listen and -via are incompatible"); - fl_alert("Parameters -listen and -via are incompatible"); + vlog.error(_("Parameters -listen and -via are incompatible")); + fl_alert(_("Parameters -listen and -via are incompatible")); exit_vncviewer(); return 1; } @@ -476,7 +476,7 @@ int main(int argc, char** argv) TcpListener listener(NULL, port); - vlog.info("Listening on port %d\n", port); + vlog.info(_("Listening on port %d\n"), port); sock = listener.accept(); } catch (rdr::Exception& e) { vlog.error("%s", e.str()); -- 2.39.5