ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* new version of tran for context keyword translation
@ 1998-07-31 15:11 W.H. Dekker
  0 siblings, 0 replies; only message in thread
From: W.H. Dekker @ 1998-07-31 15:11 UTC (permalink / raw)


Here is a new version. Please mind: language keys have changed:
e -> English
d -> Dutch
g -> German

#!/usr/bin/perl -w

=head1 NAME

tran - show translations for context commands and keywords

=head1 SYNOPSIS

	tran en|ne|ed|de|nd|dn command-name_or_keyword...

	tran en|ne|ed|de|nd|dn <file_containing_commnds_or_keywords

=head1 DESCRIPTION

B<tran>, given one or more context command names or keywords, or a
file (on standard input) containing those, B<tran> prints each of them
with its translation on standard output. The source language and the
target language are given with the first parameter,
which must be a key consisting of two letters, one for the source
language and for the target language. Currently the only allowed
letters are d, e and g for Dutch, English and German.

=head1 EXAMPLES

From Dutch to English:

        $ tran de taal starttekst hoogte
                            taal -> language
                      starttekst -> starttext
                          hoogte -> height

From English to German:

        $ tran eg language starttext height
                        language -> sprache
                       starttext -> starttext
                          height -> hoehe

Given a file test.tex, containing:

        \starttekst
        \omlijnd[hoogte=ruim]{Hello world!}
        \stoptekst

you can show the translation for every Dutch context command or
keyword in English with:

        $ tran de <test.tex
                          hoogte -> height
                         omlijnd -> framed
                            ruim -> broad
                      starttekst -> starttext
                       stoptekst -> stoptext

=head1 ENVIRONMENT

All terms and their translations are taken from the files
F<mult-con.tex> and F<mult-con.tex>. These are supposed to reside in
the directory $ENV{TETEXDIR}/temf/tex/context/base.  

=head1 AUTHOR

Wybo H. Dekker (wybo@servaly.hobby.nl)

=cut

use vars qw($d $e $g);

%lang=(d => 'dutch',
       e => 'english',
       g => 'german',
);

($myname=$0) =~ s|.*/||;
$xy=shift or die "Usage: $myname xy\nwith x=d|e|g and y=d|e|g and x ne y\n";
$xy=~/^de|dg|ed|gd|ge|eg$/ or die "translation must be from d|e|g to d|e|g\n";

($x,$y)=split(//,$xy);

$ENV{TETEXDIR} or $ENV{TETEXDIR}='.';
$dir="$ENV{TETEXDIR}/texmf/tex/context/base";	# where mult-co[nm].tex should be
$name='([a-zA-Z]+)';	# search pattern for translatable terms

openin("mult-com");
while (<IN>) {
  next unless /^\s*$name:\s+$name\s+$name/;
  ($d,$e)=($2,$3);
  ($g=<IN>) =~ tr /a-zA-Z//cd ;
  $xy{$$x}=$$y;
}
openin("mult-con");
while (<IN>) {
  next unless /^\s*$name:\s+$name\s+$name\s+$name/;
  ($d,$e,$g)=($2,$3,$4);
  $xy{$$x}=$$y;
}
close IN;

if (@ARGV) {
  for (@ARGV) {
    if ($xy{$_}) { $translation=$xy{$_}; write }
    else { print "$_ is not a valid command or keyword in $lang{$x}\n" }
  }
} else {
  while(<>) { for (split(/\W/)) { $w{$_}++ } }
  for (sort keys %w) {
    next unless ($translation=$xy{$_} ? $xy{$_} : "");
    write
  }
}

format =
@>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> -> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$_,$translation
.

sub openin {
  open(IN,"$dir/$_[0].tex") and return;
  die "Could not open $dir/$_[0].tex\n".
      "Please check your environment variable TETEXDIR\n".
      "it should point to the directory where texmf/ resides\n";
}

-- 
Kind regards,
Wybo
===================Servalys Analytical Chemistry Services=================
Wybo H. Dekker        | Deilsedijk 60                 | tel (31)345-652164
wybo@servaly.hobby.nl | 4158 CH Deil, The Netherlands | fax (31)345-652383


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-07-31 15:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-07-31 15:11 new version of tran for context keyword translation W.H. Dekker

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).