summaryrefslogtreecommitdiff
path: root/LedgerSMB/Template/TTI18N.pm
blob: bd79edb13cba2745eab1b633d8cc7f4aec3110df (plain)
  1. =head1 NAME
  2. LedgerSMB::Template::TTI18N Template Toolkit i18n support functions
  3. =head1 SYNOPSIS
  4. Various functions for Template Toolkit templates for internationalisation
  5. support.
  6. =head1 METHODS
  7. =over
  8. =item <?lsmb gettext(locale, 'string [_1]', param) ?>
  9. Output the gettext translation for the string in the given locale. If
  10. locale is a LedgerSMB::Locale object, it uses it. If it is a string, the
  11. locale is loaded, cached, and used.
  12. =back
  13. =head1 Copyright (C) 2007, The LedgerSMB core team.
  14. This work contains copyrighted information from a number of sources all used
  15. with permission.
  16. It is released under the GNU General Public License Version 2 or, at your
  17. option, any later version. See COPYRIGHT file for details. For a full list
  18. including contact information of contributors, maintainers, and copyright
  19. holders, see the CONTRIBUTORS file.
  20. =cut
  21. package LedgerSMB::Template::TTI18N;
  22. use LedgerSMB::Locale;
  23. my %locales; # Cache string-loaded locales
  24. our $ttfuncs = {};
  25. $ttfuncs->{gettext} = sub {
  26. my $locale = shift;
  27. if (ref $locale) {
  28. return $locale->text(@_);
  29. } elsif ($locales{$locale}) {
  30. return $locales{$locale}->text(@_);
  31. } else {
  32. $locales{$locale} = LedgerSMB::Locale->get_handle($locale);
  33. return $locales{$locale}->text(@_);
  34. }
  35. };