summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: 6b1c4e664e371569e72e86d5c5a69c2d7a1d4fe4 (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. _auto => 1,
  34. _decode => 1,
  35. }
  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 = (
  49. "January", "February", "March", "April",
  50. "May ", "June", "July", "August",
  51. "September", "October", "November", "December"
  52. ) 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 ( !$longformat && $date =~ /^\d{4}\D/ ) { # reparsing date at this point
  64. # causes problems!
  65. return $date;
  66. }
  67. if ( $date =~ /\D/ ) {
  68. if ( $myconfig->{dateformat} =~ /^yy/ ) {
  69. ( $yy, $mm, $dd ) = split /\D/, $date;
  70. }
  71. if ( $myconfig->{dateformat} =~ /^mm/ ) {
  72. ( $mm, $dd, $yy ) = split /\D/, $date;
  73. }
  74. if ( $myconfig->{dateformat} =~ /^dd/ ) {
  75. ( $dd, $mm, $yy ) = split /\D/, $date;
  76. }
  77. }
  78. else {
  79. $date = substr( $date, 2 );
  80. ( $yy, $mm, $dd ) = ( $date =~ /(..)(..)(..)/ );
  81. }
  82. $dd *= 1;
  83. $mm--;
  84. $yy += 2000 if length $yy == 2;
  85. if ( $myconfig->{dateformat} =~ /^dd/ ) {
  86. $mm++;
  87. $dd = substr( "0$dd", -2 );
  88. $mm = substr( "0$mm", -2 );
  89. $longdate = "$dd$spc$mm$spc$yy";
  90. if ( defined $longformat ) {
  91. $longdate = "$dd";
  92. $longdate .= ( $spc eq '.' ) ? ". " : " ";
  93. $longdate .= &text( $self, $longmonth[ --$mm ] ) . " $yy";
  94. }
  95. }
  96. elsif ( $myconfig->{dateformat} =~ /^yy/ ) {
  97. $mm++;
  98. $dd = substr( "0$dd", -2 );
  99. $mm = substr( "0$mm", -2 );
  100. $longdate = "$yy$spc$mm$spc$dd";
  101. }
  102. else {
  103. $mm++;
  104. $dd = substr( "0$dd", -2 );
  105. $mm = substr( "0$mm", -2 );
  106. $longdate = "$mm$spc$dd$spc$yy";
  107. }
  108. if ( defined $longformat ) {
  109. $longdate = &text( $self, $longmonth[ --$mm ] ) . " $dd $yy";
  110. }
  111. $longdate;
  112. }
  113. 1;