]> git.sur5r.net Git - bacula/bacula/commitdiff
Fix gettext problem in wx-console when ENABLE_NLS is not set.
authorNicolas Boichat <nicolas@boichat.ch>
Fri, 19 Aug 2005 09:34:49 +0000 (09:34 +0000)
committerNicolas Boichat <nicolas@boichat.ch>
Fri, 19 Aug 2005 09:34:49 +0000 (09:34 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@2336 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/baconfig.h
bacula/src/wx-console/console_thread.cpp
bacula/src/wx-console/console_thread.h
bacula/src/wx-console/main.cpp

index d7000e57095d0dc2a4a2fdca3946e9c2ead1010a..04dc8c6617aeeee2575bb238800111c7a90758f9 100644 (file)
 #define NPRT(x) (x)?(x):_("*None*")
 
 #ifdef ENABLE_NLS
-#include <libintl.h>
-#include <locale.h>
-#ifndef _
-#define _(s) gettext((s))
-#endif /* N */
-#ifndef N_
-#define N_(s) (s)
-#endif /* N_ */
-#else
-#undef _
-#define _(s) (s)
-#undef N_
-#define N_(s) (s)
-#undef textdomain
-#define textdomain(d)
-#undef bindtextdomain
-#define bindtextdomain(p, d)
-#undef setlocale
-#define setlocale(p, d)
-#endif
+   #include <libintl.h>
+   #include <locale.h>
+   #ifndef _
+      #define _(s) gettext((s))
+   #endif /* _ */
+   #ifndef N_
+      #define N_(s) (s)
+   #endif /* N_ */
+#else /* !ENABLE_NLS */
+   #ifndef _
+      #define _(s) (s)
+   #endif
+   #ifndef N_
+      #define N_(s) (s)
+   #endif
+   #ifndef textdomain
+      #define textdomain(d)
+   #endif
+   #ifndef bindtextdomain
+      #define bindtextdomain(p, d)
+   #endif
+   #ifndef setlocale
+      #define setlocale(p, d)
+   #endif
+#endif /* ENABLE_NLS */
 
 /* This should go away! ****FIXME***** */
 #define MAXSTRING 500
index dc37429e7d9f6aaa290a9261337bd03b149ea99f..0ef8b068d5e32a1db846757bfb4f3e1c8cfd0db7 100644 (file)
@@ -23,9 +23,8 @@
 
 // http://66.102.9.104/search?q=cache:Djc1mPF3hRoJ:cvs.sourceforge.net/viewcvs.py/audacity/audacity-src/src/AudioIO.cpp%3Frev%3D1.102+macos+x+wxthread&hl=fr
 
-/* Note: this is the only source file in src/wx-console which uses the
- * standard gettext macros. So every translated string passed to wxWidgets
- * must be converted. (wxString(_("..."),wxConvUTF8)) */
+/* _("...") macro returns a wxChar*, so if we need a char*, we need to convert it with:
+ * wxString(_("...")).mb_str(*wxConvCurrent) */
 
 #include "console_thread.h" // class's header file
 
@@ -33,8 +32,6 @@
 
 #include <wx/thread.h>
 #include <wx/file.h>
-#include <bacula.h>
-#include <jcr.h>
 
 #include "console_conf.h"
 
@@ -94,24 +91,24 @@ static int check_resources()
          if (have_tls) {
             director->tls_enable = true;
          } else {
-            Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+            Jmsg(NULL, M_FATAL, 0, wxString(_("TLS required but not configured in Bacula.\n")).mb_str(*wxConvCurrent));
             xOK = false;
             continue;
          }
       }
 
       if ((!director->tls_ca_certfile && !director->tls_ca_certdir) && director->tls_enable) {
-         Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
+         Jmsg(NULL, M_FATAL, 0, wxString(_("Neither \"TLS CA Certificate\""
                              " or \"TLS CA Certificate Dir\" are defined for Director \"%s\" in config file.\n"
-                             " At least one CA certificate store is required.\n"),
+                             " At least one CA certificate store is required.\n")).mb_str(*wxConvCurrent),
                              director->hdr.name);
          xOK = false;
       }
    }
    
    if (numdir == 0) {
-      Jmsg(NULL, M_FATAL, 0, _("No Director resource defined in config file.\n"
-                          "Without that I don't how to speak to the Director :-(\n"));
+      Jmsg(NULL, M_FATAL, 0, wxString(_("No Director resource defined in config file.\n"
+                          "Without that I don't how to speak to the Director :-(\n")).mb_str(*wxConvCurrent));
       xOK = false;
    }
 
@@ -123,15 +120,15 @@ static int check_resources()
          if (have_tls) {
             cons->tls_enable = true;
          } else {
-            Jmsg(NULL, M_FATAL, 0, _("TLS required but not configured in Bacula.\n"));
+            Jmsg(NULL, M_FATAL, 0, wxString(_("TLS required but not configured in Bacula.\n")).mb_str(*wxConvCurrent));
             xOK = false;
             continue;
          }
       }
 
       if ((!cons->tls_ca_certfile && !cons->tls_ca_certdir) && cons->tls_enable) {
-         Jmsg(NULL, M_FATAL, 0, _("Neither \"TLS CA Certificate\""
-                             " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in config file.\n"),
+         Jmsg(NULL, M_FATAL, 0, wxString(_("Neither \"TLS CA Certificate\""
+                             " or \"TLS CA Certificate Dir\" are defined for Console \"%s\" in config file.\n")).mb_str(*wxConvCurrent),
                              cons->hdr.name);
          xOK = false;
       }
@@ -190,12 +187,12 @@ static void scan_err(const char *file, int line, LEX *lc, const char *msg, ...)
 
    if (lc->line_no > lc->begin_line_no) {
       bsnprintf(more, sizeof(more),
-                _("Problem probably begins at line %d.\n"), lc->begin_line_no);
+                wxString(_("Problem probably begins at line %d.\n")).mb_str(*wxConvCurrent), lc->begin_line_no);
    } else {
       more[0] = 0;
    }
 
-   err.Format(wxString(_("Config error: %s\n            : line %d, col %d of file %s\n%s\n%s"), wxConvUTF8),
+   err.Format(_("Config error: %s\n            : line %d, col %d of file %s\n%s\n%s"),
       buf, lc->line_no, lc->col_no, lc->fname, lc->line, more);
      
    errmsg << err; 
@@ -205,7 +202,7 @@ wxString console_thread::LoadConfig(wxString configfile) {
    if (!inited) {
       InitLib();
       if (!inited)
-         return wxString(_("Error while initializing library."), wxConvUTF8);
+         return _("Error while initializing library.");
    }
    
    free_config_resources();
@@ -231,11 +228,11 @@ wxString console_thread::LoadConfig(wxString configfile) {
    }
    
    if (init_tls() != 0) {
-      Jmsg(NULL, M_ERROR_TERM, 0, _("TLS library initialization failed.\n"));
+      Jmsg(NULL, M_ERROR_TERM, 0, wxString(_("TLS library initialization failed.\n")).mb_str(*wxConvCurrent));
    }
 
    if (!check_resources()) {
-      Jmsg(NULL, M_ERROR_TERM, 0, _("Please correct configuration file.\n"));
+      Jmsg(NULL, M_ERROR_TERM, 0, wxString(_("Please correct configuration file.\n")).mb_str(*wxConvCurrent));
    }
 
    term_msg();
@@ -266,6 +263,12 @@ console_thread::~console_thread() {
  * Thread entry point
  */
 void* console_thread::Entry() {
+   /* It seems we must redefine the locale on each thread. */
+   wxLocale m_locale;
+   m_locale.Init();
+   m_locale.AddCatalog(wxT("bacula"));
+   wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR));
+
    DIRRES* dir;
    if (!inited) {
       csprint(_("Error : Library not initialized\n"));
@@ -326,7 +329,7 @@ void* console_thread::Entry() {
                csprint(wxString(wxT("   ")) <<  (i+1) << wxT(": ") << wxString(res[i]->hdr.name,*wxConvCurrent) << wxT("\n"));
             }
          }
-         csprint(wxString::Format(wxString(_("Please choose a director (1-%d): "), wxConvUTF8), count), CS_DATA);
+         csprint(wxString::Format(_("Please choose a director (1-%d): "), count), CS_DATA);
          csprint(NULL, CS_PROMPT);
          choosingdirector = true;
          directorchoosen = -1;
@@ -355,7 +358,7 @@ void* console_thread::Entry() {
    /* Initialize Console TLS context */
    if (cons && (cons->tls_enable || cons->tls_require)) {
       /* Generate passphrase prompt */
-      bsnprintf(buf, sizeof(buf), _("Passphrase for Console \"%s\" TLS private key: "), cons->hdr.name);
+      bsnprintf(buf, sizeof(buf), wxString(_("Passphrase for Console \"%s\" TLS private key: ")).mb_str(*wxConvCurrent), cons->hdr.name);
 
       /* Initialize TLS context:
        * Args: CA certfile, CA certdir, Certfile, Keyfile,
@@ -365,7 +368,7 @@ void* console_thread::Entry() {
          cons->tls_keyfile, tls_pem_callback, &buf, NULL, true);
 
       if (!cons->tls_ctx) {
-         bsnprintf(buf, sizeof(buf), _("Failed to initialize TLS context for Console \"%s\".\n"),
+         bsnprintf(buf, sizeof(buf), wxString(_("Failed to initialize TLS context for Console \"%s\".\n")).mb_str(*wxConvCurrent),
             dir->hdr.name);
          csprint(buf);
          return NULL;
@@ -376,7 +379,7 @@ void* console_thread::Entry() {
    /* Initialize Director TLS context */
    if (dir->tls_enable || dir->tls_require) {
       /* Generate passphrase prompt */
-      bsnprintf(buf, sizeof(buf), _("Passphrase for Director \"%s\" TLS private key: "), dir->hdr.name);
+      bsnprintf(buf, sizeof(buf), wxString(_("Passphrase for Director \"%s\" TLS private key: ")).mb_str(*wxConvCurrent), dir->hdr.name);
 
       /* Initialize TLS context:
        * Args: CA certfile, CA certdir, Certfile, Keyfile,
@@ -386,7 +389,7 @@ void* console_thread::Entry() {
          dir->tls_keyfile, tls_pem_callback, &buf, NULL, true);
 
       if (!dir->tls_ctx) {
-         bsnprintf(buf, sizeof(buf), _("Failed to initialize TLS context for Director \"%s\".\n"),
+         bsnprintf(buf, sizeof(buf), wxString(_("Failed to initialize TLS context for Director \"%s\".\n")).mb_str(*wxConvCurrent),
             dir->hdr.name);
          csprint(buf);
          return NULL;
@@ -394,7 +397,7 @@ void* console_thread::Entry() {
    }
 
 
-   UA_sock = bnet_connect(&jcr, 3, 3, _("Director daemon"),
+   UA_sock = bnet_connect(&jcr, 3, 3, wxString(_("Director daemon")).mb_str(*wxConvCurrent),
       dir->address, NULL, dir->DIRport, 0);
       
    if (UA_sock == NULL) {
index bf363f3c539291480e246f10e39dc5778c0f1a23..fa1d3bf5f95f60a6b0a4de795986b4bd108fe88b 100644 (file)
@@ -31,6 +31,7 @@
 
 #include <wx/string.h>
 #include <wx/thread.h> // inheriting class's header file
+#include <wx/intl.h> /* We need to have _ and N_ defined by wxWidgets before Bacula tries to redefine them */
 #include "bacula.h"
 #include "jcr.h"
 
index d4dc49e348cc5864a374bf92d7e1760a01d71ebe..5dae9b5d8365695392529d4526aa3d9c52052b66 100644 (file)
@@ -69,8 +69,8 @@ IMPLEMENT_APP(MyApp)
 // 'Main program' equivalent: the program execution "starts" here
 bool MyApp::OnInit()
 {
+   /* wxWidgets internationalisation */
    wxLocale m_locale;
-   
    m_locale.Init();
    m_locale.AddCatalog(wxT("bacula"));
    wxLocale::AddCatalogLookupPathPrefix(wxT(LOCALEDIR));