How to force formatted date (month) language ?

Y

Yohan N. Leder

Hi,

I would like to produce a formatted GMT date & time string which will
depend of a user choice in a web form (in a CGI framework) about human
language he prefers (e.g. a french native may prefer to choose
'english'). I wish that it works under both Unix and Windows.

Here is a test script on which I'm trying to go through POSIX::setlocale
() as described in 'perldoc perllocale' about LC_TIME :

#!/usr/bin/perl -w
use strict;
use POSIX qw(locale_h strftime);
print "Content-type: text/html\n\n";
my $datetime;

# english
setlocale(LC_TIME, "en_US.ISO8859-1");
$datetime = strftime "%d %b %Y @ %H:%M:%S GMT", gmtime;
print "<p>ENGLISH =>".$datetime."</p>";

# french
setlocale(LC_TIME, "fr_FR.ISO8859-1");
$datetime = strftime "%d %b %Y @ %H:%M:%S GMT", gmtime;
print "<p>FRENCH => ".$datetime."</p>";
exit 0;

But it doesn't seems to work because it just displays (in client
browser) the same french string in both cases (tested with ActivePerl
5.8.8 under Windows 2K FR) :

ENGLISH => 07 juil. 2006 @ 21:18:35 GMT
FRENCH => 07 juil. 2006 @ 21:18:35 GMT

When I would like to obtain something like :

ENGLISH => 07 Jul 2006 @ 21:18:35 GMT
FRENCH => 07 juil. 2006 @ 21:18:35 GMT

I've also tried with Perl 5.00503 under FreeBSD US, and, this time, it
gives english strings only (the only difference is the minus 'j' in
French string, but still with English word):

ENGLISH =>07 Jul 2006 @ 21:41:14 GMT
FRENCH => 07 jul 2006 @ 21:41:14 GMT

How to proceed to get this string in English or French (i.e. month here)
for sure (ie. depending of a language value extracted from STDIN about
web form POST in the real script) ?
 
S

Sisyphus

Yohan N. Leder said:
Hi,

I would like to produce a formatted GMT date & time string which will
depend of a user choice in a web form (in a CGI framework) about human
language he prefers (e.g. a french native may prefer to choose
'english'). I wish that it works under both Unix and Windows.

Here is a test script on which I'm trying to go through POSIX::setlocale
() as described in 'perldoc perllocale' about LC_TIME :

#!/usr/bin/perl -w
use strict;
use POSIX qw(locale_h strftime);
print "Content-type: text/html\n\n";
my $datetime;

# english
setlocale(LC_TIME, "en_US.ISO8859-1");

For Win32 (and perhaps others ?), try:
setlocale(LC_TIME, "English_USA.1252");
$datetime = strftime "%d %b %Y @ %H:%M:%S GMT", gmtime;
print "<p>ENGLISH =>".$datetime."</p>";

# french
setlocale(LC_TIME, "fr_FR.ISO8859-1");
$datetime = strftime "%d %b %Y @ %H:%M:%S GMT", gmtime;
print "<p>FRENCH => ".$datetime."</p>";
exit 0;

I'm on an "English" Win32 Machine - and, with the second strftime() call, I
still got 'Jul' instead of 'juil.' However, when I changed your second
setlocale() call to:
setlocale(LC_TIME, "French_France.1252");

I then got the desired 'juil.' in the output.

Cheers,
Rob
 
Y

Yohan N. Leder

sisyphus1 said:
For Win32 (and perhaps others ?), try:
setlocale(LC_TIME, "English_USA.1252");
[...]
I'm on an "English" Win32 Machine - and, with the second strftime() call, I
still got 'Jul' instead of 'juil.' However, when I changed your second
setlocale() call to:
setlocale(LC_TIME, "French_France.1252");

I then got the desired 'juil.' in the output.

Cheers,
Rob

Effectively, I've tried 'setlocale(LC_TIME, "English_USA.1252");' and
'setlocale(LC_TIME, "French_France.1252");' under Win 2K FR and it
respectively gives 'Jul' and "juil.' as expected. Does it means the
'en_US' and 'fr_FR' are not supported under Win32 ? Thanks ;)

Also, I've done the same test under a FreeBSD US and it still gives :
ENGLISH => 08 Jul 2006 @ 17:26:58 GMT
FRENCH => 08 Jul 2006 @ 17:26:58 GMT

What's the right LC_TIME specification for Unix flavors and, more
generally, no-Win32 operating systems ?
 
D

DJ Stunks

Yohan said:
sisyphus1 said:
For Win32 (and perhaps others ?), try:
setlocale(LC_TIME, "English_USA.1252");
[...]
I'm on an "English" Win32 Machine - and, with the second strftime() call, I
still got 'Jul' instead of 'juil.' However, when I changed your second
setlocale() call to:
setlocale(LC_TIME, "French_France.1252");

I then got the desired 'juil.' in the output.

Cheers,
Rob

Effectively, I've tried 'setlocale(LC_TIME, "English_USA.1252");' and
'setlocale(LC_TIME, "French_France.1252");' under Win 2K FR and it
respectively gives 'Jul' and "juil.' as expected. Does it means the
'en_US' and 'fr_FR' are not supported under Win32 ? Thanks ;)

To build up a locale string in Win32 follow the instructions on this
page:

http://msdn.microsoft.com/library/d...ib/html/_crt_language_and_country_strings.asp

The possible choices for lang are listed:

http://msdn.microsoft.com/library/d...ry/en-us/vclib/html/_crt_language_strings.asp

The optional Country/Region and Code Pages supported by Windows are:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_country_strings.asp
http://www.microsoft.com/globaldev/reference/wincp.mspx
Also, I've done the same test under a FreeBSD US and it still gives :
ENGLISH => 08 Jul 2006 @ 17:26:58 GMT
FRENCH => 08 Jul 2006 @ 17:26:58 GMT

What's the right LC_TIME specification for Unix flavors and, more
generally, no-Win32 operating systems ?

as perllocale states, you should be able to produce a list of supported
locales on a UNIX-ish OS by using
$ locale -a

in this case, I would say the easiest way to get the same script to
produce similar** results is to simply use 'english' and 'french' as
your locale strings.

HTH,
-jp

Note **: on redhat linux, 'french' produced "jui" rather than "juil.".
 
B

Bart Van der Donck

Yohan said:
Effectively, I've tried 'setlocale(LC_TIME, "English_USA.1252");' and
'setlocale(LC_TIME, "French_France.1252");' under Win 2K FR and it
respectively gives 'Jul' and "juil.' as expected. Does it means the
'en_US' and 'fr_FR' are not supported under Win32 ?

Both English and French locales should be available.
Also, I've done the same test under a FreeBSD US and it still gives :
ENGLISH => 08 Jul 2006 @ 17:26:58 GMT
FRENCH => 08 Jul 2006 @ 17:26:58 GMT

1252 is a Microsoft proprietary code page and thus not very useful for
general use across various OS's.

The code of your first post should be okay, but there is something
going on you're not aware of.

The "official" French month abbreviations are the following:
janvier : janv.
février : févr.
mars : mars
avril : avr.
mai : mai
juin : juin
juillet : juil. ou juill.
août : août
septembre : sept.
octobre : oct.
novembre : nov.
décembre : déc.
(http://fr.wikipedia.org/wiki/Mois)

It seems that MS' French_France.1252 follows these rules. But if we
want to force a three-char month notation (more English & informatics
style), then Houston has a problem:

French for June = Juin
French for July = Juillet
So, the three first chars are 'jui' for both months.

The logic would then be to take the first following character, like
Juin = jui
Juillet = jul
What's the right LC_TIME specification for Unix flavors and, more
generally, no-Win32 operating systems ?

General UNIX/Linux: setlocale('LC_TIME', 'fr_FR.ISO_8859-1');
Win32: setlocale('LC_TIME', 'fr');
Solaris: setlocale("LC_TIME", "fr");
FreeBSD: setlocale("LC_TIME", "fr_FR.ISO8859-1");
(out of http://www.oscommerce-fr.info/faq/qa_info.php?qID=52)

I also met:
French_France.1252
french.ISO_8859-1
french
fr_FR

A last super-safe option is to switch to the month number (like '7' in
stead of July). And then manually code out the part to tie it to the
actual month name/abbreviation you wish (according to the language the
user specified on the web page).
 
Y

Yohan N. Leder

in this case, I would say the easiest way to get the same script to
produce similar** results is to simply use 'english' and 'french' as
your locale strings.

It would be effectively a middle way, but, after thought I think I'll go
to the Bart suggestion : convert numeric month to abbreviated month name
by myself. Thanks anyway.
 
Y

Yohan N. Leder

A last super-safe option is to switch to the month number (like '7' in
stead of July). And then manually code out the part to tie it to the
actual month name/abbreviation you wish (according to the language the
user specified on the web page).

Hmm, understood your demonstration about jui/jul ambiguousness... I'll
take the super-sage way ;) So, just a question : do you know the
"official" English month abbreviations ? Not found on Wikipedia as for
French side.

Thanks, Bart
 
B

Bart Van der Donck

Yohan said:
[...]
Hmm, understood your demonstration about jui/jul ambiguousness... I'll
take the super-sage way ;) So, just a question : do you know the
"official" English month abbreviations ? Not found on Wikipedia as for
French side.

Me neither. But it's pretty safe to assume that those are 'jan feb mar
apr may jun jul aug sep oct nov dec'.

But, same as in French, it looks like these are no "hard" standards.
 
Y

Yohan N. Leder

Me neither. But it's pretty safe to assume that those are 'jan feb mar
apr may jun jul aug sep oct nov dec'.

Adopted ! Maybe with upper case at begin ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top