From 67200727b7302529707cbeac0762cae28c931618 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 16 May 2016 00:42:28 +0000 Subject: load translations on demand git-svn-id: svn://tug.org/texlive/trunk@41176 c570f23f-e606-0410-a88d-b1316a301751 --- Master/tlpkg/TeXLive/trans.pl | 172 +++++++++++++++++++++--------------------- 1 file changed, 87 insertions(+), 85 deletions(-) (limited to 'Master/tlpkg/TeXLive/trans.pl') diff --git a/Master/tlpkg/TeXLive/trans.pl b/Master/tlpkg/TeXLive/trans.pl index 09991f53a52..951c4f83ca0 100644 --- a/Master/tlpkg/TeXLive/trans.pl +++ b/Master/tlpkg/TeXLive/trans.pl @@ -104,102 +104,104 @@ sub __ ($@) { return sprintf($ret, @_); } -if (($::lang ne "en") && ($::lang ne "C")) { - my $code = $::lang; - my @files_to_check; - if (defined($::area)) { - $code .= "_$::area"; - push @files_to_check, - $::lang . "_" . $::area, "$::lang-$::area", - $::lang . "_" . lc($::area), "$::lang-" . lc($::area), - # try also without area code, even if it is given! - $::lang; - } else { - push @files_to_check, $::lang; - } - my $found = 0; - for my $f (@files_to_check) { - if (-r "$::installerdir/tlpkg/translations/$f.po") { - $found = 1; - $::lang = $f; - last; +sub load_translations() { + if (($::lang ne "en") && ($::lang ne "C")) { + my $code = $::lang; + my @files_to_check; + if (defined($::area)) { + $code .= "_$::area"; + push @files_to_check, + $::lang . "_" . $::area, "$::lang-$::area", + $::lang . "_" . lc($::area), "$::lang-" . lc($::area), + # try also without area code, even if it is given! + $::lang; + } else { + push @files_to_check, $::lang; } - } - if (!$found) { - tlwarn ("\n Sorry, no translations available for $code (nor $::lang); falling back to English. - Make sure that you have the package \"texlive-msg-translations\" installed. - (If you'd like to help translate the installer's messages, please see - http://tug.org/texlive/doc.html#install-tl-xlate for information.)\n\n"); - } else { - # merge the translated strings into the text string - open(LANG, "<$::installerdir/tlpkg/translations/$::lang.po"); - my $msgid; - my $msgstr; - my $inmsgid; - my $inmsgstr; - while () { - chomp; - next if m/^\s*#/; - if (m/^\s*$/) { - if ($inmsgid) { - debug("msgid $msgid without msgstr in $::lang.po\n"); - $inmsgid = 0; - $inmsgstr = 0; - $msgid = ""; - $msgstr = ""; - next; - } - if ($inmsgstr) { - if ($msgstr) { - if (!utf8::decode($msgstr)) { - warn("decoding string to utf8 didn't work: $msgstr\n"); - } - # we decode msgid too to get \\ and not \ - if (!utf8::decode($msgid)) { - warn("decoding string to utf8 didn't work: $msgid\n"); + my $found = 0; + for my $f (@files_to_check) { + if (-r "$::installerdir/tlpkg/translations/$f.po") { + $found = 1; + $::lang = $f; + last; + } + } + if (!$found) { + tlwarn ("\n Sorry, no translations available for $code (nor $::lang); falling back to English. + Make sure that you have the package \"texlive-msg-translations\" installed. + (If you'd like to help translate the installer's messages, please see + http://tug.org/texlive/doc.html#install-tl-xlate for information.)\n\n"); + } else { + # merge the translated strings into the text string + open(LANG, "<$::installerdir/tlpkg/translations/$::lang.po"); + my $msgid; + my $msgstr; + my $inmsgid; + my $inmsgstr; + while () { + chomp; + next if m/^\s*#/; + if (m/^\s*$/) { + if ($inmsgid) { + debug("msgid $msgid without msgstr in $::lang.po\n"); + $inmsgid = 0; + $inmsgstr = 0; + $msgid = ""; + $msgstr = ""; + next; + } + if ($inmsgstr) { + if ($msgstr) { + if (!utf8::decode($msgstr)) { + warn("decoding string to utf8 didn't work: $msgstr\n"); + } + # we decode msgid too to get \\ and not \ + if (!utf8::decode($msgid)) { + warn("decoding string to utf8 didn't work: $msgid\n"); + } + $TRANS{$::lang}{$msgid} = $msgstr; + } else { + ddebug("untranslated $::lang: ...$msgid...\n"); } - $TRANS{$::lang}{$msgid} = $msgstr; - } else { - ddebug("untranslated $::lang: ...$msgid...\n"); + $inmsgid = 0; + $inmsgstr = 0; + $msgid = ""; + $msgstr = ""; + next; } - $inmsgid = 0; - $inmsgstr = 0; - $msgid = ""; - $msgstr = ""; next; } - next; - } - if (m/^msgid\s+"(.*)"\s*$/) { - if ($msgid) { - warn("stray msgid line: $_"); + if (m/^msgid\s+"(.*)"\s*$/) { + if ($msgid) { + warn("stray msgid line: $_"); + next; + } + $inmsgid = 1; + $msgid = $1; next; } - $inmsgid = 1; - $msgid = $1; - next; - } - if (m/^"(.*)"\s*$/) { - if ($inmsgid) { - $msgid .= $1; - } elsif ($inmsgstr) { - $msgstr .= $1; - } else { - tlwarn("cannot parse $::lang.po line: $_\n"); - } - next; - } - if (m/^msgstr\s+"(.*)"\s*$/) { - if (!$inmsgid) { - tlwarn("msgstr $1 without msgid\n"); + if (m/^"(.*)"\s*$/) { + if ($inmsgid) { + $msgid .= $1; + } elsif ($inmsgstr) { + $msgstr .= $1; + } else { + tlwarn("cannot parse $::lang.po line: $_\n"); + } next; } - $msgstr = $1; - $inmsgstr = 1; - $inmsgid = 0; + if (m/^msgstr\s+"(.*)"\s*$/) { + if (!$inmsgid) { + tlwarn("msgstr $1 without msgid\n"); + next; + } + $msgstr = $1; + $inmsgstr = 1; + $inmsgid = 0; + } } + close(LANG); } - close(LANG); } } -- cgit v1.2.3