diff options
author | Anas Nashif <anas.nashif@intel.com> | 2012-11-08 07:23:59 -0800 |
---|---|---|
committer | Anas Nashif <anas.nashif@intel.com> | 2012-11-08 07:23:59 -0800 |
commit | 95f620342fa1cadde2a645061444aee04e01ad78 (patch) | |
tree | 342a30b71ad2e55bfba3e85f5d950f3c3a2770d3 | |
download | perl-gettext-95f620342fa1cadde2a645061444aee04e01ad78.tar.gz perl-gettext-95f620342fa1cadde2a645061444aee04e01ad78.tar.bz2 perl-gettext-95f620342fa1cadde2a645061444aee04e01ad78.zip |
Imported Upstream version 1.05upstream/1.05
-rw-r--r-- | Makefile.PL | 66 | ||||
-rw-r--r-- | README | 230 | ||||
-rw-r--r-- | config.h | 4 | ||||
-rw-r--r-- | gettext.pm | 282 | ||||
-rw-r--r-- | gettext.xs | 118 | ||||
-rw-r--r-- | t/bind.t | 16 | ||||
-rw-r--r-- | t/frconvert.t | 29 | ||||
-rw-r--r-- | t/jaconvert.t | 27 | ||||
-rw-r--r-- | t/raw.t | 18 | ||||
-rw-r--r-- | t/use.t | 8 | ||||
-rw-r--r-- | test_data/foo.po | 8 | ||||
-rw-r--r-- | test_data/gen_test_data.pl | 50 | ||||
-rw-r--r-- | test_data/jaeuc.po | 5 |
13 files changed, 861 insertions, 0 deletions
diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..e1f7d45 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,66 @@ +use ExtUtils::MakeMaker; +use Config; + +my $cc; +if (defined($ENV{'CC'})) { + $cc = $ENV{'CC'}; +} else { + $cc = $Config{'cc'}; +} +my $libs = ''; + +unless (conftest("char *x = gettext(\"foo\");", "gettext", 0)) { + # try with -lintl + $libs = "-lintl"; + unless (conftest("char *x = gettext(\"foo\");", "gettext", 0)) { + unlink("conftest.c"); + unlink("conftest"); + die "gettext function not found. Please install libintl"; + } +} + +open(CONFIG, ">config.h"); +print CONFIG "/* Generated automatically by ", $0, ". Do not edit */\n"; + +conftest("char *x = dcgettext(\"foo\", \"bar\", 0);", "dgettext", 1); +conftest("char *x = ngettext(\"foo\", \"foos\", 1);", "ngettext", 1); +conftest("char *x = bind_textdomain_codeset(\"foo\", \"UTF-8\");", "bind_textdomain_codeset", 1); + +close CONFIG; + +unlink("conftest.c"); +unlink("conftest"); + +WriteMakefile( + NAME => "Locale::gettext", + LIBS => ($libs eq '') ? [] : [$libs], + VERSION_FROM => 'gettext.pm', +); + +sub conftest { + my ($testcode, $func, $record) = @_; + + print "checking for ", $func; + print(" in ", $libs) if ($libs ne ''); + print "..."; + open(TEST, ">conftest.c"); + print TEST "#include <libintl.h>\n\nint main(int argc, char **argv)\n{\n"; + print TEST $testcode; + print TEST "return 0;}\n"; + close TEST; + open(SAVE, ">&STDERR"); + open(STDERR, ">/dev/null"); + system($cc . " -o conftest " . $libs . " conftest.c"); + my $exitstatus = $?; + open(STDERR, ">&SAVE"); + if ($exitstatus != 0) { + print " no\n"; + return 0; + } else { + print " yes\n"; + if ($record) { + print CONFIG "#define HAVE_", uc($func), "\n"; + } + return 1; + } +} @@ -0,0 +1,230 @@ +Locale::gettext +version 1.05 + +This is a perl5 module quickly written to gain access to +the C library functions for internatialization. They +work just like the C versions. + +As of version 1.04, an object oriented interface more +suitable to native Perl programs is available. + +Locale::gettext is Copyright 1996..2005 by Phillip Vandry +<vandry@TZoNE.ORG>. All rights reserved. + +This library is free software; you may distribute under the terms +of either the GNU General Public License or the Artistic License, as +specified in the Perl README file. + +Changes +------- + +1.05 Bugfix: [cpan #13042] useless #ifdef should be #if + Bugfix: [cpan #13044] make test fails when using POSIX locale + +1.04 Add several functions provided by the GNU gettext library + Create object oriented interface + +1.03 Fix error in README file + +1.02 Include a License + +1.01 Changed from "gettext" to "Locale::gettext" (i.e. + moved under Locale::) on the advice of several + people + + Small "lint" fix from schwern@starmedia.net + +1.00 Initial version + +TODO +---- + +A TIEHASH interface + +Here's a quick tutorial. +----------------------- + +Note that your vendor's implementation of these functions +may be a bit different, but I think that in general these +are quite standard POSIX functions. + +Phillip Vandry <vandry@TZoNE.ORG> +Mlink Internet <http://www.Mlink.NET> +July 1996 + +INTERNATIONALIZING YOUR PROGRAM + +Step 1 +------ + +If you've already written your code, you need to +wrap the gettext() function around all of the +text strings. Needless to say, this is much easier if +you do it while you write. + +# create object for oo interface +my $d = Locale::gettext->domain("my_program"); + +print "Welcome to my program\n"; + +# oo +print $d->get("Welcome to my program"), "\n"; + +# traditional +print gettext("Welcome to my program"), "\n"; + +Note that you probably don't want to include that newline +in the gettext() call, nor any formatting codes such as +HTML tags. The argument to gettext() is the text string +in the default language or locale. This is known as the +C locale and should probably be usually English. + +Step 2 +------ + +Do the apropriate initializations at the beginning of your +program: + +# +use POSIX; # for setlocale() +use Locale::gettext; +# +# The following statement initializes the locale handling +# code in the C library. Normally, it causes it to read +# in the environment variables that determine the current +# locale. +# +# The first parameter is the category you would +# like to initialize locale information for. You can use +# LC_ALL for this, which will set locale information for +# all categories, including LC_CTYPE, LC_TIME, LC_NUMERIC, +# etc.. +# +# I recommend that you set only LC_MESSAGES (text strings) +# or LC_CTYPE (character sets) and LC_TIME (time +# conventions) too at most. You may find that if you set +# LC_NUMERIC or some other categories, you will start +# outputting decimal numbers with strange thousand separators +# and decimal points and they will be unparseable in +# other countries. +# +# The second parameter is the locale name. If it is an +# empty string, then this information will be fetched from +# environment variables. +# +# Note that setlocale() will cause every part of your +# program to start operating in the new, non default (C) +# locale, including C library functions. So don't be +# surprised if POSIX::ctime returns "Montag, 22. Juli 1996, +# 12:08:25 Uhr EDT" instead of "Mon Jul 22 12:08:25 EDT 1996" +# If you set LC_TIME or LC_ALL using setlocale(). +# +setlocale(LC_MESSAGES, ""); +# +# Decide on a unique identifier that will distinguish your +# program's text strings in the LC_MESSAGES database. This +# would usually be the name of your program +# +# By default, locale information is found in OS dependant +# system directories such as /usr/lib/locale, or any directory +# found in the $PATH-like environment variable $NLSPATH. +# I recommend that you do _not_ install files in /usr. If +# your program is installed in a directory tree such as +# /opt/my_package_name/{bin,man,lib,etc}, then you could +# use /opt/my_package_name/locale to store locale information +# specific to your program, or you could put in somewhere +# in /usr/local/lib. +# +# Wherever you put it, if it is not one of the default +# directories, you will need to call bindtextdomain() to +# tell the library where to find your files. The first +# parameter is your database's identifier that you chose +# above. +# +# oo interface: + +my $d = Locale::gettext->domain("my_domain"); +$d->dir("/opt/my_package_name/locale"); + +# traditional interface: +bindtextdomain("my_domain", "/opt/my_package_name/locale"); +textdomain("my_domain"); + +# That's it for the initializations + +Step 3 +------ + +Test to see if your program still works after all these mods :-) + +Step 4 +------ + +TRANSLATE! + +Read msgfmt(1) for details on this. Basically, for each locale +other than the default, you need to create a file like this: +(Note: I do not speak German, I'm making an attempt here :-) +Call this file with the .po extension. + +--BEGIN +domain "my_domain" + +msgid "Welcome to my program" +msgstr "Willkommen in mein Program" + +msgid "Help" +msgstr "Hilfe" +--END + +The "msgid" parameter must match exactly the argument to the +gettext() function, and "msgstr" is the corresponding translation. + +You can use the xgettext(1) utility to initially construct this +file from all of the gettext() calls in your source code. It was +designed for C but it works OK with perl. + +Step 5 +------ + +Compile the .po file + +$ msgfmt my_file.po + +This will create a file called my_domain.mo (default messages.mo) +which you should place in the <locale>/LC_MESSAGES/my_domain.mo +subdirectory of either a system default directory, a directory +in $NLSPATH, or the directory argument to bindtextdomain(). +Replace <locale> with the name of the locale for which this file +is created. + +For example: + +$ mkdir -p /opt/my_package/locale/de/LC_MESSAGES +$ mkdir -p /opt/my_package/locale/fr/LC_MESSAGES +$ cd /path/to/my/source/code +$ cd de +$ msgfmt my_domain.po +$ mv my_domain.mo /opt/my_package/locale/de/LC_MESSAGES +$ cd ../fr +$ msgfmt my_domain.po +$ mv my_domain.mo /opt/my_package/locale/fr/LC_MESSAGES + +Step 6 +------ + +Test it out + +$ my_program +Welcome to my program +$ LANG=fr my_program +Bienvenue à mon programme +$ LANG=de my_program +Willkommen in mein Program + +(Or, set only the messages category instead of the whole locale) + +$ LC_MESSAGES=fr +$ export LC_MESSAGES +$ my_program +Bienvenue à mon programme diff --git a/config.h b/config.h new file mode 100644 index 0000000..2f6619c --- /dev/null +++ b/config.h @@ -0,0 +1,4 @@ +/* Generated automatically by Makefile.PL. Do not edit */ +#define HAVE_DGETTEXT +#define HAVE_NGETTEXT +#define HAVE_BIND_TEXTDOMAIN_CODESET diff --git a/gettext.pm b/gettext.pm new file mode 100644 index 0000000..fa2465a --- /dev/null +++ b/gettext.pm @@ -0,0 +1,282 @@ +package Locale::gettext; + +=head1 NAME + +Locale::gettext - message handling functions + +=head1 SYNOPSIS + + use Locale::gettext; + use POSIX; # Needed for setlocale() + + setlocale(LC_MESSAGES, ""); + + # OO interface + my $d = Locale::gettext->domain("my_program"); + + print $d->get("Welcome to my program"), "\n"; + # (printed in the local language) + + # Direct access to C functions + textdomain("my_program"); + + print gettext("Welcome to my program"), "\n"; + # (printed in the local language) + +=head1 DESCRIPTION + +The gettext module permits access from perl to the gettext() family of +functions for retrieving message strings from databases constructed +to internationalize software. + +=cut + +use Carp; + +require Exporter; +require DynaLoader; +@ISA = qw(Exporter DynaLoader); + +BEGIN { + eval { + require Encode; + $encode_available = 1; + }; + import Encode if ($encode_available); +} + +$VERSION = "1.05" ; + +%EXPORT_TAGS = ( + + locale_h => [qw(LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES LC_ALL)], + + libintl_h => [qw(gettext textdomain bindtextdomain dcgettext dgettext ngettext dngettext dcngettext bind_textdomain_codeset)], + +); + +Exporter::export_tags(); + +@EXPORT_OK = qw( +); + +bootstrap Locale::gettext $VERSION; + +sub AUTOLOAD { + local $! = 0; + my $constname = $AUTOLOAD; + $constname =~ s/.*:://; + my $val = constant($constname, (@_ ? $_[0] : 0)); + if ($! == 0) { + *$AUTOLOAD = sub { $val }; + } + else { + croak "Missing constant $constname"; + } + goto &$AUTOLOAD; +} + +=over 2 + +=item $d = Locale::gettext->domain(DOMAIN) + +=item $d = Locale::gettext->domain_raw(DOMAIN) + +Creates a new object for retrieving strings in the domain B<DOMAIN> +and returns it. C<domain> requests that strings be returned as +Perl strings (possibly with wide characters) if possible while +C<domain_raw> requests that octet strings directly from functions +like C<dgettext()>. + +=cut + +sub domain_raw { + my ($class, $domain) = @_; + my $self = { domain => $domain, raw => 1 }; + bless $self, $class; +} + +sub domain { + my ($class, $domain) = @_; + unless ($encode_available) { + croak "Encode module not available, cannot use Locale::gettext->domain"; + } + my $self = { domain => $domain, raw => 0 }; + bless $self, $class; + eval { bind_textdomain_codeset($self->{domain}, "UTF-8"); }; + if ($@ =~ /not implemented/) { + # emulate it + $self->{emulate} = 1; + } elsif ($@ ne '') { + die; # some other problem + } + $self; +} + +=item $d->get(MSGID) + +Calls C<dgettext()> to return the translated string for the given +B<MSGID>. + +=cut + +sub get { + my ($self, $msgid) = @_; + $self->_convert(dgettext($self->{domain}, $msgid)); +} + +=item $d->cget(MSGID, CATEGORY) + +Calls C<dcgettext()> to return the translated string for the given +B<MSGID> in the given B<CATEGORY>. + +=cut + +sub cget { + my ($self, $msgid, $category) = @_; + $self->_convert(dcgettext($self->{domain}, $msgid, $category)); +} + +=item $d->nget(MSGID, MSGID_PLURAL, N) + +Calls C<dngettext()> to return the translated string for the given +B<MSGID> or B<MSGID_PLURAL> depending on B<N>. + +=cut + +sub nget { + my ($self, $msgid, $msgid_plural, $n) = @_; + $self->_convert(dngettext($self->{domain}, $msgid, $msgid_plural, $n)); +} + +=item $d->ncget(MSGID, MSGID_PLURAL, N, CATEGORY) + +Calls C<dngettext()> to return the translated string for the given +B<MSGID> or B<MSGID_PLURAL> depending on B<N> in the given +B<CATEGORY>. + +=cut + +sub ncget { + my ($self, $msgid, $msgid_plural, $n, $category) = @_; + $self->_convert(dcngettext($self->{domain}, $msgid, $msgid_plural, $n, $category)); +} + +=item $d->dir([NEWDIR]) + +If B<NEWDIR> is given, calls C<bindtextdomain> to set the +name of the directory where messages for the domain +represented by C<$d> are found. Returns the (possibly changed) +current directory name. + +=cut + +sub dir { + my ($self, $newdir) = @_; + if (defined($newdir)) { + bindtextdomain($self->{domain}, $newdir); + } else { + bindtextdomain($self->{domain}); + } +} + +=item $d->codeset([NEWCODE]) + +For instances created with C<Locale::gettext-E<gt>domain_raw>, manuiplates +the character set of the returned strings. +If B<NEWCODE> is given, calls C<bind_textdomain_codeset> to set the +character encoding in which messages for the domain +represented by C<$d> are returned. Returns the (possibly changed) +current encoding name. + +=cut + +sub codeset { + my ($self, $codeset) = @_; + if ($self->{raw} < 1) { + warn "Locale::gettext->codeset: meaningful only for instances created with domain_raw"; + return; + } + if (defined($codeset)) { + bind_textdomain_codeset($self->{domain}, $codeset); + } else { + bind_textdomain_codeset($self->{domain}); + } +} + +sub _convert { + my ($self, $str) = @_; + return $str if ($self->{raw}); + # thanks to the use of UTF-8 in bind_textdomain_codeset, the + # result should always be valid UTF-8 when raw mode is not used. + if ($self->{emulate}) { + delete $self->{emulate}; + $self->{raw} = 1; + my $null = $self->get(""); + if ($null =~ /charset=(\S+)/) { + $self->{decode_from} = $1; + $self->{raw} = 0; + } #else matches the behaviour of glibc - no null entry + # means no conversion is done + } + if ($self->{decode_from}) { + return decode($self->{decode_from}, $str); + } else { + return decode_utf8($str); + } +} + +sub DESTROY { + my ($self) = @_; +} + +=back + +gettext(), dgettext(), and dcgettext() attempt to retrieve a string +matching their C<msgid> parameter within the context of the current +locale. dcgettext() takes the message's category and the text domain +as parameters while dcgettext() defaults to the LC_MESSAGES category +and gettext() defaults to LC_MESSAGES and uses the current text domain. +If the string is not found in the database, then C<msgid> is returned. + +ngettext(), dngettext(), and dcngettext() function similarily but +implement differentiation of messages between singular and plural. +See the documentation for the corresponding C functions for details. + +textdomain() sets the current text domain and returns the previously +active domain. + +I<bindtextdomain(domain, dirname)> instructs the retrieval functions to look +for the databases belonging to domain C<domain> in the directory +C<dirname> + +I<bind_textdomain_codeset(domain, codeset)> instructs the retrieval +functions to translate the returned messages to the character encoding +given by B<codeset> if the encoding of the message catalog is known. + +=head1 NOTES + +Not all platforms provide all of the functions. Functions that are +not available in the underlying C library will not be available in +Perl either. + +Perl programs should use the object interface. In addition to being +able to return native Perl wide character strings, +C<bind_textdomain_codeset> will be emulated if the C library does +not provide it. + +=head1 VERSION + +1.05. + +=head1 SEE ALSO + +gettext(3i), gettext(1), msgfmt(1) + +=head1 AUTHOR + +Phillip Vandry <vandry@TZoNE.ORG> + +=cut + +1; diff --git a/gettext.xs b/gettext.xs new file mode 100644 index 0000000..adf6203 --- /dev/null +++ b/gettext.xs @@ -0,0 +1,118 @@ +#include "EXTERN.h" +#include "perl.h" +#include "XSUB.h" +#include <string.h> +#include <libintl.h> +#include "config.h" + +static double +constant(char *name, int arg) +{ + errno = 0; + if (strEQ(name, "LC_CTYPE")) return LC_CTYPE; + if (strEQ(name, "LC_NUMERIC")) return LC_NUMERIC; + if (strEQ(name, "LC_COLLATE")) return LC_COLLATE; + if (strEQ(name, "LC_MONETARY")) return LC_MONETARY; + if (strEQ(name, "LC_MESSAGES")) return LC_MESSAGES; + if (strEQ(name, "LC_ALL")) return LC_ALL; + errno = EINVAL; + return 0; +} + +#define ANY_MISSING 0 + +#ifndef HAVE_DGETTEXT +/* if dgettext is not there, neither will + dcgettext, dngettext and dcngettext be. + But only deal with dngettext and + dcngettext if they will not be dealt + with later because of ngettext */ +#define dgettext(a,b) not_here("dgettext") +#define dcgettext(a,b,c) not_here("dcgettext") +#ifdef HAVE_NGETTEXT +#define dngettext(a,b,c,d) not_here("dngettext") +#define dcngettext(a,b,c,d,e) not_here("dcngettext") +#endif +#undef ANY_MISSING +#define ANY_MISSING 1 +#endif + +#ifndef HAVE_NGETTEXT +#define ngettext(a,b,c) not_here("ngettext") +#define dngettext(a,b,c,d) not_here("dngettext") +#define dncgettext(a,b,c,d,e) not_here("dcngettext") +#undef ANY_MISSING +#define ANY_MISSING 1 +#endif + +#ifndef HAVE_BIND_TEXTDOMAIN_CODESET +#define bind_textdomain_codeset(a,b) not_here("bind_textdomain_codeset") +#undef ANY_MISSING +#define ANY_MISSING 1 +#endif + +#if ANY_MISSING +static int +not_here(char *s) +{ + croak("Locale::gettext::%s not implemented on this architecture", s); + return -1; +} +#endif + +MODULE = Locale::gettext PACKAGE = Locale::gettext + +double +constant(name,arg) + char * name + int arg + +char * +gettext(msgid) + char * msgid + +char * +dcgettext(domainname, msgid, category) + char * domainname + char * msgid + int category + +char * +dgettext(domainname, msgid) + char * domainname + char * msgid + +char * +ngettext(msgid, msgid_plural, n) + char * msgid + char * msgid_plural + unsigned long n + +char * +dcngettext(domainname, msgid, msgid_plural, n, category) + char * domainname + char * msgid + char * msgid_plural + unsigned long n + int category + +char * +dngettext(domainname, msgid, msgid_plural, n) + char * domainname + char * msgid + char * msgid_plural + unsigned long n + +char * +textdomain(domain) + char * domain + +char * +bindtextdomain(domain, dirname = NULL) + char * domain + char * dirname + +char * +bind_textdomain_codeset(domain, codeset = NULL) + char * domain + char * codeset diff --git a/t/bind.t b/t/bind.t new file mode 100644 index 0000000..c8839ae --- /dev/null +++ b/t/bind.t @@ -0,0 +1,16 @@ +#!/usr/bin/env perl -w +use strict; +use Test; +BEGIN { plan tests => 1 } + +use Locale::gettext; +bindtextdomain("foo", "dirname"); +if ((bindtextdomain("foo") eq 'dirname') && + (bindtextdomain("foo") eq 'dirname')) { + ok(1); +} else { +print "[", bindtextdomain("foo"), "]\n"; + ok(0); +} +exit; +__END__ diff --git a/t/frconvert.t b/t/frconvert.t new file mode 100644 index 0000000..d33dc11 --- /dev/null +++ b/t/frconvert.t @@ -0,0 +1,29 @@ +#!/usr/bin/env perl -w +use strict; +use Test; +BEGIN { plan tests => 1 } +require "test_data/gen_test_data.pl"; + +gen("foo"); +use Locale::gettext; +my $d; +eval { + $d = Locale::gettext->domain("foo"); +}; +if ($@ =~ /Encode module not available/) { + skip("Locale::gettext->domain not available, skipping", 0) +} elsif ($@ ne '') { + die $@; +} else { + $d->dir("test_data"); + if ($d->get("No problem") eq "Pas de probl\x{e8}me") { + ok(1); + } else { +use Data::Dumper; +print Dumper($d); +print "[", $d->get("No problem"), "]\n"; + ok(0); + } +} +exit; +__END__ diff --git a/t/jaconvert.t b/t/jaconvert.t new file mode 100644 index 0000000..5794dc4 --- /dev/null +++ b/t/jaconvert.t @@ -0,0 +1,27 @@ +#!/usr/bin/env perl -w +use strict; +use Test; +BEGIN { plan tests => 1 } +require "test_data/gen_test_data.pl"; + +gen("jaeuc"); +use Locale::gettext; +my $d; +eval { + $d = Locale::gettext->domain("jaeuc"); +}; +if ($@ =~ /Encode module not available/) { + skip("Locale::gettext->domain not available, skipping", 0) +} elsif ($@ ne '') { + die $@; +} else { + $d->dir("test_data"); + if ($d->get("test") eq "\x{30c6}\x{30b9}\x{30c8}") { + ok(1); + } else { + print $d->get("test"), "\n"; + ok(0); + } +} +exit; +__END__ @@ -0,0 +1,18 @@ +#!/usr/bin/env perl -w +use strict; +use Test; +BEGIN { plan tests => 1 } +require "test_data/gen_test_data.pl"; + +gen("foo"); +use Locale::gettext; +my $d = Locale::gettext->domain_raw("foo"); +$d->dir("test_data"); +if ($d->get("No worries") eq "Sans craintes") { + ok(1); +} else { + ok(0); +} +undef $d; +exit; +__END__ @@ -0,0 +1,8 @@ +#!/usr/bin/env perl -w +use strict; +use Test; +BEGIN { plan tests => 1 } + +use Locale::gettext; ok(1); +exit; +__END__ diff --git a/test_data/foo.po b/test_data/foo.po new file mode 100644 index 0000000..4b89389 --- /dev/null +++ b/test_data/foo.po @@ -0,0 +1,8 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=iso-8859-15" + +msgid "No worries" +msgstr "Sans craintes" + +msgid "No problem" +msgstr "Pas de problème" diff --git a/test_data/gen_test_data.pl b/test_data/gen_test_data.pl new file mode 100644 index 0000000..8763f31 --- /dev/null +++ b/test_data/gen_test_data.pl @@ -0,0 +1,50 @@ +use strict; + +sub gen { + my ($domain) = @_; + + my $messages; + unless (open(LOCALE, "locale|")) { + doskip(); + } + while (<LOCALE>) { + if (/^LC_MESSAGES=\"(.*)\"$/) { + $messages = $1; + last; + } elsif (/^LC_MESSAGES=(.*)$/) { + $messages = $1; + } + } + close LOCALE; + if ($? != 0) { + doskip(); + } + + if ($messages eq 'C') { + skip("cannot run test in the C locale", 0); + exit 0; + } + if ($messages eq 'POSIX') { + skip("cannot run test in the POSIX locale", 0); + exit 0; + } + + mkdir "test_data/" . $messages, 0755 unless (-d "test_data/" . $messages); + mkdir "test_data/" . $messages . "/LC_MESSAGES", 0755 + unless (-d "test_data/" . $messages . "/LC_MESSAGES"); + unless (-r ("test_data/" . $messages . "/LC_MESSAGES/" . $domain . ".mo")) { + system "msgfmt", "-o", "test_data/" . $messages . "/LC_MESSAGES/" . + $domain . ".mo", + "test_data/" . $domain . ".po"; + if ($? != 0) { + doskip(); + } + } +} + +sub doskip { + skip("could not generate test data, skipping test", 0); + exit 0; +} + +1; diff --git a/test_data/jaeuc.po b/test_data/jaeuc.po new file mode 100644 index 0000000..b2efdad --- /dev/null +++ b/test_data/jaeuc.po @@ -0,0 +1,5 @@ +msgid "" +msgstr "Content-Type: text/plain; charset=euc-jp" + +msgid "test" +msgstr "¥Æ¥¹¥È" |