Skip to content

Commit

Permalink
Implement i18n in ncks, extend to es and fr
Browse files Browse the repository at this point in the history
  • Loading branch information
czender committed Jun 17, 2014
1 parent f46ac33 commit 2f1baea
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 24 deletions.
2 changes: 1 addition & 1 deletion doc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
cd ~/nco;cvs commit -m "Preparing nco-4.4.5 release"
cvs tag -c nco-4_4_5;cvs tag -c nco-4_4_5-1

* Update i18n
* Implement i18n in ncks, extend to es and fr

2014-06-15 Charlie Zender <[email protected]>

Expand Down
16 changes: 8 additions & 8 deletions po/es/nco.po
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Portable Object French translations for NCO, the netCDF Operators
# Portable Object Spanish translations for NCO, the netCDF Operators
# Copyright (C) 1995-2014 Charlie Zender
# This file is distributed under the same license as the NCO package

Expand All @@ -10,7 +10,7 @@ msgstr ""
"POT-Creation-Date: 2014-06-17 13:16-0700\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Charlie Zender <[email protected]>\n"
"Language-Team: French <[email protected]>\n"
"Language-Team: Spanish <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=iso-8859-1\n"
Expand All @@ -19,24 +19,24 @@ msgstr ""
#: ../src/nco/ncra.c:539
#, c-format
msgid "%s: ERROR Incorrect abbreviation for file list\n"
msgstr "%s: ERREUR abréviation incorrecte pour la liste de fichiers\n"
msgstr "%s: ERREUR Abreviatura incorrecta para lista de archivos\n"

#: ../src/nco/ncra.c:616
#, c-format
msgid "%s: I18N Current charset = %s\n"
msgstr "%s: I18N Courant charset = %s\n"
msgstr "%s: I18N Corriente charset = %s\n"

#: ../src/nco/ncra.c:796
#, c-format
msgid "%s: INFO Input file %d is %s"
msgstr "%s: INFO Fichier d'entrée %d est %s"
msgstr "%s: INFO archivo de entrada %d es %s"

#: ../src/nco/ncra.c:799
#, c-format
msgid ", local file is %s"
msgstr ", fichier local est %s"
msgstr ", archivo local es %s"

#: ../src/nco/ncks.c:717
#, c-format
msgid "%s: This text may appear in a foreign language\n"
msgstr "%s: Ce texte peut apparaître dans une langue étrangère\n"
msgid "%s: I18N This text may appear in a foreign language\n"
msgstr "%s: I18N Este texto puede aparecer en un idioma extranjero\n"
5 changes: 5 additions & 0 deletions po/fr/nco.po
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ msgstr "%s: INFO Fichier d'entr
#, c-format
msgid ", local file is %s"
msgstr ", fichier local est %s"

#: ../src/nco/ncks.c:717
#, c-format
msgid "%s: I18N This text may appear in a foreign language\n"
msgstr "%s: I18N Ce texte peut apparaître dans une langue étrangère\n"
48 changes: 44 additions & 4 deletions src/nco/ncks.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Header: /data/zender/nco_20150216/nco/src/nco/ncks.c,v 1.725 2014-06-17 13:28:48 zender Exp $ */
/* $Header: /data/zender/nco_20150216/nco/src/nco/ncks.c,v 1.726 2014-06-17 23:50:01 zender Exp $ */

/* ncks -- netCDF Kitchen Sink */

Expand Down Expand Up @@ -79,6 +79,19 @@
# endif /* !HAVE_GETOPT_H */
#endif /* HAVE_GETOPT_LONG */

#ifdef I18N
# include <langinfo.h> /* nl_langinfo() */
# include <libintl.h> /* Internationalization i18n */
# include <locale.h> /* Locale setlocale() */
# define _(sng) gettext (sng)
# define gettext_noop(sng) (sng)
# define N_(sng) gettext_noop(sng)
#endif /* I18N */
/* Supply stub gettext() function in case i18n failed */
#ifndef _LIBINTL_H
# define gettext(foo) foo
#endif /* _LIBINTL_H */

/* 3rd party vendors */
#include <netcdf.h> /* netCDF definitions and C library */

Expand Down Expand Up @@ -165,8 +178,8 @@ main(int argc,char **argv)

char trv_pth[]="/"; /* [sng] Root path of traversal tree */

const char * const CVS_Id="$Id: ncks.c,v 1.725 2014-06-17 13:28:48 zender Exp $";
const char * const CVS_Revision="$Revision: 1.725 $";
const char * const CVS_Id="$Id: ncks.c,v 1.726 2014-06-17 23:50:01 zender Exp $";
const char * const CVS_Revision="$Revision: 1.726 $";
const char * const opt_sht_lst="34567aABb:CcD:d:FG:g:HhL:l:MmOo:Pp:qQrRs:uv:X:xz-:";

cnk_sct cnk; /* [sct] Chunking structure */
Expand Down Expand Up @@ -383,6 +396,13 @@ main(int argc,char **argv)
}; /* end opt_lng */
int opt_idx=0; /* Index of current long option into opt_lng array */

#ifdef _LIBINTL_H
setlocale(LC_ALL,""); /* LC_ALL sets all localization tokens to same value */
bindtextdomain("nco","/home/zender/share/locale"); /* ${LOCALEDIR} is e.g., /usr/share/locale */
/* MO files should be in ${LOCALEDIR}/es/LC_MESSAGES */
textdomain("nco"); /* PACKAGE is name of program or library */
#endif /* not _LIBINTL_H */

/* Start timer and save command line */
ddra_info.tmr_flg=nco_tmr_srt;
rcd+=nco_ddra((char *)NULL,(char *)NULL,&ddra_info);
Expand Down Expand Up @@ -433,7 +453,7 @@ main(int argc,char **argv)
(void)fprintf(stdout,"%s\n",nco_cmp_get());
nco_exit(EXIT_SUCCESS);
} /* endif "cmp" */
if(!strcmp(opt_crr,"cpy") || !strcmp(opt_crr,"copyright" || !strcmp(opt_crr,"license"))){
if(!strcmp(opt_crr,"cpy") || !strcmp(opt_crr,"copyright") || !strcmp(opt_crr,"license")){
(void)nco_cpy_prn();
nco_exit(EXIT_SUCCESS);
} /* endif "copyright" */
Expand Down Expand Up @@ -682,6 +702,26 @@ main(int argc,char **argv)
if(opt_crr) opt_crr=(char *)nco_free(opt_crr);
} /* end while loop */

#ifdef _LANGINFO_H
/* Internationalization i18n
Linux Journal 200211 p. 57--59 http://www.linuxjournal.com/article/6176
Fedora: http://fedoraproject.org/wiki/How_to_do_I18N_through_gettext
cd ~/nco/bld;make I18N=Y
cd ~/nco/bld;xgettext --default-domain=nco --join-existing -o ../po/nco.pot ../src/nco/ncks.c ../src/nco/ncra.c
for LL in fr es; do
msgfmt ~/nco/po/${LL}/nco.po -o ~/nco/po/${LL}/nco.mo
/bin/cp ~/nco/po/${LL}/nco.mo ~/share/locale/${LL}/LC_MESSAGES
# sudo /bin/cp ~/nco/po/${LL}/nco.mo /usr/share/locale/${LL}/LC_MESSAGES
done
export LOCALEDIR=${HOME}/share/locale
LC_ALL=en ncks -D 1 -O ~/nco/data/in.nc ~/foo.nc
LANG=en_GB.utf8 LANGUAGE=en_GB:en:fr_FR:fr LC_ALL=en_GB.utf8 ncks -D 1 -O ~/nco/data/in.nc ~/foo.nc
LANG=es ncks -D 1 -O ~/nco/data/in.nc ~/foo.nc
LANG=fr_FR.utf8 LANGUAGE=fr_FR:fr:en_GB:en LC_ALL=fr_FR.utf8 ncks -D 1 -O ~/nco/data/in.nc ~/foo.nc */
if(nco_dbg_lvl >= nco_dbg_std) (void)fprintf(stdout,gettext("%s: I18N Current charset = %s\n"),nco_prg_nm,nl_langinfo(CODESET));
if(nco_dbg_lvl >= nco_dbg_std) (void)fprintf(stdout,gettext("%s: I18N This text may appear in a foreign language\n"),nco_prg_nm);
#endif /* !_LANGINFO_H */

/* Initialize traversal table */
(void)trv_tbl_init(&trv_tbl);

Expand Down
6 changes: 3 additions & 3 deletions src/nco/nco_ctl.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Header: /data/zender/nco_20150216/nco/src/nco/nco_ctl.c,v 1.479 2014-06-15 21:06:22 zender Exp $ */
/* $Header: /data/zender/nco_20150216/nco/src/nco/nco_ctl.c,v 1.480 2014-06-17 23:50:01 zender Exp $ */

/* Purpose: Program flow control functions */

Expand Down Expand Up @@ -686,7 +686,7 @@ nco_cnf_prn(void) /* [fnc] Print NCO configuration and help text */
/* Purpose: Print NCO configuration and help text */

(void)fprintf(stdout,"Homepage: http://nco.sf.net\n");
(void)fprintf(stdout,"User's Guide: http://nco.sf.net/nco.html\n");
(void)fprintf(stdout,"User Guide: http://nco.sf.net/nco.html\n");
/* fxm: TKN2YESNO breaks when TKN is undefined
Full macro language like M4 might be useful here, though probably too much trouble */
#define TKN2YESNO(x) ((x+0) ? ("No"):("Yes"))
Expand Down Expand Up @@ -1119,7 +1119,7 @@ nco_usg_prn(void)
(void)fprintf(stdout,"\nEight ways to find more help on %s and/or NCO:\n",nco_prg_nm_get());
(void)fprintf(stdout,"1. Examples: http://nco.sf.net/nco.html#xmp_%s\n",nco_prg_nm_get());
(void)fprintf(stdout,"2. Ref. manual: http://nco.sf.net/nco.html#%s\n",nco_prg_nm_get());
(void)fprintf(stdout,"3. User's Guide: http://nco.sf.net#RTFM\n");
(void)fprintf(stdout,"3. User Guide: http://nco.sf.net#RTFM\n");
(void)fprintf(stdout,"4. Manual pages: \'man %s\', \'man nco\', ...\n",nco_prg_nm_get());
(void)fprintf(stdout,"5. Homepage: http://nco.sf.net\n");
(void)fprintf(stdout,"6. FAQ: http://nco.sf.net#FAQ\n");
Expand Down
11 changes: 3 additions & 8 deletions src/nco/ncra.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Header: /data/zender/nco_20150216/nco/src/nco/ncra.c,v 1.541 2014-06-17 20:39:52 zender Exp $ */
/* $Header: /data/zender/nco_20150216/nco/src/nco/ncra.c,v 1.542 2014-06-17 23:50:01 zender Exp $ */

/* This single source file compiles into three separate executables:
ncra -- netCDF record averager
Expand Down Expand Up @@ -74,7 +74,6 @@
# endif /* !HAVE_GETOPT_H */
#endif /* HAVE_GETOPT_LONG */

/* Internationalization i18n, Linux Journal 200211 p. 57--59 http://www.linuxjournal.com/article/6176 http://fedoraproject.org/wiki/How_to_do_I18N_through_gettext */
#ifdef I18N
# include <langinfo.h> /* nl_langinfo() */
# include <libintl.h> /* Internationalization i18n */
Expand Down Expand Up @@ -136,8 +135,8 @@ main(int argc,char **argv)
char *sng_cnv_rcd=NULL_CEWI; /* [sng] strtol()/strtoul() return code */
char trv_pth[]="/"; /* [sng] Root path of traversal tree */

const char * const CVS_Id="$Id: ncra.c,v 1.541 2014-06-17 20:39:52 zender Exp $";
const char * const CVS_Revision="$Revision: 1.541 $";
const char * const CVS_Id="$Id: ncra.c,v 1.542 2014-06-17 23:50:01 zender Exp $";
const char * const CVS_Revision="$Revision: 1.542 $";
const char * const opt_sht_lst="3467ACcD:d:FG:g:HhL:l:n:Oo:p:P:rRt:v:X:xY:y:-:";

cnk_sct cnk; /* [sct] Chunking structure */
Expand Down Expand Up @@ -612,10 +611,6 @@ main(int argc,char **argv)
if(opt_crr) opt_crr=(char *)nco_free(opt_crr);
} /* end while loop */

#ifdef _LANGINFO_H
if(nco_dbg_lvl >= nco_dbg_std) (void)fprintf(stdout,gettext("%s: I18N Current charset = %s\n"),nco_prg_nm,nl_langinfo(CODESET));
#endif /* !_LANGINFO_H */

/* Process positional arguments and fill in filenames */
fl_lst_in=nco_fl_lst_mk(argv,argc,optind,&fl_nbr,&fl_out,&FL_LST_IN_FROM_STDIN);

Expand Down

0 comments on commit 2f1baea

Please sign in to comment.