From 10898d3ac2433f900159166088ab071fc818d1b3 Mon Sep 17 00:00:00 2001 From: nalin Date: Sat, 12 Jul 2003 08:23:48 +0000 Subject: - convert \N to \n when reading filter output - add a sample .spec doc file - add more scripts --- Makefile | 14 ++++++-- collect-potfiles | 54 +++++++++++++++++++++++++++++ convert-locale | 81 +++++++++++++++++++------------------------- create-locales | 46 +++++++++++++++++++++++++ inject-talkfilter-locales | 50 +++++++++++++++++++++++++++ pomatic.spec | 8 ++++- pomatic.x | 57 +++++++++++++++++++------------ talkfilters-i18n.spec.redhat | 27 +++++++++++++++ 8 files changed, 265 insertions(+), 72 deletions(-) create mode 100755 collect-potfiles create mode 100755 create-locales create mode 100755 inject-talkfilter-locales create mode 100644 talkfilters-i18n.spec.redhat diff --git a/Makefile b/Makefile index dc14bdd..07ad4b3 100644 --- a/Makefile +++ b/Makefile @@ -20,16 +20,26 @@ LDFLAGS=-lfl .x.c: flex -o$@ $^ +SCRIPTS = collect-potfiles convert-locale create-locales inject-talkfilter-locales + install: all mkdir -p $(DESTDIR)$(bindir) mkdir -p $(DESTDIR)$(mandir)/man1 - install -m755 pomatic convert-locale $(DESTDIR)$(bindir)/ + install -m755 pomatic $(SCRIPTS) $(DESTDIR)$(bindir)/ install -m644 pomatic.1 $(DESTDIR)$(mandir)/man1 +clean: + $(RM) *.o pomatic + dist: archive +tag: + cvs tag -c $(CVSTAG) + +force-tag: + cvs tag -cF $(CVSTAG) + archive: - @cvs tag -cF $(CVSTAG) @rm -rf /tmp/pomatic-$(VERSION) /tmp/pomatic @cd /tmp; cvs export -r$(CVSTAG) pomatic; mv pomatic pomatic-$(VERSION) @cd /tmp; tar czSpf pomatic-$(VERSION).tar.gz pomatic-$(VERSION) diff --git a/collect-potfiles b/collect-potfiles new file mode 100755 index 0000000..e72786f --- /dev/null +++ b/collect-potfiles @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Collect .pot files from a set of source packages and place them in +# a specified output directory. +# + +outdir=$1 +shift + +if [ -z "$outdir" ] ; then + echo usage: `basename $0` output_directory sourcerpm '[...]' + exit 1 +fi + +tmpdir=`mktemp -d ${TMPDIR:-/tmp}/collect-potfilesXXXXXX` +if [ -z "$tmpdir" ] ; then + echo error creating tmpdir + exit 1 +fi + +exec < /dev/null + +cleanup() +{ + rm -fr $tmpdir +} +trap cleanup PIPE INT KILL TERM + +for sourcepackage in $@ ; do + rpm \ + --define "_topdir $tmpdir" \ + --define "_sourcedir $tmpdir" \ + --define "_specdir $tmpdir" \ + --define "_builddir $tmpdir" \ + --define "_srpmdir $tmpdir" \ + --define "_rpmdir $tmpdir" \ + -U $sourcepackage > /dev/null 2> /dev/null && + rpmbuild \ + --define "_topdir $tmpdir" \ + --define "_sourcedir $tmpdir" \ + --define "_specdir $tmpdir" \ + --define "_builddir $tmpdir" \ + --define "_srpmdir $tmpdir" \ + --define "_rpmdir $tmpdir" \ + -bp $tmpdir/*.spec > /dev/null 2> /dev/null + for potfile in `find $tmpdir -name "*.pot"`; do + basename $potfile + cp -f $potfile $outdir/ + done + chmod -R u+rw $tmpdir/* + rm -fr $tmpdir/* +done + +cleanup diff --git a/convert-locale b/convert-locale index 39dc3a2..f848263 100755 --- a/convert-locale +++ b/convert-locale @@ -1,61 +1,48 @@ #!/bin/bash +# +# Create translation catalogs on the system for all of the packages for which +# we can find .mo files. +# -SOURCELOCALEDIR=/usr/share/locale +SOURCELOCALEDIRS="/usr/share/locale /usr/lib/locale" DESTLOCALEDIR=$DESTDIR/usr/share/locale -LIBLOCALEDIR=$DESTDIR/usr/lib/locale -SOURCELOCALE=de -DESTLOCALES= +DESTFILTERS= while [ $# -gt 0 ] ; do - case $1 in - --source) - shift - SOURCELOCALE=$1 - shift - ;; - *) - DESTLOCALES="$DESTLOCALES $1" - shift - ;; - esac + DESTFILTERS="$DESTFILTERS $1" + shift done -if [ -z "$DESTLOCALES" ] ; then - echo Usage: `basename $0` '[--source sourcelocale]' 'destlocale [...]' +if [ -z "$DESTFILTERS" ] ; then + echo Usage: `basename $0` 'filter [...]' fi -messagedir=$SOURCELOCALEDIR/$SOURCELOCALE/LC_MESSAGES +exec < /dev/null -for DESTLOCALE in $DESTLOCALES ; do - aliasfile=/usr/X11R6/lib/X11/locale/locale.alias - alias=`basename $DESTLOCALE` +PACKAGES=`find $SOURCELOCALEDIRS -name "*.mo" -print0 | xargs -0 -n1 basename | sed 's,.mo$,,g' | sort -u` - echo Converting strings from $SOURCELOCALE using $alias. - - test -d $LIBLOCALEDIR || mkdir -p $LIBLOCALEDIR - test -d $DESTLOCALEDIR/$alias/LC_MESSAGES || \ - mkdir -p $DESTLOCALEDIR/$alias/LC_MESSAGES - - test -d $LIBLOCALEDIR/$alias/LC_MESSAGES || \ - ln -s /usr/lib/locale/en_US $LIBLOCALEDIR/$alias - - sources=`find $messagedir -type f -name "*.mo" | sort` - - for source in $sources ; do - domain=`basename $source .mo` - echo " $domain" - target=$DESTLOCALEDIR/$alias/LC_MESSAGES/$domain.mo - TMP1=`mktemp /tmp/convert${domain}XXXXXX` - TMP2=`mktemp /tmp/convert${domain}XXXXXX` - msgunfmt $source > $TMP1 - pomatic $TMP1 $DESTLOCALE > $TMP2 - msgfmt -o $target $TMP2 - rm $TMP1 $TMP2 - done - echo - - if ! grep -q ^$alias: $aliasfile ; then - echo $alias: en_US.ISO8859-1 >> $aliasfile +for filter in $DESTFILTERS ; do + destlocale=en_US@$filter + test -d $DESTLOCALEDIR/$destlocale/LC_MESSAGES || \ + mkdir -p $DESTLOCALEDIR/$destlocale/LC_MESSAGES +done +for package in $PACKAGES ; do + sourcemo=`find $SOURCELOCALEDIRS -name $package.mo | head -n1` + if test -n "$sourcemo" ; then + echo -n $package + for filter in $DESTFILTERS ; do + destlocale=en_US@$filter + msgunfmt $sourcemo | \ + pomatic /dev/stdin $filter | \ + msgfmt -o $DESTLOCALEDIR/$destlocale/LC_MESSAGES/$package.mo - && \ + echo -n " $destlocale" + done + echo "" fi done +for filter in $DESTFILTERS ; do + destlocale=en_US@$filter + test -d $DESTLOCALEDIR/$destlocale/LC_MESSAGES && \ + rmdir $DESTLOCALEDIR/$destlocale/LC_MESSAGES 2> /dev/null +done diff --git a/create-locales b/create-locales new file mode 100755 index 0000000..543c80f --- /dev/null +++ b/create-locales @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Generate new .mo files for each of the packages in a given directory. +# +if [ $# -lt 1 ] ; then + echo usage: `basename $0` source_rpm_directory + exit 1 +fi +localedir=${DESTDIR:-}/usr/share/locale +filters="biffster chef drawl jive krad kraut l33t redneck valspeak" + +tmpdir=`mktemp -d ${TMPDIR:-/tmp}/create-localesXXXXXX` +if [ -z "$tmpdir" ] ; then + echo error creating tmpdir + exit 1 +fi + +exec < /dev/null + +cleanup() +{ + rm -fr $tmpdir +} +trap cleanup PIPE INT KILL TERM + +echo '>>>> Collecting potfiles. <<<<' +collect-potfiles $tmpdir `find $@ -name "*.src.rpm" | sort` + +echo '>>>> Generating translations. <<<<' +for filter in $filters ; do + locale=en_US@$filter + test -d $localedir/$locale/LC_MESSAGES || \ + mkdir -p $localedir/$locale/LC_MESSAGES +done +for potfile in $tmpdir/*.pot ; do + locale=en_US@$filter + potfilename=`basename $potfile` + package=`basename $potfilename .pot` + echo -n "$package " + for filter in $filters ; do + pomatic $potfile $filter | msgfmt -o $localedir/$locale/LC_MESSAGES/$package.mo - && echo -n " $filter" + done + echo "" +done + +cleanup diff --git a/inject-talkfilter-locales b/inject-talkfilter-locales new file mode 100755 index 0000000..fe76f6c --- /dev/null +++ b/inject-talkfilter-locales @@ -0,0 +1,50 @@ +#!/bin/sh +# +# Add translations for $po_filters for every .pot file in this tree, and if +# we find what looks like autoconf scripts setting ALL_LINGUAS, add the +# new translations to the list of languages. +# +po_filters="biffster chef drawl jive krad kraut l33t redneck valspeak" +quiet=false + +exec < /dev/null + +for arg in $@ ; do + case "$arg" in + --quiet) quiet=true ;; + *) po_filters="$po_filters $arg" ;; + esac +done + +for filter in $po_filters ; do + fakelang="en_US@$filter" + + found=false + for potfile in `find . -name "*.pot"` ; do + if test -r "$potfile" ; then + subdir=`dirname $potfile` + if ! $quiet ; then + echo "Generating $fakelang translation." + fi + pomatic $potfile $filter > $subdir/$fakelang.po + found=true + fi + done + + if ! $found ; then + continue + fi + + for script in `find . -name configure.in -o -name configure.ac -o -name configure` ; do + if test -r $script ; then + sed -e 's,^ALL_LINGUAS="\(.*\)",ALL_LINGUAS="\1 '"$fakelang"'",g' $script > $script.___spec_prep_post && \ + chmod --reference $script $script.___spec_prep_post && \ + touch -r $script $script.___spec_prep_post && \ + mv -f $script.___spec_prep_post $script && \ + $quiet || echo "Added $fakelang to ALL_LINGUAS in $script." + if test -r $script.__spec_prep_post ; then + rm -f $script.___spec_prep_post + fi + fi + done +done diff --git a/pomatic.spec b/pomatic.spec index 9a72e95..e83ba52 100644 --- a/pomatic.spec +++ b/pomatic.spec @@ -1,5 +1,5 @@ Name: pomatic -Version: 1.0.1 +Version: 1.0.2 Release: 1 Source: %{name}-%{version}.tar.gz Summary: pomatic @@ -26,10 +26,16 @@ rm -fr $RPM_BUILD_ROOT %files %defattr(-,root,root) +%doc talkfilters-i18n.spec.redhat %{_bindir}/* %{_mandir}/*/* %changelog +* Sat Jul 12 2003 Nalin Dahyabhai +- convert \N to \n when reading filter output +- add a sample .spec doc file +- add more scripts + * Fri Aug 3 2001 Nalin Dahyabhai - fixup empty-string translation to include actual header information diff --git a/pomatic.x b/pomatic.x index 7293eac..9478a77 100644 --- a/pomatic.x +++ b/pomatic.x @@ -24,18 +24,18 @@ char *filter = "cat"; struct passwd *pwd; time_t now; struct tm tm; - if(string == str) { - if(msgid) { + if (string == str) { + if (msgid) { printf("msgid %s", msgid); } else { printf("msgid \"\"\n"); } - if(strcmp(msgid, "\"\"\n") == 0) { + if (strcmp(msgid, "\"\"\n") == 0) { pwd = getpwuid(getuid()); now = time(NULL); tm = *(gmtime(&now)); - if(pwd) { - if(strchr(pwd->pw_gecos, ',')) { + if (pwd) { + if (strchr(pwd->pw_gecos, ',')) { char *p = strchr(pwd->pw_gecos, ','); *p = '\0'; } @@ -60,7 +60,7 @@ char *filter = "cat"; pipe(opipe); childpid = fork(); - if(childpid == 0) { + if (childpid == 0) { /* child */ dup2(ipipe[0], STDIN_FILENO); close(ipipe[1]); @@ -77,26 +77,39 @@ char *filter = "cat"; msgpipe = fdopen(opipe[0], "r"); printf("msgstr \"\"\n"); - while(fgets(message, sizeof(message), msgpipe)) { - for(i = 0; message[i]; i++) { - if(i > 0) - if(message[i] == '"') - if(message[i - 1] != '\\') - if(message[i - 1] != '\n') - if(message[i + 1] != '\n') + while (fgets(message, sizeof(message), msgpipe)) { + for (i = 0; message[i]; i++) { + if (i > 0) + if (message[i] == '"') + if (message[i - 1] != '\\') + if (message[i - 1] != '\n') + if (message[i + 1] != '\n') fputc('\\', stdout); fputc(message[i], stdout); + if (message[i] == '\\') { + switch (message[i + 1]) { + case 'N': + message[i + 1] = 'n'; + break; + case 'R': + message[i + 1] = 'r'; + break; + case 'T': + message[i + 1] = 't'; + break; + } + } } } waitpid(childpid, NULL, 0); fclose(msgpipe); } - if(msgid) + if (msgid) free(msgid); msgid = NULL; - if(msgstr) + if (msgstr) free(msgstr); msgstr = NULL; } @@ -108,7 +121,7 @@ char *filter = "cat"; \".*\"\n { char *tmp; char **target = NULL; - if(string == str) { + if (string == str) { target = &msgstr; } else { target = &msgid; @@ -127,27 +140,27 @@ main(int argc, char **argv) { int base = 0; yyin = stdin; - if(argc == 1) { + if (argc == 1) { printf("Usage: %s [-s] [potfile] [filter]\n", strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0]); return 1; } - if(argc > 1) { - if(strcmp(argv[1], "-s") == 0) { + if (argc > 1) { + if (strcmp(argv[1], "-s") == 0) { mode = str; base++; } } - if(argc > base + 1) { + if (argc > base + 1) { yyin = fopen(argv[base + 1], "r"); } - if(argc > base + 2) { + if (argc > base + 2) { filter = argv[base + 2]; } - while(yyin && !feof(yyin)) + while (yyin && !feof(yyin)) yylex(); return 0; diff --git a/talkfilters-i18n.spec.redhat b/talkfilters-i18n.spec.redhat new file mode 100644 index 0000000..4ce95e4 --- /dev/null +++ b/talkfilters-i18n.spec.redhat @@ -0,0 +1,27 @@ +Name: talkfilters-i18n +Version: 1.0 +Release: 1 +Summary: talkfilters translations +Group: Applications/Text +License: GPL +BuildRoot: %{_tmppath}/%{name}-root +BuildPrereq: talkfilters, pomatic >= 1.0.2 +ExclusiveArch: noarch + +%description +The talkfilters-i18n package contains translations for applications. + +%install +rm -fr $RPM_BUILD_ROOT +env DESTDIR=$RPM_BUILD_ROOT create-locales /mnt/redhat/test/latest-i386/SRPMS/ + +%clean +rm -fr $RPM_BUILD_ROOT + +%files +%defattr(-,root,root) +%{_datadir}/locale/*/LC_MESSAGES/* + +%changelog +* Fri Jul 11 2003 Nalin Dahyabhai +- initial package -- cgit