summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: 9f4d2fdb87d5c3e93f45d7281ff176bbcf11681c (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 ($date =~ /\D/) {
  62. if ($myconfig->{dateformat} =~ /^yy/) {
  63. ($yy, $mm, $dd) = split /\D/, $date;
  64. }
  65. if ($myconfig->{dateformat} =~ /^mm/) {
  66. ($mm, $dd, $yy) = split /\D/, $date;
  67. }
  68. if ($myconfig->{dateformat} =~ /^dd/) {
  69. ($dd, $mm, $yy) = split /\D/, $date;
  70. }
  71. } else {
  72. $date = substr($date, 2);
  73. ($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
  74. }
  75. $dd *= 1;
  76. $mm--;
  77. $yy += 2000 if length $yy == 2;
  78. if ($myconfig->{dateformat} =~ /^dd/) {
  79. $mm++;
  80. $dd = substr("0$dd", -2);
  81. $mm = substr("0$mm", -2);
  82. $longdate = "$dd$spc$mm$spc$yy";
  83. if (defined $longformat) {
  84. $longdate = "$dd";
  85. $longdate .= ($spc eq '.') ? ". " : " ";
  86. $longdate .= &text($self, $longmonth[--$mm])." $yy";
  87. }
  88. } elsif ($myconfig->{dateformat} =~ /^yy/) {
  89. $mm++;
  90. $dd = substr("0$dd", -2);
  91. $mm = substr("0$mm", -2);
  92. $longdate = "$yy$spc$mm$spc$dd";
  93. if (defined $longformat) {
  94. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  95. }
  96. } else {
  97. $mm++;
  98. $dd = substr("0$dd", -2);
  99. $mm = substr("0$mm", -2);
  100. $longdate = "$mm$spc$dd$spc$yy";
  101. if (defined $longformat) {
  102. $longdate = &text($self, $longmonth[--$mm])." $dd $yy";
  103. }
  104. }
  105. }
  106. 1;