From 07b5e8c7173363dfe1bec5ff4ccf99c09f27769d Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 24 Jul 2005 19:18:37 +0000 Subject: [PATCH] Add all the files. --- README | 35 ++++++++++++++++++++++ Sesse::ExtractGettext.pm | 27 +++++++++++++++++ Sesse::GettextizeTemplates.pm | 28 ++++++++++++++++++ make-pot.pl | 26 +++++++++++++++++ messages.pot | 20 +++++++++++++ nb.po | 53 ++++++++++++++++++++++++++++++++++ nb/LC_MESSAGES/myproject.mo | Bin 0 -> 1420 bytes process-template.pl | 29 +++++++++++++++++++ templates.pot | 52 +++++++++++++++++++++++++++++++++ test.tmpl | 18 ++++++++++++ tpl-test.pot | 29 +++++++++++++++++++ 11 files changed, 317 insertions(+) create mode 100644 README create mode 100644 Sesse::ExtractGettext.pm create mode 100644 Sesse::GettextizeTemplates.pm create mode 100644 make-pot.pl create mode 100644 messages.pot create mode 100644 nb.po create mode 100644 nb/LC_MESSAGES/myproject.mo create mode 100644 process-template.pl create mode 100644 templates.pot create mode 100644 test.tmpl create mode 100644 tpl-test.pot diff --git a/README b/README new file mode 100644 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 , +licensed under the GPLv2. Absolutely no warranty. Comments welcome :-) diff --git a/Sesse::ExtractGettext.pm b/Sesse::ExtractGettext.pm new file mode 100644 index 0000000..734962f --- /dev/null +++ b/Sesse::ExtractGettext.pm @@ -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 index 0000000..44d433a --- /dev/null +++ b/Sesse::GettextizeTemplates.pm @@ -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 index 0000000..7a9a4b4 --- /dev/null +++ b/make-pot.pl @@ -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 index 0000000..afed637 --- /dev/null +++ b/messages.pot @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 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 , 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 \n" +"Language-Team: Norwegian Bokmal \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 index 0000000000000000000000000000000000000000..10628c6e0b2e1aafa9d4f82a5d9022da2dc6ae68 GIT binary patch literal 1420 zcmbVM&5j#I5FSDx$VmJh2nP;@5U>&3gKZ^ZHJgpH*?7Z>Y+`MONE|q{XUgM_XS#;& zo|t_Ht~>&7zyZ#@08fC#m6w38$Bs8bNc^<@sk&?GzpDG!w=RE|U|j*;1#;k3;9DTB zAAz@lpMW=jUw{vR-+(`WS6)bx*CV~O)_(`|2jB*975v{XukBrWDM>!S`8CiT(CeUY zf_?=W{R${dB_PR*!1D{Hl9xA(7$;07$syGygqkUE)7Cn~jStDO2(7dywt7}`nI<{7 z)UfxuVwyW?NV?!n$)vZc=^)7$#uNUUN;99cV;g#d)anq}*_6JNjv9SVR)Q(uZK1<} z`sI!78BDWUiY1l8-hLFQsKrM?rdlJ2psQV4F)egSK{mP_BsBS!3!`glJ$I!jNJ4`A zLRP(c#fae>q@gQQJntFSRysy16r8rcuY(CGomgrFJ`3&HL!(bF#^m_x&Nwc2H~zyy zx@v(kZS#+1yg0|`*_I^pK9cpv_toY{&noNFRs!uz505@Syf>l8le0%B4@+y~%2GfVRI&!Q7 z^wnLoJ)`k(ctZ_8RpaY49%ZA^$3t)+sLuGQiGKcGZoHPekJhMsQ#^4QJqm2BcJx_F z_c~i5RIzl^SI_phXQrBqgtU<6*5JOjRfo}1IqN2)2jW&-8Exr~EE{z6rWx&7WoNf* z<1t5RYiyNvMp7%c2B#;dlZ#@+tdGP7jGoHRTVxiS{t1TL*nKJ%+IbEKU*yMX??NsH zj&W5JTSy7p8STwX7;MW<6xv$#ZRnew({ 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 index 0000000..86c4f7e --- /dev/null +++ b/templates.pot @@ -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 , 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 \n" +"Language-Team: LANGUAGE \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 index 0000000..2c6f6b3 --- /dev/null +++ b/test.tmpl @@ -0,0 +1,18 @@ + + + A little template test + + +

This is a test.

+ +

<_>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.

+ + diff --git a/tpl-test.pot b/tpl-test.pot new file mode 100644 index 0000000..a971dc5 --- /dev/null +++ b/tpl-test.pot @@ -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 "" -- 2.39.2