pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/devel/gettext-lib Add a script to workaround uses of m...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/a8205d306025
branches:  trunk
changeset: 471908:a8205d306025
user:      jmmv <jmmv%pkgsrc.org@localhost>
date:      Thu Apr 01 18:33:20 2004 +0000

description:
Add a script to workaround uses of msgid_plural, which is not yet supported
by our native libintl.  While it is not implemented, this allows us to build
programs against the native libintl, loosing very few functionality (some
translations of plural messages on few languages), and avoiding runtime
conflicts between native libintl and the gnu one (coming from the gettext
package).

Packages including .po files with uses of msgid_plural should define the
USE_MSGFMT_PLURALS variable to 'yes', so that the msgfmt wrapper is used.
(Do not use it when not really needed, as it will pull in perl5 as a build
dependancy).

diffstat:

 devel/gettext-lib/buildlink2.mk |   20 ++++++-
 devel/gettext-lib/builtin.mk    |   20 ++++++-
 devel/gettext/files/msgfmt.pl   |  110 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 148 insertions(+), 2 deletions(-)

diffs (178 lines):

diff -r 5ddb4f02a1bf -r a8205d306025 devel/gettext-lib/buildlink2.mk
--- a/devel/gettext-lib/buildlink2.mk   Thu Apr 01 18:32:37 2004 +0000
+++ b/devel/gettext-lib/buildlink2.mk   Thu Apr 01 18:33:20 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: buildlink2.mk,v 1.31 2004/03/29 05:05:34 jlam Exp $
+# $NetBSD: buildlink2.mk,v 1.32 2004/04/01 18:33:20 jmmv Exp $
 
 .if !defined(GETTEXT_BUILDLINK2_MK)
 GETTEXT_BUILDLINK2_MK= # defined
@@ -165,4 +165,22 @@
        libpattern="${BUILDLINK_PREFIX.gettext}/lib/libintl.*";         \
        ${BUILDLINK_FAKE_LA}
 
+.if defined(USE_MSGFMT_PLURALS) && !empty(USE_MSGFMT_PLURALS:M[Yy][Ee][Ss])
+USE_PERL5?=            build
+CONFIGURE_ENV+=                MSGFMT=${BUILDLINK_DIR}/bin/msgfmt
+
+SUBST_CLASSES+=                        fix-msgfmt
+SUBST_STAGE.fix-msgfmt=                post-buildlink
+SUBST_MESSAGE.fix-msgfmt=      "Fixing paths in msgfmt wrapper."
+SUBST_FILES.fix-msgfmt=                ${BUILDLINK_DIR}/bin/msgfmt
+SUBST_SED.fix-msgfmt=          -e 's|@PERL@|${PERL5}|g'
+SUBST_SED.fix-msgfmt+=         -e 's|@MSGFMT@|${BUILDLINK_PREFIX.gettext}/bin/msgfmt|g'
+
+BUILDLINK_TARGETS+=    buildlink-msgfmt
+
+buildlink-msgfmt:
+       @${CP} ../../devel/gettext/files/msgfmt.pl ${BUILDLINK_DIR}/bin/msgfmt
+       @${CHMOD} +x ${BUILDLINK_DIR}/bin/msgfmt
+.endif
+
 .endif # GETTEXT_BUILDLINK2_MK
diff -r 5ddb4f02a1bf -r a8205d306025 devel/gettext-lib/builtin.mk
--- a/devel/gettext-lib/builtin.mk      Thu Apr 01 18:32:37 2004 +0000
+++ b/devel/gettext-lib/builtin.mk      Thu Apr 01 18:33:20 2004 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: builtin.mk,v 1.4 2004/03/29 05:43:30 jlam Exp $
+# $NetBSD: builtin.mk,v 1.5 2004/04/01 18:33:20 jmmv Exp $
 
 .if !defined(_BLNK_LIBINTL_FOUND)
 _BLNK_LIBINTL_FOUND!=  \
@@ -150,4 +150,22 @@
 .  endif
 .endif
 
+.if defined(USE_MSGFMT_PLURALS) && !empty(USE_MSGFMT_PLURALS:M[Yy][Ee][Ss])
+USE_PERL5?=            build
+CONFIGURE_ENV+=                MSGFMT=${BUILDLINK_DIR}/bin/msgfmt
+
+SUBST_CLASSES+=                        fix-msgfmt
+SUBST_STAGE.fix-msgfmt=                post-buildlink
+SUBST_MESSAGE.fix-msgfmt=      "Fixing paths in msgfmt wrapper."
+SUBST_FILES.fix-msgfmt=                ${BUILDLINK_DIR}/bin/msgfmt
+SUBST_SED.fix-msgfmt=          -e 's|@PERL@|${PERL5}|g'
+SUBST_SED.fix-msgfmt+=         -e 's|@MSGFMT@|${BUILDLINK_PREFIX.gettext}/bin/msgfmt|g'
+
+BUILDLINK_TARGETS+=    buildlink-msgfmt
+
+buildlink-msgfmt:
+       @${CP} ../../devel/gettext/files/msgfmt.pl ${BUILDLINK_DIR}/bin/msgfmt
+       @${CHMOD} +x ${BUILDLINK_DIR}/bin/msgfmt
+.endif
+
 .endif # CHECK_BUILTIN.gettext
diff -r 5ddb4f02a1bf -r a8205d306025 devel/gettext/files/msgfmt.pl
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/devel/gettext/files/msgfmt.pl     Thu Apr 01 18:33:20 2004 +0000
@@ -0,0 +1,110 @@
+#!@PERL@
+#
+# $NetBSD: msgfmt.pl,v 1.1 2004/04/01 18:33:20 jmmv Exp $
+#
+# msgfmt.pl - Workaround uses of msgid_plural to work with implementations
+#             that don't support it.
+#
+# Copyright (c) 2004 Julio M. Merino Vidal <jmmv%NetBSD.org@localhost>
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in
+#    the documentation and/or other materials provided with the
+#    distribution.
+# 3. Neither the name of author nor the names of its contributors may
+#    be used to endorse or promote products derived from this software
+#    without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+# Parse command line.  We copy almost everything as is in the @args array,
+# which will be used later when calling the real "msgfmt" utility.  As an
+# exception, the file name is transformed to the temporary file we will
+# use, and the original one is stored in the $file variable.
+@args = ();
+$file = "";
+$skip = 0;
+foreach (@ARGV) {
+    if ($skip) {
+        $skip = 0;
+    } elsif (/^-(a|D|o)$/) {
+        $skip = 1;
+    } elsif (/^--(alignment|directory|output-file)$/) {
+        $skip = 1;
+    } elsif (/^[^-]/) {
+        $file = $_;
+        $_ = "$file.tmp";
+    }
+
+    push @args, $_;
+}
+
+# Parse the catalog file to convert msgid_plural entries to the "old"
+# format, which handles each of the translations independantly.
+open INFILE, $file;
+open OUTFILE, ">$file.tmp";
+
+$read_plural = 0;
+$skip = 0;
+@msgid_plural = ();
+
+printf "Fixing plural forms in $file\n";
+while (<INFILE>) {
+    if (/^msgid_plural/) {
+        $read_plural = 1;
+        s/^msgid_plural[ \t]+"/"/;
+        push @msgid_plural, $_;
+    } elsif ($read_plural && /^msgstr\[0\]/) {
+        $read_plural = 0;
+        s/^msgstr\[0\]/msgstr/;
+        print OUTFILE;
+    } elsif ($read_plural) {
+        push @msgid_plural, $_;
+    } elsif (/^msgstr\[1\]/) {
+        print OUTFILE "\n";
+        print OUTFILE "msgid ";
+        foreach $line (@msgid_plural) {
+            print OUTFILE "$line";
+        }
+        s/^msgstr\[1\]/msgstr/;
+        print OUTFILE;
+        @msgid_plural = ();
+    } elsif (/^msgstr\[2\]/) {
+       $skip = 1;
+    } elsif (/^[ \t]*$/) {
+       $skip = 0;
+        print OUTFILE;
+    } elsif (! $skip) {
+        print OUTFILE;
+    }
+}
+
+close OUTFILE;
+close INFILE;
+
+# Call the real msgfmt utility, using the temporary file as the source
+# catalog.
+printf "Running `@MSGFMT@ @args'\n";
+$ret = system("@MSGFMT@ @args") >> 8;
+
+if ($ret == 0) {
+    unlink "$file.tmp";
+}
+
+exit $ret;



Home | Main Index | Thread Index | Old Index