summaryrefslogtreecommitdiff
path: root/LedgerSMB/Locale.pm
blob: bfa4e461915e85f3231e77d2338fadd82ac5e286 (plain)
  1. =head1 NAME
  2. LedgerSMB::Locale Locale handling class for LedgerSMB
  3. =head1 SYNOPSIS
  4. Locale support module for LedgerSMB. Uses Locale::Maketext::Lexicon as a base.
  5. =head1 METHODS
  6. =item get_handle ($language_code)
  7. Returns a locale handle for accessing the other methods. Inherited from
  8. Locale::Maketext.
  9. =item text ($string)
  10. Returns the translation for the given string. This is a legacy wrapper that
  11. merely calls $self->maketext.
  12. =item date ($myconfig, $date, $longformat)
  13. Returns the given date after formatting it. $longformat is a ternary flag that
  14. determines how the date is formatted. If $longformat is true, the date will be
  15. given in the form of "_('September') 23 2007". If $longformat is false but
  16. defined, the date will be in the form of "_('Sep') 23 2007" unless the date is
  17. given in the form 'yyyy.mm.dd', in which case it is returned as-is. If
  18. $longformat is not defined, the date will be output in the format specified by
  19. $myconfig->{dateformat}.
  20. =head1 Copyright (C) 2006, The LedgerSMB core team.
  21. #=====================================================================
  22. #
  23. # Locale support module for LedgerSMB
  24. # LedgerSMB::Locale
  25. #
  26. # LedgerSMB
  27. # Small Medium Business Accounting software
  28. # http://www.ledgersmb.org/
  29. #
  30. #
  31. # Copyright (C) 2006
  32. # This work contains copyrighted information from a number of sources all used
  33. # with permission. It is released under the GNU General Public License
  34. # Version 2 or, at your option, any later version. See COPYRIGHT file for
  35. # details.
  36. #
  37. # This file contains source code included with or based on SQL-Ledger which
  38. # is Copyright Dieter Simader and DWS Systems Inc. 2000-2005 and licensed
  39. # under the GNU General Public License version 2 or, at your option, any later
  40. # version. For a full list including contact information of contributors,
  41. # maintainers, and copyright holders, see the CONTRIBUTORS file.
  42. #
  43. # Original Copyright Notice from SQL-Ledger 2.6.17 (before the fork):
  44. # Copyright (C) 2000
  45. #
  46. # Author: DWS Systems Inc.
  47. # Web: http://www.sql-ledger.org
  48. #
  49. # Contributors: Thomas Bayen <bayen@gmx.de>
  50. # Antti Kaihola <akaihola@siba.fi>
  51. # Moritz Bunkus (tex)
  52. # Jim Rawlings <jim@your-dba.com> (DB2)
  53. #
  54. #======================================================================
  55. =cut
  56. package LedgerSMB::Locale;
  57. use base 'Locale::Maketext';
  58. use Locale::Maketext::Lexicon;
  59. use Encode;
  60. Locale::Maketext::Lexicon->import(
  61. {
  62. '*' => [ Gettext => "${LedgerSMB::Sysconfig::localepath}/*.po", ],
  63. _auto => 1,
  64. _decode => 1,
  65. }
  66. );
  67. sub text {
  68. my ( $self, $text, @params ) = @_;
  69. return $self->maketext( $text, @params );
  70. }
  71. ##sub date {
  72. ## my ($self, $myconfig, $date, $longformat) = @_;
  73. ## return $date;
  74. ##}
  75. sub date {
  76. my ( $self, $myconfig, $date, $longformat ) = @_;
  77. my @longmonth = (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
  78. @longmonth = (
  79. "January", "February", "March", "April",
  80. "May ", "June", "July", "August",
  81. "September", "October", "November", "December"
  82. ) if $longformat;
  83. my $longdate = '';
  84. return '' if not $date;
  85. my $spc = '';
  86. my $yy = '';
  87. my $mm = '';
  88. my $dd = '';
  89. # get separator
  90. $spc = $myconfig->{dateformat};
  91. $spc =~ s/\w//g;
  92. $spc = substr( $spc, 0, 1 );
  93. if ( !$longformat && $date =~ /^\d{4}\D/ ) { # reparsing date at this point
  94. # causes problems!
  95. return $date;
  96. }
  97. if ( $date =~ /\D/ ) {
  98. if ( $myconfig->{dateformat} =~ /^yy/ ) {
  99. ( $yy, $mm, $dd ) = split /\D/, $date;
  100. }
  101. if ( $myconfig->{dateformat} =~ /^mm/ ) {
  102. ( $mm, $dd, $yy ) = split /\D/, $date;
  103. }
  104. if ( $myconfig->{dateformat} =~ /^dd/ ) {
  105. ( $dd, $mm, $yy ) = split /\D/, $date;
  106. }
  107. }
  108. else {
  109. $date = substr( $date, 2 );
  110. ( $yy, $mm, $dd ) = ( $date =~ /(..)(..)(..)/ );
  111. }
  112. $dd *= 1;
  113. $mm--;
  114. $yy += 2000 if length $yy == 2;
  115. if ( $myconfig->{dateformat} =~ /^dd/ ) {
  116. $mm++;
  117. $dd = substr( "0$dd", -2 );
  118. $mm = substr( "0$mm", -2 );
  119. $longdate = "$dd$spc$mm$spc$yy";
  120. }
  121. elsif ( $myconfig->{dateformat} =~ /^yy/ ) {
  122. $mm++;
  123. $dd = substr( "0$dd", -2 );
  124. $mm = substr( "0$mm", -2 );
  125. $longdate = "$yy$spc$mm$spc$dd";
  126. }
  127. else {
  128. $mm++;
  129. $dd = substr( "0$dd", -2 );
  130. $mm = substr( "0$mm", -2 );
  131. $longdate = "$mm$spc$dd$spc$yy";
  132. }
  133. if ( defined $longformat ) {
  134. $longdate = &text( $self, $longmonth[ --$mm ] ) . " $dd $yy";
  135. }
  136. $longdate;
  137. }
  138. 1;