OpenStreetMap Forum

The Free Wiki World Map

You are not logged in.

#1 2019-04-08 12:48:02

ToniE
Member
From: Ottobrunn, Bayern, Germany
Registered: 2016-06-13
Posts: 156

[solved] Help: Perl and setlocale()

My script is written in Perl and I started translating messages into German. French, ... will follow soon.

I use

use POSIX;

use utf8;
binmode STDIN,  ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";

use locale;
use Locale::gettext;
use Locale::Util    qw ( set_locale );

and translate with "gettext()"

For 'German' (de_DE) I get the messages from ../locale/de/LC_MESSAGES/ptna.mo, so far so good.

I managed to make it work on my OpenSuse Linux (with tons of 'locale -a') and it now shows ü,Ü, ä, Ä, ... correctly.

However, on a Debian with less "locale -a" it finds the message catalog but spoils the ü, Ü, ...
Can't make it work.

Debian-$ locale -a
C
C.UTF-8
de_DE.utf8
en_US.utf8
POSIX
ru_RU.utf8

Here's the other part of the code

    $ENV{'LANG'} = 'de_DE';
    $ENV{'LANGUAGE'} = $ENV{'LANG'};
    setlocale( LC_ALL, '' );
    bindtextdomain( 'ptna', $PATH );
    textdomain( "ptna" );

I also tried "de_DE.UTF-8" and 'de_DE.utf8' and setlocale(LC_ALL,'de','DE') also set_locale(), ... but it still spoils the ü, Ü, ...

Access to Debian is via "ssh" though - does this make *the* difference.

I'm lost now - any help?

Toni

Last edited by ToniE (2019-04-10 11:09:57)


Alle Edits meiner Kommentare sind (nur) Typofixes, wenn nicht explizit anders angegeben.

Online

#2 2019-04-10 10:56:07

ToniE
Member
From: Ottobrunn, Bayern, Germany
Registered: 2016-06-13
Posts: 156

Re: [solved] Help: Perl and setlocale()

ToniE wrote:

My script is written in Perl and I started translating messages into German. French, ... will follow soon.

I use

use POSIX;

use utf8;
binmode STDIN,  ":utf8";
binmode STDOUT, ":utf8";
binmode STDERR, ":utf8";

use locale;
use Locale::gettext;
use Locale::Util    qw ( set_locale );

and translate with "gettext()"

For 'German' (de_DE) I get the messages from ../locale/de/LC_MESSAGES/ptna.mo, so far so good.

I managed to make it work on my OpenSuse Linux (with tons of 'locale -a') and it now shows ü,Ü, ä, Ä, ... correctly.

However, on a Debian with less "locale -a" it finds the message catalog but spoils the ü, Ü, ...
Can't make it work.

Debian-$ locale -a
C
C.UTF-8
de_DE.utf8
en_US.utf8
POSIX
ru_RU.utf8

Here's the other part of the code

    $ENV{'LANG'} = 'de_DE';
    $ENV{'LANGUAGE'} = $ENV{'LANG'};
    setlocale( LC_ALL, '' );
    bindtextdomain( 'ptna', $PATH );
    textdomain( "ptna" );

I also tried "de_DE.UTF-8" and 'de_DE.utf8' and setlocale(LC_ALL,'de','DE') also set_locale(), ... but it still spoils the ü, Ü, ...

Access to Debian is via "ssh" though - does this make *the* difference.

I'm lost now - any help?

Toni

Seems that the following is sufficient to find the message catalog ...

    $ENV{'LANGUAGE'} = 'de';
    setlocale( LC_MESSAGES, '' );
    bindtextdomain( 'ptna', $PATH );
    textdomain( "ptna" );

Seems that the following does the magic by decoding the text from the message catalog (UTF-8) into Perl's internal character representation

    printf decode( 'utf8', gettext( "..." ) );

... at least it works now as expected.


Alle Edits meiner Kommentare sind (nur) Typofixes, wenn nicht explizit anders angegeben.

Online

Board footer

Powered by FluxBB