<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#
#  Lang.pm
#
#  $Id: Lang.pm,v 1.15 1998/05/16 10:28:59 cg Exp $
#
#  Language support.
#
#  © Copyright 1997, Cees de Groot
#

package SGMLTools::Lang;

use strict;
use vars qw($VERSION @ISA @EXPORT @Languages $translations);

require 5.0004;
use Exporter;
use SGMLTools::Vars;

$VERSION = sprintf("%d.%02d", q$Revision: 1.15 $ =~ /(\d+)\.(\d+)/);
@ISA     = qw(Exporter);
@EXPORT  = qw(Any2ISO ISO2Native ISO2English Xlat);

=head1 NAME

SGMLTools::Lang - language name and translation functions

=head1 SYNOPSIS

  $isoname = Any2ISO ('deutsch');
  $native  = ISO2Native ('de');
  $engname = ISO2English ('nederlands');
  
  $global-&gt;{language} = 'nl';
  $dutch = Xlat ('Table of Contents');

=head1 DESCRIPTION

B&lt;SGMLTools::Lang&gt; gives a simple interface to various forms of language
names, and provides a translation service. Languages can be specified in
three different ways: by their native name, by their english name, and
by their 2-letter ISO code. For example, you can specify the German
language as C&lt;deutsch&gt;, as C&lt;german&gt; or as C&lt;de&gt;.

=head1 FUNCTIONS

=over 4

=cut

@Languages = qw(
  en english english
  de deutsch german
  nl nederlands dutch
  fr français french
  es español spanish
  da dansk danish
  no norsk norwegian
  se svenska swedish
  pt portuges portuguese
  ca català catalan
  it italiano italian
  ro românã romanian
);


=item Any2ISO

Maps any of the three forms of languages to the ISO name. So either of
these invocations:

  Any2ISO ('dutch');
  Any2ISO ('nederlands');
  Any2ISO ('nl');

will return the string C&lt;"nl"&gt;.

=cut

sub Any2ISO
{
  my $lang = shift (@_);
  
  my $i = 0;
  foreach my $l (@Languages)
    {
      ($l eq $lang) &amp;&amp; last;
      $i++;
    }
  return $Languages[(int $i / 3) * 3];
}


=item ISO2Native

Maps the ISO code to the native name of the language.

=cut

sub ISO2Native
{
  my $iso = shift (@_);

  my $i = 0;
  foreach my $l (@Languages)
    {
      ($l eq $iso) &amp;&amp; last;
      $i++;
    }
  return $Languages[$i + 1];

}


=item ISO2English

Maps the ISO code to the english name of the language.

=cut

sub ISO2English
{
  my $iso = shift (@_);

  my $i = 0;
  foreach my $l (@Languages)
    {
      ($l eq $iso) &amp;&amp; last;
      $i++;
    }
  return $Languages[$i + 2];
}

=item Xlat

Translates its (English) argument to the language specified by the
current value of C&lt;$gobal-E&lt;gt&gt;{language}&gt;. The module, in its source
file, contains a data structure, indexed by the English strings, that
has all available translations. 

=cut

sub Xlat
{
  my ($txt) = @_;

  return $txt if ($global-&gt;{language} eq "en");
  return $translations-&gt;{$txt}{$global-&gt;{language}};
};


#
#  By the time this grows big, we'll make up something else.
#
$translations = {
  "Previous" =&gt; {
     "nl" =&gt; "Terug",
     "de" =&gt; "Zurück",
     "es" =&gt; "Página anterior",
     "fr" =&gt; "Page précédente",
     "da" =&gt; "Forrige",
     "no" =&gt; "Forrige",
     "se" =&gt; "Föregående",
     "pt" =&gt; "Página anterior",
     "ca" =&gt; "Pàgina anterior",
     "it" =&gt; "Indietro",
     "ro" =&gt; "Înapoi"
  },
  "Next" =&gt; {
     "nl" =&gt; "Verder",
     "de" =&gt; "Weiter",
     "es" =&gt; "Página siguiente",
     "fr" =&gt; "Page suivante",
     "da" =&gt; "Næste",
     "no" =&gt; "Neste",
     "se" =&gt; "Nästa",
     "pt" =&gt; "Página seguinte",
     "ca" =&gt; "Pàgina següent",
     "it" =&gt; "Avanti",
     "ro" =&gt; "Înainte"
  },
  "Contents" =&gt; {
     "nl" =&gt; "Inhoud",
     "de" =&gt; "Inhalt",
     "es" =&gt; "Índice general",
     "fr" =&gt; "Table des matières",
     "da" =&gt; "Indhold",
     "no" =&gt; "Innhold",
     "se" =&gt; "Innehållsförteckning",
     "pt" =&gt; "Índice",
     "ca" =&gt; "Índex",
     "it" =&gt; "Indice",
     "ro" =&gt; "Cuprins"
  },
  "Table of Contents" =&gt; {
     "nl" =&gt; "Inhoudsopgave",
     "de" =&gt; "Inhaltsverzeichnis",
     "es" =&gt; "Índice general",
     "fr" =&gt; "Table des matières",
     "da" =&gt; "Indholdsfortegnelse",
     "no" =&gt; "Innholdsfortegnelse",
     "se" =&gt; "Innehållsförteckning",
     "pt" =&gt; "Índice geral",
     "ca" =&gt; "Índex general",
     "it" =&gt; "Indice Generale",
     "ro" =&gt; "Cuprins"
  }
};

=back

=head1 AUTHOR

Cees de Groot, C&lt;E&lt;lt&gt;cg@pobox.comE&lt;gt&gt;&gt;

=cut

1;
</pre></body></html>