#!/bin/sh
# Print the team's address (to stdout) and output additional instructions
# (to stderr).
projectsdir="$1"
progdir="$2"
catalog="$3"  # e.g. "pt_BR"
language="$4" # e.g. "pt"

url=`cat "$projectsdir/GNOME/teams.url"`
html=`"$progdir/urlget" "$url" "$projectsdir/GNOME/teams.html"`
# The HTML page doesn't contain the languages with ISO 639 codes.
# So we have to translate ourselves...
case "$catalog" in
  af) english=Afrikaans;;
  ar) english=Arabic;;
  az) english="Azerbaijani turkish";;
  eu) english=Basque;;
  bs) english=Bosnian;;
  pt_BR) english="Brazilian Portug";; # someday they'll fix the mistake
  bg) english=Bulgarian;;
  en_GB) english="Commonwealth English";;
  hr) english=Croatian;;
  ca) english=Catalan;;
  zh_CN) english="Chinese (Team in China)";;
  zh_TW) english="Chinese (Team in Taiwan)";;
  cs) english=Czech;;
  da) english=Danish;;
  nl) english=Dutch;;
  et) english=Estonian;;
  fi) english=Finnish;;
  fr) english=French;;
  gl) english=Galician;;
  de) english=German;;
  el) english=Greek;;
  he) english=Hebrew;;
  hi) english=Hindi;;
  hu) english=Hungarian;;
  id) english=Indonesian;;
  ga) english=Irish;;
  it) english=Italian;;
  ja) english=Japanese;;
  ko) english=Korean;;
  lv) english=Latvian;;
  lt) english=Lithuanian;;
  ml) english=Malayalam;;
  mt) english=Maltese;;
  mr) english=Marathi;;
  no) english=Norwegian;;
  fa) english=Persian;;
  pl) english=Polish;;
  pt) english=Portuguese;;
  ro) english=Romanian;;
  ru) english=Russian;;
  sk) english=Slovak;;
  sl) english=Slovenian;;
  es) english=Spanish;;
  sv) english=Swedish;;
  ta) english=Tamil;;
  te) english=Telugu;;
  th) english=Thai;;
  tr) english=Turkish;;
  uk) english=Ukrainian;;
  vi) english=Vietnamese;;
  # ??) english=Walloon;;
  cy) english=Welsh;;
  *) english=;;
esac
if test -n "$english"; then
  (echo "Please consider joining your translation team, and visit"
   echo "  $url"
   echo "  http://developer.gnome.org/projects/gtp/"
  ) 1>&2
  sed_addnl='s,</tr>,</tr>\
,g'
  address=`echo "$html" | tr '\012' '|' | sed -e "$sed_addnl" | sed -n -e "s,^.*<td.*$english.*</td>.*<td.*</td>.*<td.*<a href=\"\\([^\"]*\\)\">.*</td>.*\$,\\1,p"`
  # address can be empty or contain 1 or more space separated URLs.
else
  (echo "A translation team for your "`if test "$catalog" = "$language"; then echo "language ($language)"; else echo "local dialect ($catalog)"; fi`
   echo "may not exist yet.  Please visit"
   echo "  $url"
   echo "  http://developer.gnome.org/projects/gtp/"
   echo "and decide whether you want to create a new translation team."
  ) 1>&2
  address=
fi
exit 0
