Ask a Question related to PERL Miscellaneous, Design and Development.
-
Joseph Brenner #1
locale games - looking for portable ways to get a list of valid locales
I think the question I want to ask here is: "Is there any
portable way of getting a listing of valid locales on the
current system?" I've been reading perllocale, and it looks
like the best they can do is point you at a dozen things
that might work on a given machine, but aren't guaranteed.
The reason I'm wondering with this has to do with the fact that a
CPAN tester is reporting a failure for a module I've been working
on ("Text::Capitalize"):
[url]http://nntp.x.perl.org/group/perl.cpan.testers/101269[/url]
The trouble is pretty clearly that the module does a "use
locale" so that it can handle accented characters correctly,
and my tests include some cases to cover this. For example,
the capitalize_title function transforms "über maus" to
"Über Maus", at least under the "en_US" LANG setting on my
box. My presumption is that it's failing on this sun
machine because it has a different locale setting (possibly
"C" or "Posix"... I would think "de" would work). It's
reporting things like this:
t/002-captitle-default............................# Failed test (t/002-captitle-default.t at line 22)
# got: 'üBer Maus'
# expected: 'Über Maus'
This failure is not a big deal from my point of view (if the user
wants the code to work with the full iso-8859 character set,
they'll presumably choose an appropriate locale, if they don't
have one by default). But still, I'd prefer to clean up the
warning, and I think there are two obvious ways the test could be
re-written: (1) check the locale setting and skip the test if it
doesn't look like it's appropriate or (2) set the locale
correctly for the test, and then revert to the original setting
afterwards.
Both approaches have their problems. The second sounds better to me,
but what if there is no "en_US" setting on the machine? It might not
be installed, or it might be called something else. I gather that
these are all possiblities: "En_US", "en_US.ISO8859-1",
"en_US.iso88591", "en_US", "en" and so on (?)... (I love standards).
So I would *think* that what I need is some way of getting a list of
valid locales, and I don't see any way of doing that out on CPAN.
But if that doesn't exist, I would guess I can try something like:
require 5.004;
use POSIX qw(locale_h);
BEGIN {
@american = qw( en_US.ISO8859-1 en_US.iso88591 en_US en En_US en_us );
foreach $en (@american) {
eval{ setlocale(LC_CTYPE, $en) };
unless ($@) { # $!?
$true_american = $en;
last;
}
}
}
Though that, of course, would limit it to POSIX compliant systems...
It also limits it to american english, but I don't mind that too
much, since at the moment at least "Text::Capitalize" is a fairly
parochial English-centric module.
So what do you folks think? Is there a better way of doing
it that I'm missing?
Joseph Brenner Guest
-
Ways to get the List of Countries and Cities
Hi There! I'm trying to create a User Registration page in ASP.NET and wondering what is the best way to get the list of up-to-date Countries and... -
to_s and locales in Gtk
Hi, Using the Gtk test-runner some very strange errors happened during running the xmlrpc4r tests. Indeed, xmlrpc4r and Gtk does not work... -
XPOST - Gamepub - Games portal - Games Wanted
here's one for you...a little late I know http://www.apneaevent.com/nrage ptol -
Any portable ways to get a list of valid locales?
I think the question I want to ask here is: "Is there any portable way of getting a listing of valid locales on the current system?" I've been... -
Valid list of HTTPResponse.ContentType string types
Hi All, I am look for a valid list of string args that can be used with HTTPResponse.ContentType. Thanks for any help!! Bob Hanson CEO... -
Ilja Tabachnik #2
Re: locale games - looking for portable ways to get a list of valid locales
Joseph Brenner wrote:
........>
> So I would *think* that what I need is some way of getting a list of
> valid locales, and I don't see any way of doing that out on CPAN.
IMHO, the portable way (for Unix-like systems) is just to use
the locale(1) command, say @all_locales = `locale -a`.
The locale(1) and it's '-a' switch is defined in SUSv2 (and 3 ?)
HTH
Ilja.
Ilja Tabachnik Guest



Reply With Quote

