--- /dev/null
+Preliminary notes. (Note that all of this has already been done for you
+in the archive, this is mainly so you can see what to do in your own
+projects.)
+
+Create the individiual .pot template files by using:
+
+ baby:~/ttk-gettext--mainline--1.0> perl make-pot.pl test.tmpl | msguniq > tpl-test.pot
+ (repeat for multiple templates)
+ xgettext --keyword=_ --from-code=utf-8 -o messages.pot -L perl *.pl
+
+Merge them all together using msgcat:
+
+ msgcat *.pot > templates.pot
+
+Now you can actually start translating. Do a msginit as usual:
+
+ LANG=nb_NO.UTF-8 msginit --input templates.pot
+
+And then translate using the editor of your choice. kbabel is a popular choice,
+but you can use your favourite editor by using potool:
+
+ poedit nb.po
+
+And then compile it using msgfmt as usual:
+
+ mkdir -p nb/LC_MESSAGES
+ msgfmt -o nb/LC_MESSAGES/myproject.mo nb.po
+
+Now you can compare the output in different locales:
+
+ LANG=C perl process-template.pl
+ LANG=nb_NO.UTF-8 perl process-template.pl
+
+Everything in here is © 2005 Steinar H. Gunderson <sgunderson@bigfoot.com>,
+licensed under the GPLv2. Absolutely no warranty. Comments welcome :-)
--- /dev/null
+
+package Sesse::ExtractGettext;
+use strict;
+use warnings;
+use Template::Directive;
+
+our @ISA = qw(Template::Directive);
+
+sub textblock {
+ my ($self, $text) = @_;
+
+ while ($text =~ s/<(h[1-6]|p|td|th|title|input|span|li|option|_)[^>]*>(.*?)<\/\1>//s) {
+ my $id = $2;
+ next if $id =~ /^\s*$/;
+ $id =~ s/\n/\\n"\n"/g;
+ $id =~ s/(.)"(?!\n)/$1\\"/g;
+
+ print "msgid \"$id\"\n";
+ print "msgstr \"\"\n";
+ print "\n";
+ }
+
+ return $self->SUPER::textblock($text);
+}
+
+
+
--- /dev/null
+
+package Sesse::GettextizeTemplates;
+use strict;
+use warnings;
+use Locale::gettext;
+use Template::Directive;
+
+our @ISA = qw(Template::Directive);
+
+# blah!
+sub mygettext {
+ my $text = shift;
+
+ return "" if ($text eq "");
+ return Locale::gettext::gettext($text);
+}
+
+sub textblock {
+ my ($self, $text) = @_;
+
+ $text =~ s/(<(h[1-6]|p|td|th|title|input|span|li|option|_)[^>]*>)(.*?)(<\/\2>)/$1.mygettext($3).$4/seg;
+ $text =~ s/<\/?_>//g;
+
+ return $self->SUPER::textblock($text);
+}
+
+
+
--- /dev/null
+#! /usr/bin/perl
+use Template;
+require 'Sesse::ExtractGettext.pm';
+
+my $template = Template->new({ FACTORY => 'Sesse::ExtractGettext' });
+my $date = `date +"%Y-%M-%d %H:%M%z"`; # pah :-)
+chomp $date;
+
+print <<"EOF";
+# template file for $ARGV[0]
+msgid ""
+msgstr ""
+"Project-Id-Version: myproject\\n"
+"Report-Msgid-Bugs-To: \\n"
+"POT-Creation-Date: $date\\n"
+"MIME-Version: 1.0\\n"
+"Content-Type: text/plain; charset=utf-8\\n"
+"Content-Transfer-Encoding: 8bit\\n"
+
+EOF
+
+my $eaten = '';
+$template->process($ARGV[0], { page => 'templates/index.tmpl' }, \$eaten)
+ or die $template->error(); # errors don't really matter, but OK
+
+print "# eof\n";
--- /dev/null
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-07-24 21:11+0200\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"
+
+#: process-template.pl:20
+msgid "Test message from outside a template.\n"
+msgstr ""
--- /dev/null
+# #-#-#-#-# messages.pot (ttk-gettext--mainline- VERSION) #-#-#-#-#
+# Norwegian Bokmal translations for ttk-gettext--mainline- package.
+# Copyright (C) 2005 THE ttk-gettext--mainline-'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the ttk-gettext--mainline- package.
+# Steinar H. Gunderson <sgunderson@bigfoot.com>, 2005.
+#
+# #-#-#-#-# tpl-test.pot (myproject) #-#-#-#-#
+# template file for test.tmpl
+msgid ""
+msgstr ""
+"#-#-#-#-# messages.pot (PACKAGE VERSION) #-#-#-#-#\n"
+"Project-Id-Version: ttk-gettext--mainline- 1.0\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-07-24 21:11+0200\n"
+"PO-Revision-Date: 2005-07-24 21:12+0200\n"
+"Last-Translator: Steinar H. Gunderson <sgunderson@bigfoot.com>\n"
+"Language-Team: Norwegian Bokmal <i18n-nb@lister.ping.uio.no>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"#-#-#-#-# tpl-test.pot (myproject) #-#-#-#-#\n"
+"Project-Id-Version: myproject\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-11-24 21:11+0200\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+
+#: process-template.pl:20
+msgid "Test message from outside a template.\n"
+msgstr "Testbeskjed fra utenfor en template.\n"
+
+msgid "A little template test"
+msgstr "En liten template-test."
+
+msgid "This is a test."
+msgstr "Dette er en test."
+
+msgid ""
+"This is a different test pattern. You may notice that\n"
+" since the block doesn't close the last tag, we had to\n"
+" use a special pseudo-tag to show the gettext magic that\n"
+" we want to translate it. In most cases this isn't required,\n"
+" though."
+msgstr ""
+"Pah, for lang, gidder ikke oversette :-P"
+
+msgid "Foo was enabled."
+msgstr "Foo er på."
+
+msgid "This is the end of the test."
+msgstr "Dette er slutten på testen."
--- /dev/null
+#! /usr/bin/perl
+use strict;
+use warnings;
+use POSIX;
+use Locale::gettext;
+use Template;
+require 'Sesse::GettextizeTemplates.pm';
+
+# Common short macro to get non-templatized gettext stuff working
+*_ = sub {
+ return Locale::gettext::gettext(@_);
+};
+
+# set the locale
+POSIX::setlocale(&POSIX::LC_CTYPE, "");
+POSIX::setlocale(&POSIX::LC_MESSAGES, "");
+Locale::gettext::bindtextdomain("myproject", ".");
+Locale::gettext::textdomain("myproject");
+
+# Do a test message with no templates
+print _("Test message from outside a template.\n");
+
+# Process the test template and print it to stdout
+my $template = Template->new({ FACTORY => 'Sesse::GettextizeTemplates' });
+my $output = '';
+$template->process('test.tmpl', { foo => int(rand 2) }, \$output)
+ or die $template->error();
+
+print $output;
--- /dev/null
+# #-#-#-#-# messages.pot (PACKAGE VERSION) #-#-#-#-#
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+#
+# #-#-#-#-# tpl-test.pot (myproject) #-#-#-#-#
+# template file for test.tmpl
+#, fuzzy
+msgid ""
+msgstr ""
+"#-#-#-#-# messages.pot (PACKAGE VERSION) #-#-#-#-#\n"
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-07-24 21:11+0200\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=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"#-#-#-#-# tpl-test.pot (myproject) #-#-#-#-#\n"
+"Project-Id-Version: myproject\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-11-24 21:11+0200\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: process-template.pl:20
+msgid "Test message from outside a template.\n"
+msgstr ""
+
+msgid "A little template test"
+msgstr ""
+
+msgid "This is a test."
+msgstr ""
+
+msgid ""
+"This is a different test pattern. You may notice that\n"
+" since the block doesn't close the last tag, we had to\n"
+" use a special pseudo-tag to show the gettext magic that\n"
+" we want to translate it. In most cases this isn't required,\n"
+" though."
+msgstr ""
+
+msgid "Foo was enabled."
+msgstr ""
+
+msgid "This is the end of the test."
+msgstr ""
--- /dev/null
+<html>
+ <head>
+ <title>A little template test</title>
+ </head>
+ <body>
+ <p>This is a test.</p>
+
+ <p><_>This is a different test pattern. You may notice that
+ since the block doesn't close the last tag, we had to
+ use a special pseudo-tag to show the gettext magic that
+ we want to translate it. In most cases this isn't required,
+ though.</_>
+[% IF foo %]
+ <_>Foo was enabled.</_>
+[% END %]
+ <_>This is the end of the test.</_></p>
+ </body>
+</html>
--- /dev/null
+# template file for test.tmpl
+msgid ""
+msgstr ""
+"Project-Id-Version: myproject\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2005-11-24 21:11+0200\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+msgid "A little template test"
+msgstr ""
+
+msgid "This is a test."
+msgstr ""
+
+msgid ""
+"This is a different test pattern. You may notice that\n"
+" since the block doesn't close the last tag, we had to\n"
+" use a special pseudo-tag to show the gettext magic that\n"
+" we want to translate it. In most cases this isn't required,\n"
+" though."
+msgstr ""
+
+msgid "Foo was enabled."
+msgstr ""
+
+msgid "This is the end of the test."
+msgstr ""