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