On Thu, May 21, 2009 at 02:06:17PM +0200, Adam Tkac wrote:
> Hi all,
>
> one man reported problem that vncviewer doesn't show Russian letters
> (https://bugzilla.redhat.com/show_bug.cgi?id=501832).
>
> After quick inspection main problem is that libX11 text routines
> (mainly XDrawString) doesn't support UTF-8.
Ok, based on discussion in this thread I created proposed patch.
Gettext is used only if user uses iso-8859-1 or iso-8859-2 encoding.
I would like to commit this patch to both 1_0 and trunk.
What is your opinion?
Regards, Adam
--
Adam Tkac, Red Hat, Inc.
Index: unix/vncviewer/AboutDialog.h
===================================================================
--- unix/vncviewer/AboutDialog.h (revision 3817)
+++ unix/vncviewer/AboutDialog.h (working copy)
@@ -25,12 +25,8 @@
#include "TXMsgBox.h"
#include "parameters.h"
-#include "gettext.h"
-#define _(String) gettext (String)
-#define gettext_noop(String) String
-#define N_(String) gettext_noop (String)
-
extern char buildtime[];
+extern const char * _(const char *string);
class AboutDialog : public TXMsgBox {
public:
Index: unix/vncviewer/vncviewer.cxx
===================================================================
--- unix/vncviewer/vncviewer.cxx (revision 3817)
+++ unix/vncviewer/vncviewer.cxx (working copy)
@@ -30,6 +30,7 @@
#include <unistd.h>
#include <errno.h>
#include <signal.h>
+#include <langinfo.h>
#include <locale.h>
#include <rfb/Logger_stdio.h>
#include <rfb/LogWriter.h>
@@ -39,9 +40,6 @@
#include "CConn.h"
#include "gettext.h"
-#define _(String) gettext (String)
-#define gettext_noop(String) String
-#define N_(String) gettext_noop (String)
rfb::LogWriter vlog("main");
@@ -172,6 +170,33 @@
static XLoginIconifier xloginIconifier;
+const char * _(const char *string)
+{
+ static int i18n = -1; /* -1 = unknown, 0 = not supported, 1 = supported */
+ char *lang;
+
+ if (i18n == -1) {
+ lang = nl_langinfo(CODESET);
+ i18n = (strcasecmp(lang, "iso-8859-1") == 0 ||
+ strcasecmp(lang, "iso-8859-2") == 0) ? 1 : 0;
+
+ if (i18n != 0) {
+ /* Initialize gettext */
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE_NAME, LOCALEDIR);
+ textdomain(PACKAGE_NAME);
+
+ // Set gettext codeset to what our GUI toolkit uses. Since we are
+ // passing strings from strerror/gai_strerror to the GUI, these must
+ // be in GUI codeset as well.
+ bind_textdomain_codeset(PACKAGE_NAME, lang);
+ bind_textdomain_codeset("libc", lang);
+ }
+ }
+
+ return (i18n == 1) ? gettext(string) : string;
+}
+
static void usage()
{
fprintf(stderr,
@@ -267,30 +292,20 @@
int main(int argc, char** argv)
{
- setlocale(LC_ALL, "");
- bindtextdomain(PACKAGE_NAME, LOCALEDIR);
- textdomain(PACKAGE_NAME);
+ const char englishAbout[] = "TigerVNC Viewer for X version %s - built %s\n"
+ "Copyright (C) 2002-2005 RealVNC Ltd.\n"
+ "Copyright (C) 2000-2006 TightVNC Group\n"
+ "Copyright (C) 2004-2009 Peter Astrand for Cendio
AB\n"
+ "See http://www.tigervnc.org for information on
TigerVNC.";
- const char englishAbout[] = N_("TigerVNC Viewer for X version %s - built
%s\n"
- "Copyright (C) 2002-2005 RealVNC Ltd.\n"
- "Copyright (C) 2000-2006 TightVNC Group\n"
- "Copyright (C) 2004-2009 Peter Astrand for
Cendio AB\n"
- "See http://www.tigervnc.org for information
on TigerVNC.");
-
// Write about text to console, still using normal locale codeset
snprintf(aboutText, sizeof(aboutText),
- gettext(englishAbout), PACKAGE_VERSION, buildtime);
+ _(englishAbout), PACKAGE_VERSION, buildtime);
fprintf(stderr,"\n%s\n", aboutText);
- // Set gettext codeset to what our GUI toolkit uses. Since we are
- // passing strings from strerror/gai_strerror to the GUI, these must
- // be in GUI codeset as well.
- bind_textdomain_codeset(PACKAGE_NAME, "iso-8859-1");
- bind_textdomain_codeset("libc", "iso-8859-1");
-
// Re-create the aboutText for the GUI, now using GUI codeset
snprintf(aboutText, sizeof(aboutText),
- gettext(englishAbout), PACKAGE_VERSION, buildtime);
+ _(englishAbout), PACKAGE_VERSION, buildtime);
rfb::initStdIOLoggers();
rfb::LogWriter::setLogParams("*:stderr:30");
------------------------------------------------------------------------------
Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT
is a gathering of tech-side developers & brand creativity professionals. Meet
the minds behind Google Creative Lab, Visual Complexity, Processing, &
iPhoneDevCamp as they present alongside digital heavyweights like Barbarian
Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________
Tigervnc-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tigervnc-devel