locale games - looking for portable ways to get a list of valid locales

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. XPOST - Gamepub - Games portal - Games Wanted
      here's one for you...a little late I know http://www.apneaevent.com/nrage ptol
    4. 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...
    5. 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...
  3. #2

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139