summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: 5b1e75689f6aa666c908fea748795ed2e9c1dc6e (plain)
  1. #=====================================================================
  2. #
  3. # Locale support module for LedgerSMB
  4. # LedgerSMB::Locale
  5. #
  6. # LedgerSMB
  7. # Small Medium Business Accounting software
  8. # http://www.ledgersmb.org/
  9. #
  10. #
  11. # Copyright (C) 2006
  12. # This work contains copyrighted information from a number of sources all used
  13. # with permission. It is released under the GNU General Public License
  14. # Version 2 or, at your option, any later version. See COPYRIGHT file for
  15. # details.
  16. #
  17. #
  18. #======================================================================
  19. # This package contains locale related functions:
  20. #`
  21. # get_handle - gets a locale handle
  22. # text - outputs HTML escaped translation for input text
  23. # date - formats date for the locale
  24. #
  25. #====================================================================
  26. package LedgerSMB::Locale;
  27. use base 'Locale::Maketext';
  28. use Locale::Maketext::Lexicon;
  29. use HTML::Entities;
  30. use Encode;
  31. Locale::Maketext::Lexicon->import({
  32. '*' => [
  33. Gettext => "${LedgerSMB::Sysconfig::localepath}/*.po",
  34. ],
  35. _auto => 1,
  36. _decode => 1,
  37. });
  38. sub text {
  39. my ($self, $text) = @_;
  40. return encode_entities($self->maketext($text));
  41. }
  42. ##sub date {
  43. ## my ($self, $myconfig, $date, $longformat) = @_;
  44. ## return $date;
  45. ##}
  46. sub date {
  47. my ($self, $myconfig, $date, $longformat) = @_;
  48. my @longmonth = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
  49. @longmonth = ("January", "February", "March", "April", "May ", "June",
  50. "July", "August", "September", "October", "November",
  51. "December") if $longformat;
  52. my $longdate = '';
  53. return '' if not $date;
  54. my $spc = '';
  55. my $yy = '';
  56. my $mm = '';
  57. my $dd = '';
  58. # get separator
  59. $spc = $myconfig->{dateformat};
  60. $spc =~ s/\w//g;
  61. $spc = substr($spc, 0, 1);
  62. if ($date =~ /\D/) {
  63. if ($myconfig->{dateformat} =~ /^yy/) {
  64. ($yy, $mm, $dd) = split /\D/, $date;
  65. }
  66. if ($myconfig->{dateformat} =~ /^mm/) {
  67. ($mm, $dd, $yy) = split /\D/, $date;
  68. }
  69. if ($myconfig->{dateformat} =~ /^dd/) {
  70. ($dd, $mm, $yy) = split /\D/, $date;
  71. }
  72. } else {
  73. $date = substr($date, 2);
  74. ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
  75. }
  76. $dd *= 1;
  77. $mm--;
  78. $yy += 2000 if length $yy == 2;
  79. if ($myconfig->{dateformat} =~ /^dd/) {
  80. $mm++;
  81. $dd = substr("0$dd", -2);
  82. $mm = substr("0$mm", -2);
  83. $longdate = "$dd$spc$mm$spc$yy";
  84. if (defined $longformat) {
  85. $longdate = "$dd";
  86. $longdate .= ($spc eq '.') ? ". " : " ";
  87. $longdate .= &text($self, $longmonth[--$mm])." $yy";
  88. }
  89. } elsif ($myconfig->{dateformat} =~ /^yy/) {
  90. $mm++;
  91. $dd = substr("0$dd", -2);
  92. $mm = substr("0$mm", -2);
  93. $longdate = "$yy$spc$mm$spc$dd";
  94. if (defined $longformat) {
  95. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  96. }
  97. } else {
  98. $mm++;
  99. $dd = substr("0$dd", -2);
  100. $mm = substr("0$mm", -2);
  101. $longdate = "$mm$spc$dd$spc$yy";
  102. if (defined $longformat) {
  103. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  104. }
  105. }
  106. }
  107. 1;