]> git.sesse.net Git - ttk-gettext/commitdiff
Add all the files.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 24 Jul 2005 19:18:37 +0000 (19:18 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 24 Jul 2005 19:18:37 +0000 (19:18 +0000)
README [new file with mode: 0644]
Sesse::ExtractGettext.pm [new file with mode: 0644]
Sesse::GettextizeTemplates.pm [new file with mode: 0644]
make-pot.pl [new file with mode: 0644]
messages.pot [new file with mode: 0644]
nb.po [new file with mode: 0644]
nb/LC_MESSAGES/myproject.mo [new file with mode: 0644]
process-template.pl [new file with mode: 0644]
templates.pot [new file with mode: 0644]
test.tmpl [new file with mode: 0644]
tpl-test.pot [new file with mode: 0644]

diff --git a/README b/README
new file mode 100644 (file)
index 0000000..bf4aa66
--- /dev/null
+++ b/README
@@ -0,0 +1,35 @@
+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 :-)
diff --git a/Sesse::ExtractGettext.pm b/Sesse::ExtractGettext.pm
new file mode 100644 (file)
index 0000000..734962f
--- /dev/null
@@ -0,0 +1,27 @@
+
+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);
+}
+
+
+
diff --git a/Sesse::GettextizeTemplates.pm b/Sesse::GettextizeTemplates.pm
new file mode 100644 (file)
index 0000000..44d433a
--- /dev/null
@@ -0,0 +1,28 @@
+
+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);
+}
+
+
+
diff --git a/make-pot.pl b/make-pot.pl
new file mode 100644 (file)
index 0000000..7a9a4b4
--- /dev/null
@@ -0,0 +1,26 @@
+#! /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";
diff --git a/messages.pot b/messages.pot
new file mode 100644 (file)
index 0000000..afed637
--- /dev/null
@@ -0,0 +1,20 @@
+# 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 ""
diff --git a/nb.po b/nb.po
new file mode 100644 (file)
index 0000000..033125a
--- /dev/null
+++ b/nb.po
@@ -0,0 +1,53 @@
+# #-#-#-#-#  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."
diff --git a/nb/LC_MESSAGES/myproject.mo b/nb/LC_MESSAGES/myproject.mo
new file mode 100644 (file)
index 0000000..10628c6
Binary files /dev/null and b/nb/LC_MESSAGES/myproject.mo differ
diff --git a/process-template.pl b/process-template.pl
new file mode 100644 (file)
index 0000000..b417b89
--- /dev/null
@@ -0,0 +1,29 @@
+#! /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;
diff --git a/templates.pot b/templates.pot
new file mode 100644 (file)
index 0000000..86c4f7e
--- /dev/null
@@ -0,0 +1,52 @@
+# #-#-#-#-#  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 ""
diff --git a/test.tmpl b/test.tmpl
new file mode 100644 (file)
index 0000000..2c6f6b3
--- /dev/null
+++ b/test.tmpl
@@ -0,0 +1,18 @@
+<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>
diff --git a/tpl-test.pot b/tpl-test.pot
new file mode 100644 (file)
index 0000000..a971dc5
--- /dev/null
@@ -0,0 +1,29 @@
+# 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 ""