Changeset 255

Show
Ignore:
Timestamp:
04/04/03 19:59:32 (6 years ago)
Author:
jajcus
Message:

- perliminary gettext support

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk

    • Property svn:ignore changed from
      Makefile
      Makefile.in
      aclocal.m4
      autoscan.log
      config.guess
      config.h
      config.h.in
      config.log
      config.status
      config.sub
      configure
      depcomp
      install-sh
      libtool
      ltmain.sh
      missing
      mkinstalldirs
      stamp-h
      stamp-h.in
      stamp-h1
      jabber-gg-transport-*.tar.gz
      autom4te.cache
      to
      Makefile
      Makefile.in
      aclocal.m4
      autoscan.log
      config.guess
      config.h
      config.h.in
      config.log
      config.status
      config.sub
      configure
      depcomp
      install-sh
      libtool
      ltmain.sh
      missing
      mkinstalldirs
      stamp-h
      stamp-h.in
      stamp-h1
      jabber-gg-transport-*.tar.gz
      autom4te.cache
      intl
  • trunk/.cvsignore

    r174 r255  
    2121jabber-gg-transport-*.tar.gz 
    2222autom4te.cache 
     23intl 
  • trunk/Makefile.am

    r116 r255  
    11 
    2 SUBDIRS = libxode src 
     2SUBDIRS = intl libxode src po 
    33 
    44EXTRA_DIST = jggtrans.xml jggtrans.xml.Pl TODO BUGS README.Pl INSTALL.Pl 
  • trunk/autogen.sh

    r130 r255  
    33( cd libxode ; ./autogen.sh ) || exit 1 
    44 
    5 libtoolize --copy --force 
    6 aclocal  
     5libtoolize --force 
     6rm -f po/ChangeLog 
     7gettextize --force 
     8aclocal 
    79autoheader 
    810automake -a  
  • trunk/configure.ac

    r254 r255  
    4949AC_CHECK_HEADERS([sys/socket.h netdb.h netinet/in.h]) 
    5050AC_CHECK_HEADERS([sys/time.h unistd.h errno.h fcntl.h]) 
    51 AC_NEED_STDINT_H 
    5251 
    5352# Checks for typedefs, structures, and compiler characteristics. 
     
    6766AC_CONFIG_SUBDIRS([libxode]) 
    6867 
    69 AC_CONFIG_FILES([Makefile src/Makefile]) 
     68AC_CONFIG_FILES([Makefile src/Makefile intl/Makefile po/Makefile.in]) 
    7069AC_OUTPUT 
  • trunk/src/ggtrans.h

    r185 r255  
    1 /* $Id: ggtrans.h,v 1.6 2003/01/15 14:13:12 jajcus Exp $ */ 
     1/* $Id: ggtrans.h,v 1.7 2003/04/04 17:59:32 jajcus Exp $ */ 
    22 
    33/* 
     
    2222 
    2323#include <libxode.h> 
     24#include <libintl.h> 
    2425#include <glib.h> 
    2526#include "../config.h" 
     27 
     28/* gettext shortcut for translating messages */ 
     29#define _(String) gettext (String) 
     30 
     31/* dummy gettext shortcut for translating error/debug messages after log handler is set */ 
     32#define __(String) gettext (String) 
    2633 
    2734extern GMainLoop *main_loop; 
  • trunk/src/main.c

    r241 r255  
    1 /* $Id: main.c,v 1.34 2003/03/24 14:43:37 jajcus Exp $ */ 
     1/* $Id: main.c,v 1.35 2003/04/04 17:59:32 jajcus Exp $ */ 
    22 
    33/* 
     
    162162        switch(log_level){ 
    163163                case G_LOG_LEVEL_ERROR: 
    164                         fprintf(f,"Fatal error: %s\n",message); 
     164                        fprintf(f,_("Fatal error: %s\n"),_(message)); 
    165165                        break; 
    166166                case G_LOG_LEVEL_CRITICAL: 
    167                         fprintf(f,"Error: %s\n",message); 
     167                        fprintf(f,_("Error: %s\n"),_(message)); 
    168168                        break; 
    169169                case G_LOG_LEVEL_WARNING: 
    170                         fprintf(f,"Warning: %s\n",message); 
     170                        fprintf(f,_("Warning: %s\n"),_(message)); 
    171171                        break; 
    172172                case G_LOG_LEVEL_MESSAGE: 
     
    174174                case G_LOG_LEVEL_INFO: 
    175175                        if (debug_level<0) break; 
    176                         fprintf(f,"%s\n",message); 
     176                        fprintf(f,"%s\n",_(message)); 
    177177                        break; 
    178178                case G_LOG_LEVEL_DEBUG: 
    179179                        if (debug_level>0) 
    180                                 fprintf(f,"Debug: %s\n",message); 
     180                                fprintf(f,_("Debug: %s\n"),_(message)); 
    181181                        break; 
    182182                default: 
    183                         fprintf(f,"Unknown: %s\n",message); 
     183                        fprintf(f,_("Unknown: %s\n"),_(message)); 
    184184                        break; 
    185185        } 
     
    191191        switch(log_level){ 
    192192                case G_LOG_LEVEL_ERROR: 
    193                         syslog(LOG_ERR,"Fatal error: %s",message); 
     193                        syslog(LOG_ERR,_("Fatal error: %s"),_(message)); 
    194194                        break; 
    195195                case G_LOG_LEVEL_CRITICAL: 
    196                         syslog(LOG_ERR,"Error: %s",message); 
     196                        syslog(LOG_ERR,_("Error: %s"),_(message)); 
    197197                        break; 
    198198                case G_LOG_LEVEL_WARNING: 
    199                         syslog(LOG_WARNING,"Warning: %s",message); 
     199                        syslog(LOG_WARNING,_("Warning: %s"),_(message)); 
    200200                        break; 
    201201                case G_LOG_LEVEL_MESSAGE: 
    202202                        if (debug_level<-1) break; 
    203                         syslog(LOG_NOTICE,"%s",message); 
     203                        syslog(LOG_NOTICE,"%s",_(message)); 
    204204                        break; 
    205205                case G_LOG_LEVEL_INFO: 
    206206                        if (debug_level<0) break; 
    207                         syslog(LOG_NOTICE,"%s",message); 
     207                        syslog(LOG_NOTICE,"%s",_(message)); 
    208208                        break; 
    209209                case G_LOG_LEVEL_DEBUG: 
    210210                        if (debug_level>0) 
    211                                 syslog(LOG_DEBUG,"Debug: %s\n",message); 
     211                                syslog(LOG_DEBUG,_("Debug: %s\n"),_(message)); 
    212212                        break; 
    213213                default: 
    214                         syslog(LOG_NOTICE,"Unknown: %s\n",message); 
     214                        syslog(LOG_NOTICE,_("Unknown: %s\n"),_(message)); 
    215215                        break; 
    216216        } 
     
    220220                        const gchar *message, gpointer user_data){ 
    221221 
     222char *lc_ctype,*lc_messages; 
     223 
     224        lc_ctype=setlocale(LC_CTYPE,NULL); 
     225        lc_messages=setlocale(LC_MESSAGES,NULL); 
     226         
    222227        log_level&=G_LOG_LEVEL_MASK; 
    223228        if (foreground) log_handler_file(stderr,log_domain,log_level,message); 
    224229        if (log_file) log_handler_file(log_file,log_domain,log_level,message); 
    225230        if (use_syslog) log_handler_syslog(log_domain,log_level,message); 
     231         
     232        setlocale(LC_CTYPE,lc_ctype); 
     233        setlocale(LC_MESSAGES,lc_ctype); 
    226234} 
    227235 
     
    231239int fd; 
    232240 
    233         debug("Daemonizing..."); 
     241        debug(__("Daemonizing...")); 
    234242        pid=fork(); 
    235         if (pid==-1) g_error("Failed to fork(): %s",g_strerror(errno)); 
     243        if (pid==-1) g_error(__("Failed to fork(): %s"),g_strerror(errno)); 
    236244        if (pid){ 
    237245                if (pidfile){ 
     
    239247                        fclose(pidfile); 
    240248                } 
    241                 debug("Daemon born, pid %i.",pid); 
     249                debug(__("Daemon born, pid %i."),pid); 
    242250                exit(0); 
    243251        } 
     
    261269        if (sid==-1) abort(); 
    262270        foreground=FALSE; 
    263         debug("I am a daemon, I think."); 
     271        debug(__("I am a daemon, I think.")); 
    264272        return; 
    265273} 
     
    270278        p=strrchr(name,'/'); 
    271279        if (p) name=p+1; 
    272         printf("\nJabber GaduGadu Transport %s\n",VERSION); 
    273         printf("\n"); 
    274         printf("\tUsage: %s [OPTIONS]... [<config file>]\n",name); 
    275         printf("\nOptions:\n"); 
    276         printf("\t-h         This message\n"); 
    277         printf("\t-f         Run in foreground. Debug/error messages will be sent to stderr\n"); 
    278         printf("\t-d <n>      Log level (0(default) - normal, >0 more, <0 less)\n"); 
    279         printf("\t-D <n>      libgg debug level (enables also -f)\n"); 
    280         printf("\t-u <user>   Switch to uid of <user> on startup\n"); 
    281         printf("\t-g <group>  Switch to gid of <group> on startup\n"); 
    282         printf("\n"); 
     280        printf(_("\nJabber GaduGadu Transport %s\n"),VERSION); 
     281        printf(_("\n")); 
     282        printf(_("\tUsage: %s [OPTIONS]... [<config file>]\n"),name); 
     283        printf(_("\nOptions:\n")); 
     284        printf(_("\t-h       This message\n")); 
     285        printf(_("\t-f       Run in foreground. Debug/error messages will be sent to stderr\n")); 
     286        printf(_("\t-d <n>      Log level (0(default) - normal, >0 more, <0 less)\n")); 
     287        printf(_("\t-D <n>      libgg debug level (enables also -f)\n")); 
     288        printf(_("\t-u <user>   Switch to uid of <user> on startup\n")); 
     289        printf(_("\t-g <group>  Switch to gid of <group> on startup\n")); 
     290        printf(_("\n")); 
    283291} 
    284292 
     
    311319        newgid=0; user=NULL; group=NULL; 
    312320 
     321        /* use local locale for error and debug messages */ 
     322        setlocale(LC_MESSAGES,""); 
     323        setlocale(LC_CTYPE,""); 
     324        textdomain(PACKAGE); 
     325         
    313326        saved_pwd=getcwd(saved_pwd_b,1024); 
    314327        opterr=0; 
     
    334347                                break; 
    335348                        case 'u': 
    336                                 if (uid!=0) g_error("Cannot change user."); 
     349                                if (uid!=0) g_error(_("Cannot change user.")); 
    337350                                user=optarg; 
    338351                                break; 
    339352                        case 'g': 
    340                                 if (uid!=0) g_error("Cannot change group."); 
     353                                if (uid!=0) g_error(_("Cannot change group.")); 
    341354                                group=optarg; 
    342355                                break; 
    343356                        case '?': 
    344357                                if (isprint(optopt)) 
    345                                         fprintf(stderr,"Unknown command-line option: -%c.\n",optopt); 
     358                                        fprintf(stderr,_("Unknown command-line option: -%c.\n"),optopt); 
    346359                                else 
    347                                         fprintf(stderr,"Unknown command-line option: -\\%03o.\n",optopt); 
     360                                        fprintf(stderr,_("Unknown command-line option: -\\%03o.\n"),optopt); 
    348361                                usage(argv[0]); 
    349362                                return 1; 
    350363                        default: 
    351                                 g_error("Error while processing command line options"); 
     364                                g_error(_("Error while processing command line options")); 
    352365                                break; 
    353366                } 
     
    355368 
    356369        if (optind<argc-1){ 
    357                 fprintf(stderr,"Unexpected argument: %s\n",argv[optind]); 
     370                fprintf(stderr,_("Unexpected argument: %s\n"),argv[optind]); 
    358371                usage(argv[0]); 
    359372                return 1; 
     
    368381                                | G_LOG_LEVEL_DEBUG,log_handler,NULL); 
    369382 
     383        /* now the log handlers worry about the right language */ 
     384        setlocale(LC_MESSAGES,"C"); 
     385        setlocale(LC_CTYPE,"C"); 
     386 
    370387        config=xmlnode_file(config_file); 
    371388        if (!config){ 
    372                 g_error("Couldn't load config!"); 
     389                g_error(__("Couldn't load config!")); 
    373390                return 1; 
    374391        } 
    375392        str=xmlnode_get_name(config); 
    376393        if (!str || strcmp(str,"jggtrans")){ 
    377                 g_error("%s doesn't look like jggtrans config file.",config_file); 
     394                g_error(__("%s doesn't look like jggtrans config file."),config_file); 
    378395                return 1; 
    379396        } 
     
    386403                if (!strcmp(log_type,"syslog")){ 
    387404                        if (log_facility!=-1){ 
    388                                 g_warning("Multiple syslog configs specified. Using only one."); 
     405                                g_warning(__("Multiple syslog configs specified. Using only one.")); 
    389406                                continue; 
    390407                        } 
     
    397414                                if (!strcmp(facilitynames[log_facility].name,str)) break; 
    398415                        if (!facilitynames[log_facility].name) 
    399                                  g_error("Unknown syslog facility: %s",str); 
     416                                 g_error(__("Unknown syslog facility: %s"),str); 
    400417                } 
    401418                else if (!strcmp(log_type,"file")){ 
    402                         if (log_filename) g_warning("Multiple log files specified. Using only one."); 
     419                        if (log_filename) g_warning(__("Multiple log files specified. Using only one.")); 
    403420                        else{ 
    404421                                data=xmlnode_get_data(tag); 
     
    407424                        } 
    408425                } 
    409                 else g_warning("Ignoring unknown log type: %s",xmlnode2str(tag)); 
     426                else g_warning(__("Ignoring unknown log type: %s"),xmlnode2str(tag)); 
    410427        } 
    411428 
     
    424441                        if (r==1 && pid>0){ 
    425442                                r=kill(pid,0); 
    426                                 if (!r || (r && errno!=ESRCH)) g_error("jggtrans already running"); 
     443                                if (!r || (r && errno!=ESRCH)) g_error(__("jggtrans already running")); 
    427444                                if (r){ 
    428                                         g_warning("Stale pid file. Removing."); 
     445                                        g_warning(__("Stale pid file. Removing.")); 
    429446                                        unlink(pid_filename); 
    430447                                } 
    431448                        } 
    432                         else if (r!=EOF) g_error("Invalid pid file."); 
     449                        else if (r!=EOF) g_error(__("Invalid pid file.")); 
    433450                } 
    434451                pidfile=fopen(pid_filename,"w"); 
    435452                if (pidfile==NULL) 
    436                         g_error("Couldn't open pidfile %s",pid_filename); 
     453                        g_error(__("Couldn't open pidfile %s"),pid_filename); 
    437454        } 
    438455        else 
     
    441458        if (group){ 
    442459                grp=getgrnam(group); 
    443                 if (!grp) g_error("Couldn't find group %s",group); 
     460                if (!grp) g_error(__("Couldn't find group %s"),group); 
    444461                newgid=grp->gr_gid; 
    445462        } 
    446463        if (user){ 
    447464                pwd=getpwnam(user); 
    448                 if (!pwd) g_error("Couldn't find user %s",user); 
     465                if (!pwd) g_error(__("Couldn't find user %s"),user); 
    449466                if (newgid<=0) newgid=pwd->pw_gid; 
    450467                fchown(fileno(pidfile),pwd->pw_uid,newgid); 
    451                 if (setgid(newgid)) g_error("Couldn't change group: %s",g_strerror(errno)); 
    452                 if (initgroups(user,newgid)) g_error("Couldn't init groups: %s",g_strerror(errno)); 
    453                 if (setuid(pwd->pw_uid)) g_error("Couldn't change user: %s",g_strerror(errno)); 
    454         } 
    455         else if (uid==0 && !restarting) g_error("Refusing to run with uid=0"); 
     468                if (setgid(newgid)) g_error(__("Couldn't change group: %s"),g_strerror(errno)); 
     469                if (initgroups(user,newgid)) g_error(__("Couldn't init groups: %s"),g_strerror(errno)); 
     470                if (setuid(pwd->pw_uid)) g_error(__("Couldn't change user: %s"),g_strerror(errno)); 
     471        } 
     472        else if (uid==0 && !restarting) g_error(__("Refusing to run with uid=0")); 
    456473 
    457474        main_loop=g_main_new(0); 
     
    471488        if (log_filename){ 
    472489                log_file=fopen(log_filename,"a"); 
    473                 if (!log_file) g_critical("Couldn't open log file '%s': %s"
     490                if (!log_file) g_critical(__("Couldn't open log file '%s': %s")
    474491                                                log_filename,g_strerror(errno)); 
    475492                if (log_file) setvbuf(log_file,NULL,_IOLBF,0); 
     
    503520                int n; 
    504521 
    505                 g_message("Restarting in %i seconds.\n",restart_timeout); 
     522                g_message(__("Restarting in %i seconds.\n"),restart_timeout); 
    506523                if (restart_timeout>0) sleep(restart_timeout); 
    507524                if (saved_pwd) chdir(saved_pwd); 
     
    524541        } 
    525542 
    526         g_message("Exiting normally.\n"); 
     543        g_message(__("Exiting normally.\n")); 
    527544 
    528545        g_log_remove_handler(NULL,lh);