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