summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-06-22 19:04:24 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2007-06-22 19:04:24 +0000
commitbfa1a35ab8b449de5047bbbf7a85cbd0cc4e20a1 (patch)
tree25885edbe21b05839cacbe8b3249017c79736c23 /LedgerSMB/Template
parenteb21ae5da75a6d71afa8edc894b85701553f0751 (diff)
Template handling adjustments
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1308 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/Template')
-rwxr-xr-xLedgerSMB/Template/HTML.pm6
-rwxr-xr-xLedgerSMB/Template/PDF.pm6
-rwxr-xr-xLedgerSMB/Template/PS.pm5
-rw-r--r--LedgerSMB/Template/TTI18N.pm53
-rwxr-xr-xLedgerSMB/Template/TXT.pm5
5 files changed, 71 insertions, 4 deletions
diff --git a/LedgerSMB/Template/HTML.pm b/LedgerSMB/Template/HTML.pm
index d02000a9..0ca82bcc 100755
--- a/LedgerSMB/Template/HTML.pm
+++ b/LedgerSMB/Template/HTML.pm
@@ -42,6 +42,7 @@ package LedgerSMB::Template::HTML;
use Error qw(:try);
use CGI;
use Template;
+use LedgerSMB::Template::TTI18N;
sub get_template {
my $name = shift;
@@ -54,6 +55,7 @@ sub preprocess {
my $type = ref $rawvars;
#XXX fix escaping function
+ return $rawvars if $type =~ /^LedgerSMB::Locale/;
if ( $type eq 'ARRAY' ) {
for (@{$rawvars}) {
push @{$vars}, preprocess( $_ );
@@ -83,7 +85,9 @@ sub process {
}) || throw Error::Simple Template->error();
if (not $template->process(
get_template($parent->{template}),
- $cleanvars, "$parent->{outputfile}.html", binmode => ':utf8')) {
+ {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+ 'escape' => \&preprocess},
+ "$parent->{outputfile}.html", binmode => ':utf8')) {
throw Error::Simple $template->error();
}
$parent->{mimetype} = 'text/html';
diff --git a/LedgerSMB/Template/PDF.pm b/LedgerSMB/Template/PDF.pm
index f201b11d..cd244736 100755
--- a/LedgerSMB/Template/PDF.pm
+++ b/LedgerSMB/Template/PDF.pm
@@ -40,6 +40,7 @@ package LedgerSMB::Template::PDF;
use Error qw(:try);
use Template::Latex;
+use LedgerSMB::Template::TTI18N;
sub get_template {
my $name = shift;
@@ -51,6 +52,7 @@ sub preprocess {
my $vars;
my $type = ref $rawvars;
+ return $rawvars if $type =~ /^LedgerSMB::Locale/;
if ($type eq 'ARRAY') {
for (@{$rawvars}) {
push @{$vars}, preprocess($_);
@@ -83,7 +85,9 @@ sub process {
if (not $template->process(
get_template($parent->{template}),
- $cleanvars, "$parent->{outputfile}.pdf", binmode => 1)) {
+ {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+ 'escape' => \&preprocess},
+ "$parent->{outputfile}.pdf", binmode => 1)) {
throw Error::Simple $template->error();
}
$parent->{mimetype} = 'application/pdf';
diff --git a/LedgerSMB/Template/PS.pm b/LedgerSMB/Template/PS.pm
index 10a3806e..ac58204d 100755
--- a/LedgerSMB/Template/PS.pm
+++ b/LedgerSMB/Template/PS.pm
@@ -40,6 +40,7 @@ package LedgerSMB::Template::PS;
use Error qw(:try);
use Template::Latex;
+use LedgerSMB::Template::TTI18N;
sub get_template {
my $name = shift;
@@ -69,7 +70,9 @@ sub process {
if (not $template->process(
get_template($parent->{template}),
- $cleanvars, "$parent->{outputfile}.ps", binmode => ':utf8')) {
+ {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+ 'escape' => \&preprocess},
+ "$parent->{outputfile}.ps", binmode => 1)) {
throw Error::Simple $template->error();
}
$parent->{mimetype} = 'application/postscript';
diff --git a/LedgerSMB/Template/TTI18N.pm b/LedgerSMB/Template/TTI18N.pm
new file mode 100644
index 00000000..bd79edb1
--- /dev/null
+++ b/LedgerSMB/Template/TTI18N.pm
@@ -0,0 +1,53 @@
+
+=head1 NAME
+
+LedgerSMB::Template::TTI18N Template Toolkit i18n support functions
+
+=head1 SYNOPSIS
+
+Various functions for Template Toolkit templates for internationalisation
+support.
+
+=head1 METHODS
+
+=over
+
+=item <?lsmb gettext(locale, 'string [_1]', param) ?>
+
+Output the gettext translation for the string in the given locale. If
+locale is a LedgerSMB::Locale object, it uses it. If it is a string, the
+locale is loaded, cached, and used.
+
+=back
+
+=head1 Copyright (C) 2007, The LedgerSMB core team.
+
+This work contains copyrighted information from a number of sources all used
+with permission.
+
+It is released under the GNU General Public License Version 2 or, at your
+option, any later version. See COPYRIGHT file for details. For a full list
+including contact information of contributors, maintainers, and copyright
+holders, see the CONTRIBUTORS file.
+=cut
+
+package LedgerSMB::Template::TTI18N;
+
+use LedgerSMB::Locale;
+
+my %locales; # Cache string-loaded locales
+our $ttfuncs = {};
+
+$ttfuncs->{gettext} = sub {
+ my $locale = shift;
+ if (ref $locale) {
+ return $locale->text(@_);
+ } elsif ($locales{$locale}) {
+ return $locales{$locale}->text(@_);
+ } else {
+ $locales{$locale} = LedgerSMB::Locale->get_handle($locale);
+ return $locales{$locale}->text(@_);
+ }
+};
+
+
diff --git a/LedgerSMB/Template/TXT.pm b/LedgerSMB/Template/TXT.pm
index 40d6edb5..a950335f 100755
--- a/LedgerSMB/Template/TXT.pm
+++ b/LedgerSMB/Template/TXT.pm
@@ -40,6 +40,7 @@ package LedgerSMB::Template::TXT;
use Error qw(:try);
use Template;
+use LedgerSMB::Template::TTI18N;
sub get_template {
my $name = shift;
@@ -65,7 +66,9 @@ sub process {
if (not $template->process(
get_template($parent->{template}),
- $cleanvars, "$parent->{outputfile}.txt", binmode => ':utf8')) {
+ {%$cleanvars, %$LedgerSMB::Template::TTI18N::ttfuncs,
+ 'escape' => \&preprocess},
+ "$parent->{outputfile}.txt", binmode => ':utf8')) {
throw Error::Simple $template->error();
}
$parent->{mimetype} = 'text/plain';