;;; This file contain stuff to use gettext in wml
;;; Licence GPL
;;; Author: Martin Quinson

;;; including this file should be enough from the source side, because <p>...</p>
;;; and other tags like that are defined to use gettext. You can use
;;; gettext in

;;; The translation database (ie, the po file) should be placed in a po/
;;;  directory, relative to the current one. It should be compiled to:
;;;     po/<name of main file>.mo
;;;  where the main file is the one including all other (it is the path in
;;;    the menu tree)

;;; From the compilation side, you have to specify which language to use
;;; with this option:
;;;    -D LANG=<lang>



;;; Initialize the gettext mecanism

<if <not <get-var gettext-initialized /> />
<compound>
<set-var gettext-initialized=1 />
<perl>
use Locale::gettext;
use POSIX;

setlocale(LC_MESSAGES,"$(CUR_LANG)");
setlocale(LC_ALL,"$(CUR_LANG)");
setlocale(LANG,"$(CUR_LANG)");
bindtextdomain("$(WML_SRC_BASENAME)","$(WML_SRC_DIRNAME)/$(PODIR)");
textdomain("$(WML_SRC_BASENAME)");
</perl>
;;;CUR_LANG=$(CUR_LANG) ; path=$(path)

;;; Put the header to the pot file
[POT:# SOME DESCRIPTIVE TITLE.
\# Copyright (C) YEAR Free Software Foundation, Inc.
\# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
\#
\#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: <perl>{
 my $date = `date +'%Y-%m-%d %k:%M%z'`;
 chomp $date;
 <perl:print>$date</perl:print>
}</perl>\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"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

:POT]
</compound>
/>

;;;;;;;;;;;;;;;;;;;;;
;;; gettext and _ tag
;;;;;;;;;;;;;;;;;;;;;

<define-tag gettext endtag=required>
  <when %body>
  <perl>{
    my $str;<perl:assign $str>%body</perl:assign>;
    $str =~ s/\n/ /mg;
    $str =~ s/  */ /mg;
;;;my $str2=$str;
;;;$str2 =~ s/ /_/g;
;;;<perl:print>Translation of <pre>"$str2"</pre> is in $(WML_SRC_DIRNAME)<pre>"</perl:print>
    $str=gettext $str;
    $str= "" if $str eq " ";
;;;$str =~ s/ /_/g;
    <perl:print>$str</perl:print>
;;;<perl:print>"</pre></perl:print>
  }</perl>
  [POT:
\#: <__file__>:<__line__>
msgid <perl>{
    my $str;<perl:assign $str>%body</perl:assign>;
      $str=~ s/"/\\"/g;
      $str=~ s/\n/ /mg;
      $str=~ s/  */ /g;
      $str = "\"$str\"\n";
      <perl:print>$str</perl:print>
  }</perl>
;;; :[[s/^\(.*\)\$/"\1"/g]] {:[[s/"/\\\\"/g]] %body:} :}
msgstr ""

:POT]
 </when>
</define-tag>

<define-tag _ endtag=required whitespace=delete>
  <gettext>%body</gettext>
</define-tag>

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; redefinition of the p tag
<define-tag p endtag=required>
  <preserve gettext><set-var %attributes>
  <ifeq <get-var gettext/> "no"
    <compound>
      <protect pass=2><p</protect> %attributes<protect pass=2>></protect>
      %body
      <protect pass=2></p></protect>
    </compound>
    <compound>
      <protect pass=2><p</protect> %attributes<protect pass=2>></protect>
      <gettext>%body</gettext>
      <protect pass=2></p></protect>
    </compound>
   />
   <restore gettext>
</define-tag>

;;;<define-tag td endtag=required>
;;;  <protect pass=2><td></protect>
;;;  <gettext>%body</gettext>
;;;  <protect pass=2></td></protect>
;;;</define-tag>