rrdtool::graph and German weekday names

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

rrdtool::graph and German weekday names

Joachim Hartmann
Hello perl experts,
I run Munin on a Debian server. In the graphs the days of the week are
displayed in German. Now I monitor the weather data on a raspberry,
which basically works, but the days of the week are displayed in
English. How do I get this Perl script to display the weekdays in
English?

+++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl
#
# CGI script to create image using RRD graph


use CGI qw(:all);
use RRDs;
use strict;
use Encode;
use feature qw/switch/;


# size
my $width=703;
my $height=100;

# Grafic title
my $title='';
my $v_axis='';
my $legende='';
my $t_unit='';
my $rrd_file='wetter.rrd';
my $rrd_field='';

# read and check query params
my $query=new CGI;
my $graphvalue=$query->param('graphvalue');
my $startstamp=$query->param('startstamp');
my $stoppstamp=$query->param('stoppstamp');
my $graphwidth=$query->param('graphwidth');

$width=703;
$title='Luftdruck bezogen auf Meereshöhe';
$rrd_field='Luftdruck';
$v_axis='hPa';
$t_unit='hPa';
$legende='Luftdruck ';


# write image into temp file
my $tmpfile="/tmp/graphx_$$.png";
my @opts=("-v", $v_axis,
"-t", $title,
"-W", "Wetterstation Hannover-List",
"-w", $width,
"-l", "0",
"-s", "$startstamp",
"-e", "$stoppstamp",
"-c", "BACK#F0EFEF",
"-l", "870");

RRDs::graph($tmpfile,
       @opts,
       "DEF:temp0=$rrd_file:$rrd_field:AVERAGE",
       "LINE2:temp0#0000FF:$legende",
       "GPRINT:temp0:LAST:akt.\\:%5.1lf $t_unit",
       "GPRINT:temp0:MIN:min.\\:%5.1lf $t_unit",
       "GPRINT:temp0:MAX:max.\\:%5.1lf $t_unit",
       "GPRINT:temp0:AVERAGE:mittel\\:%5.1lf $t_unit\\n",
       "HRULE:1013.25#FF0000:mittler Luftdruck (1.1013,25 hPa):dashes"
);




# check error
my $err=RRDs::error;
die "$err\n" if $err;
# feed tmpfile to stdout
open(IMG, $tmpfile) or die "can't open $tmpfile\n";
print header('image/png');
print <IMG>;
close IMG;
unlink $tmpfile;
+++++++++++++++++++++++++++++++++++++++

The output of locale is the same for both computers:

+++++++++++++++++++++++++++++++++++++++
# locale
LANG=de_DE.UTF-8
LANGUAGE=
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
++++++++++++++++++++++++++++++++++++++
--
Greetings from the home of CeBIT
Gruß aus der Stadt der CeBIT
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

oetiker
Administrator
Hi Joachim,

Tobias Oetiker

On 1 Nov 2017, at 19:17, Joachim Hartmann <[hidden email]> wrote:

Hello perl experts,
I run Munin on a Debian server. In the graphs the days of the week are
displayed in German. Now I monitor the weather data on a raspberry,
which basically works, but the days of the week are displayed in
English. How do I get this Perl script to display the weekdays in
English?

Chances are that the locale when running as a cgi is different than the locale you got when logging into the server interactively.

I would suggest to use

use POSIX qw(locale_h);
use locale;
setlocale(LC_CTYPE, "de_DE.UTF-8");

INSIDE the script

More details on this to be found here https://perldoc.perl.org/perllocale.html

Cheers
Tobi
;
+++++++++++++++++++++++++++++++++++++++

The output of locale is the same for both computers:

+++++++++++++++++++++++++++++++++++++++
# locale
LANG=de_DE.UTF-8
LANGUAGE=
LC_CTYPE="de_DE.UTF-8"
LC_NUMERIC="de_DE.UTF-8"
LC_TIME="de_DE.UTF-8"
LC_COLLATE="de_DE.UTF-8"
LC_MONETARY="de_DE.UTF-8"
LC_MESSAGES="de_DE.UTF-8"
LC_PAPER="de_DE.UTF-8"
LC_NAME="de_DE.UTF-8"
LC_ADDRESS="de_DE.UTF-8"
LC_TELEPHONE="de_DE.UTF-8"
LC_MEASUREMENT="de_DE.UTF-8"
LC_IDENTIFICATION="de_DE.UTF-8"
LC_ALL=
++++++++++++++++++++++++++++++++++++++
--
Greetings from the home of CeBIT
Gruß aus der Stadt der CeBIT
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

Joachim Hartmann
Hi Tobi,
Am 01.11.2017 um 20:19 schrieb Tobias Oetiker:
> Hi Joachim,
>
> Tobias Oetiker
>

> I would suggest to use
>
> use POSIXqw(locale_h);
> use locale;
> setlocale(LC_CTYPE,"de_DE.UTF-8");
>
> INSIDE the script
>
> More details on this to be found here
> https://perldoc.perl.org/perllocale.html
>
> Cheers
> Tobi

the proposed solution shows no change. I then looked at the recommended
web page and ran the following script on the command line:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl
use POSIX qw(strftime);

for (1..7) {
     $wochentag[$_] = strftime("%a", 0, 0, 0, $_, 3, 96);
     printf "$wochentag[$_]\n";
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++

Here is the result:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
#~#. /test_locale. pl
Mo
Di
Wed
Thu
Fr
Sa
So
++++++++++++++++++++++++++++++++++++++++++++++++++++++

I think now rather that the solution can be found in rrdtool (1.6.0).
--
Cheers
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

oetiker
Administrator
Make sure you run the test as a cgi !

cheers
tobi


----- On Nov 2, 2017, at 11:02 AM, Joachim Hartmann [hidden email] wrote:

> Hi Tobi,
> Am 01.11.2017 um 20:19 schrieb Tobias Oetiker:
>> Hi Joachim,
>>
>> Tobias Oetiker
>>
>
>> I would suggest to use
>>
>> use POSIXqw(locale_h);
>> use locale;
>> setlocale(LC_CTYPE,"de_DE.UTF-8");
>>
>> INSIDE the script
>>
>> More details on this to be found here
>> https://perldoc.perl.org/perllocale.html
>>
>> Cheers
>> Tobi
>
> the proposed solution shows no change. I then looked at the recommended
> web page and ran the following script on the command line:
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> #!/usr/bin/perl
> use POSIX qw(strftime);
>
> for (1..7) {
>     $wochentag[$_] = strftime("%a", 0, 0, 0, $_, 3, 96);
>     printf "$wochentag[$_]\n";
> }
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Here is the result:
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> #~#. /test_locale. pl
> Mo
> Di
> Wed
> Thu
> Fr
> Sa
> So
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> I think now rather that the solution can be found in rrdtool (1.6.0).
> --
> Cheers
> Jochen

--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
www.oetiker.ch [hidden email] +41 62 775 9902

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

Heinrich Schnorrenberg
In reply to this post by Joachim Hartmann
Hi Jochen


I just checked it on my raspi . here it works.  the script is :
++++++++++++++++++++++++++++++++++++++++++++++++++++++
 #!/usr/bin/perl -w
#
use warnings;
use POSIX qw(locale_h);
use locale;
use POSIX qw(strftime);


#
for (1..7) {
   $wochentag[$_] = strftime("%a", 0, 0, 0, $_, 3, 96);
   printf "$wochentag[$_]\n";
}

++++++++++++++++++++++++++++++++++++++++++++++++++++++
the output is:

pi@raspberrypi:~/public_html/cgi-bin $ perl loc.pl
Mo
Di
Mi
Do
Fr
Sa
So

hope that helps

regards Heinrich



On 2. Nov 2017, at 11:02, Joachim Hartmann <[hidden email]> wrote:

Hi Tobi,
Am 01.11.2017 um 20:19 schrieb Tobias Oetiker:
Hi Joachim,
Tobias Oetiker

I would suggest to use
use POSIXqw(locale_h);
use locale;
setlocale(LC_CTYPE,"de_DE.UTF-8");
INSIDE the script
More details on this to be found here https://perldoc.perl.org/perllocale.html
Cheers
Tobi

the proposed solution shows no change. I then looked at the recommended web page and ran the following script on the command line:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
#!/usr/bin/perl
use POSIX qw(strftime);

for (1..7) {
   $wochentag[$_] = strftime("%a", 0, 0, 0, $_, 3, 96);
   printf "$wochentag[$_]\n";
}
++++++++++++++++++++++++++++++++++++++++++++++++++++++

Here is the result:

++++++++++++++++++++++++++++++++++++++++++++++++++++++
#~#. /test_locale. pl
Mo
Di
Wed
Thu
Fr
Sa
So
++++++++++++++++++++++++++++++++++++++++++++++++++++++

I think now rather that the solution can be found in rrdtool (1.6.0).
--
Cheers
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users


_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

Joachim Hartmann
Hello Tobi, hello Heinrich,
Am 02.11.2017 um 23:38 schrieb Heinrich Schnorrenberg:
> Hi Jochen
>
>
> I just checked it on my raspi . here it works.  the script is :
>
> hope that helps
>
> regards Heinrich
>
I'm sorry, I didn't get back to you until now! I was out of town for two
days. I'm a bloody layman about pearls:
How do I run the script as cgi?
This script shows the correct result on my command line!

+++++++++++++++++++++++++++++++++++++++++++++++++++++
#! /usr/bin/perl -w
#
use warnings;
use POSIX qw (locale_h);
use locale;
use POSIX qw (strftime);


#
for (1... 7) {
    $weekday[$_] = strftime ("%a", 0,0,0,0, $_, 3,96);
    printf "$weekday[$_]\n";
}
++++++++++++++++++++++++++++++++++++++++++++++++++++
#~# perl test_locale.pl
Mo
Di
Mi
Do
Fr
Sa
So
#~#
++++++++++++++++++++++++++++++++++++++++++++++++++++

Only the question is, is that what Tobi meant!

--
Gruß aus der Stadt der CeBIT
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

oetiker
Administrator
Hi Joachim

----- On Nov 4, 2017, at 12:13 PM, Joachim Hartmann [hidden email] wrote:

> Hello Tobi, hello Heinrich,
> Am 02.11.2017 um 23:38 schrieb Heinrich Schnorrenberg:
>> Hi Jochen
>>
>>
>> I just checked it on my raspi . here it works.  the script is :
>>
>> hope that helps
>>
>> regards Heinrich
>>
> I'm sorry, I didn't get back to you until now! I was out of town for two
> days. I'm a bloody layman about pearls:
> How do I run the script as cgi?
> This script shows the correct result on my command line!
>
> +++++++++++++++++++++++++++++++++++++++++++++++++++++
> #! /usr/bin/perl -w
> #
> use warnings;
> use POSIX qw (locale_h);
> use locale;
> use POSIX qw (strftime);
>
>
> #
> for (1... 7) {
>    $weekday[$_] = strftime ("%a", 0,0,0,0, $_, 3,96);
>    printf "$weekday[$_]\n";
> }
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> #~# perl test_locale.pl
> Mo
> Di
> Mi
> Do
> Fr
> Sa
> So
> #~#
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Only the question is, is that what Tobi meant!

what I meant is that the locale settings could be different when running this under the webservers control as a cgi

so you have to make sure the locale settings are set for cgis as well.

cheers
tobi

>
> --
> Gruß aus der Stadt der CeBIT
> Jochen

--
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
www.oetiker.ch [hidden email] +41 62 775 9902

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
Reply | Threaded
Open this post in threaded view
|

Re: rrdtool::graph and German weekday names

Joachim Hartmann

Hi Tobi,
Am 05.11.2017 um 11:56 schrieb Tobias Oetiker:

> Hi Joachim
>
> ----- On Nov 4, 2017, at 12:13 PM, Joachim Hartmann [hidden email] wrote:
>
>> Only the question is, is that what Tobi meant!
>
> what I meant is that the locale settings could be different when running this under the webservers control as a cgi
>
> so you have to make sure the locale settings are set for cgis as well.
>
> cheers
> tobi
>

>

it took me a while, but now I have checked this perl script in my browser.

++++++++++++++++++++++++++++
#! /usr/bin/perl -w
#
use POSIX qw (strftime);
use POSIX' strftime';
use POSIX qw (locale_h);
use strict;
use CGI;
use warnings;
use locale;

print CGI:: header ();
print "setlocale (LC_ALL, 0):". setlocale (LC_ALL, 0) "<br>\n";
print "setlocale (LC_ALL, \"\"):". setlocale (LC_ALL,""). "<br>\n";
my @weekday;
#
for (1... 7) {
    $weekday[$_] = strftime ("%a", 0,0,0,0, $_, 3,96);
    print "$weekday[$_]<br>";
}
++++++++++++++++++++++

Apache2 is installed on the server and lighthptd on the raspberries. The
output is the same for both of them, in English!

++++++++++++++++++++++
setlocale (LC_ALL, 0):
setlocale (LC_ALL,""): C
Mon
do
Wed
thu
Fri
Sat
Sun
++++++++++++++++++++++++++

--
Gruß aus der Stadt der CeBIT
Jochen

_______________________________________________
rrd-users mailing list
[hidden email]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users