summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: 39ee1161be1f4f26d8e07a9339a5863fa3492e82 (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. }
  91. elsif ( $myconfig->{dateformat} =~ /^yy/ ) {
  92. $mm++;
  93. $dd = substr( "0$dd", -2 );
  94. $mm = substr( "0$mm", -2 );
  95. $longdate = "$yy$spc$mm$spc$dd";
  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. }
  103. if ( defined $longformat ) {
  104. $longdate = &text( $self, $longmonth[ --$mm ] ) . " $dd $yy";
  105. }
  106. $longdate;
  107. }
  108. 1;