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