summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: c61925108c512991d35a29c484665064f53c668a (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 Encode;
  30. Locale::Maketext::Lexicon->import({
  31. '*' => [
  32. Gettext => "${LedgerSMB::Sysconfig::localepath}/*.po",
  33. ],
  34. _auto => 1,
  35. _decode => 1,
  36. });
  37. sub text {
  38. my ($self, $text, @params) = @_;
  39. return $self->maketext($text, @params);
  40. }
  41. ##sub date {
  42. ## my ($self, $myconfig, $date, $longformat) = @_;
  43. ## return $date;
  44. ##}
  45. sub date {
  46. my ($self, $myconfig, $date, $longformat) = @_;
  47. my @longmonth = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
  48. @longmonth = ("January", "February", "March", "April", "May ", "June",
  49. "July", "August", "September", "October", "November",
  50. "December") if $longformat;
  51. my $longdate = '';
  52. return '' if not $date;
  53. my $spc = '';
  54. my $yy = '';
  55. my $mm = '';
  56. my $dd = '';
  57. # get separator
  58. $spc = $myconfig->{dateformat};
  59. $spc =~ s/\w//g;
  60. $spc = substr($spc, 0, 1);
  61. if (!$longformat && $date =~ /^\d{4}\D/){ # reparsing date at this point
  62. # causes problems!
  63. return $date;
  64. }
  65. if ($date =~ /\D/) {
  66. if ($myconfig->{dateformat} =~ /^yy/) {
  67. ($yy, $mm, $dd) = split /\D/, $date;
  68. }
  69. if ($myconfig->{dateformat} =~ /^mm/) {
  70. ($mm, $dd, $yy) = split /\D/, $date;
  71. }
  72. if ($myconfig->{dateformat} =~ /^dd/) {
  73. ($dd, $mm, $yy) = split /\D/, $date;
  74. }
  75. } else {
  76. $date = substr($date, 2);
  77. ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
  78. }
  79. $dd *= 1;
  80. $mm--;
  81. $yy += 2000 if length $yy == 2;
  82. if ($myconfig->{dateformat} =~ /^dd/) {
  83. $mm++;
  84. $dd = substr("0$dd", -2);
  85. $mm = substr("0$mm", -2);
  86. $longdate = "$dd$spc$mm$spc$yy";
  87. if (defined $longformat) {
  88. $longdate = "$dd";
  89. $longdate .= ($spc eq '.') ? ". " : " ";
  90. $longdate .= &text($self, $longmonth[--$mm])." $yy";
  91. }
  92. } elsif ($myconfig->{dateformat} =~ /^yy/) {
  93. $mm++;
  94. $dd = substr("0$dd", -2);
  95. $mm = substr("0$mm", -2);
  96. $longdate = "$yy$spc$mm$spc$dd";
  97. if (defined $longformat) {
  98. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  99. }
  100. } else {
  101. $mm++;
  102. $dd = substr("0$dd", -2);
  103. $mm = substr("0$mm", -2);
  104. $longdate = "$mm$spc$dd$spc$yy";
  105. if (defined $longformat) {
  106. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  107. }
  108. }
  109. }
  110. 1;