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
1 #!/usr/bin/perl -w 2 3 # Exercise Program for localization and internationalization 4 5 use strict; 6 use lib qw(/home/xpathun/perl.d/language.d/); 7 use locale; 8 use POSIX qw(locale_h); 9 use Locale::TextDomain; 10 11 my $current_locale; 12 13 my $lang_var = `env | grep -m 1 [a-z][a-z]_[A-Z][A-Z]`; # looking for a variable which contains a valid language value 14 15 chomp $lang_var; 16 my @lang_set = split('=' , $lang_var); # extracting the value 17 18 my $lang = $lang_set[1]; 19 chomp $lang; 20 21 $current_locale = setlocale(LC_ALL , $lang) || die "Had trouble with the language $lang\n"; 22 23 my $string =__"Hello"; 24 25 print "$string\n"; 26 27 my $number = 1.23; 28 print "$number\n";
QuoteIch hatte es natürlich geladen
1 2 3 4 5 6 7 8
use lib qw(/usr/share/perl5/Debconf); use strict; use locale; use POSIX qw(locale_h); use Locale::TextDomain; use Gettext; my $gt = new Gettext;
1 2 3 4 5 6 7
use strict; use locale; use POSIX qw(locale_h); use Locale::TextDomain; use Debconf::Gettext; my $gt = new Debconf::Gettext;
Quote...
(Fehlermeldung: Can't locate object method "new" via package "Gettext" (perhaps you forgot to load "Gettext"?))
...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#!@PERL@ # Example for use of GNU gettext. # This file is in the public domain. # # Source code of the Perl program, using the Locale::Messages API. use Locale::Messages qw (textdomain bindtextdomain gettext); use POSIX qw(getpid); binmode STDOUT, ':raw'; # Needed to make it work in UTF-8 locales in Perl-5.8. sub _ ($) { &gettext; } textdomain "hello-perl"; bindtextdomain "hello-perl", "@localedir@"; print _"Hello, world!"; print "\n"; printf _"This program is running as process number %d.", getpid(); print "\n";
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
#!/usr/bin/perl use strict; use warnings; # gettext laden. # Das ist Bei Debian gleich dabei und nutzt die C-Lib gettext use Locale::gettext; # POSIX laden um "setlocale" nutzen zu lönnen use POSIX; # das Verzeichnis finden in dem das Script liegt use FindBin '$Bin'; # keine Übersetzung vorläufig setlocale(LC_MESSAGES,'C') or die( "Can't set LC_MESSAGES" ); # die Domein an ein Verzeichnis # im Ordner des Scriptes binden bindtextdomain("my_test","$Bin/translate"); # in diesem Scrit diese Domain verwenden textdomain("my_test"); print gettext("Yo man")."\n"; for(0..9) { printf gettext('ln: %02u')."\n",$_; }
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
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-06-15 23:27+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: test.pl:13
msgid "Yo man"
msgstr ""
#: test.pl:16
#, perl-format
msgid "ln: %02u"
msgstr ""
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
# German translations for PACKAGE package.
# Copyright (C) 2012 THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# ToPeG <topeg@test.local>, 2012.
#
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2012-06-15 23:27+0200\n"
"PO-Revision-Date: 2012-06-15 23:31+0200\n"
"Last-Translator: ToPeG <topeg@test.local>\n"
"Language-Team: German\n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: test.pl:13
msgid "Yo man"
msgstr "Hallo"
#: test.pl:16
#, perl-format
msgid "ln: %02u"
msgstr "Zeile %02u"
1
2
3
4
5
6
7
8
9
10
11
Hallo
Zeile 00
Zeile 01
Zeile 02
Zeile 03
Zeile 04
Zeile 05
Zeile 06
Zeile 07
Zeile 08
Zeile 09
1
2
3
4
5
6
test.pl
translate/my_test.po
translate/de.po
translate/en.po
translate/de/LC_MESSAGES/my_test.mo
translate/en/LC_MESSAGES/my_test.mo