[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [264] trunk



Revision: 264
          http://svn.sourceforge.net/ledger-smb/?rev=264&view=rev
Author:   tetragon
Date:     2006-10-23 13:14:15 -0700 (Mon, 23 Oct 2006)

Log Message:
-----------
Convert locales to Locale::Maketext::Lexicon

Modified Paths:
--------------
    trunk/LedgerSMB/Form.pm
    trunk/bin/admin.pl
    trunk/bin/am.pl
    trunk/bin/login.pl
    trunk/bin/oe.pl
    trunk/menu.pl

Added Paths:
-----------
    trunk/LedgerSMB/Locale.pm
    trunk/locale/mo/
    trunk/locale/mo/en/
    trunk/locale/mo/en/LC_MESSAGES/
    trunk/locale/mo/en/LC_MESSAGES/LedgerSMB.mo
    trunk/locale/po/
    trunk/locale/po/en.po

Modified: trunk/LedgerSMB/Form.pm
===================================================================
--- trunk/LedgerSMB/Form.pm	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/LedgerSMB/Form.pm	2006-10-23 20:14:15 UTC (rev 264)
@@ -3110,112 +3110,4 @@
 	$rv;
 }
 
-package Locale;
-
-sub new {
-	my ($type, $country, $NLS_file) = @_;
-	my $self = {};
-
-	%self = ();
-
-	if ($country && -d "locale/$country") {
-		$self->{countrycode} = $country;
-		eval { require "locale/$country/$NLS_file"; };
-	}
-
-	$self->{NLS_file} = $NLS_file;
-	$self->{charset} = $self{charset};
-
-	push @{ $self->{LONG_MONTH} }, ("January", "February", "March", "April", "May ", "June", "July", "August", "September", "October", "November", "December");
-	push @{ $self->{SHORT_MONTH} }, (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
-
-	bless $self, $type;
-}
-
-
-sub text {
-	my ($self, $text) = @_;
-	return (exists $self{texts}{$text}) ? $self{texts}{$text} : $text;
-}
-
-
-sub date {
-
-	my ($self, $myconfig, $date, $longformat) = @_;
-
-	my $longdate = "";
-	my $longmonth = ($longformat) ? 'LONG_MONTH' : 'SHORT_MONTH';
-
-
-	if ($date) {
-
-		# get separator
-		$spc = $myconfig->{dateformat};
-		$spc =~ s/\w//g;
-		$spc = substr($spc, 0, 1);
-
-		if ($date =~ /\D/) {
-
-			if ($myconfig->{dateformat} =~ /^yy/) {
-				($yy, $mm, $dd) = split /\D/, $date;
-			}
-
-			if ($myconfig->{dateformat} =~ /^mm/) {
-				($mm, $dd, $yy) = split /\D/, $date;
-			}
-
-			if ($myconfig->{dateformat} =~ /^dd/) {
-				($dd, $mm, $yy) = split /\D/, $date;
-			}
-
-		} else {
-
-			$date = substr($date, 2);
-			($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
-		}
-
-		$dd *= 1;
-		$mm--;
-		$yy += 2000 if length $yy == 2;
-
-		if ($myconfig->{dateformat} =~ /^dd/) {
-
-			$mm++;
-			$dd = substr("0$dd", -2);
-			$mm = substr("0$mm", -2);
-			$longdate = "$dd$spc$mm$spc$yy";
-
-			if (defined $longformat) {
-				$longdate = "$dd";
-				$longdate .= ($spc eq '.') ? ". " : " ";
-				$longdate .= &text($self, $self->{$longmonth}[--$mm])." $yy";
-			}
-
-		} elsif ($myconfig->{dateformat} =~ /^yy/) {
-
-			$mm++;
-			$dd = substr("0$dd", -2);
-			$mm = substr("0$mm", -2);
-			$longdate = "$yy$spc$mm$spc$dd"; 
-
-			if (defined $longformat) {
-				$longdate = &text($self, $self->{$longmonth}[--$mm])." $dd $yy";
-			}
-
-		} else {
-
-			$mm++;
-			$dd = substr("0$dd", -2);
-			$mm = substr("0$mm", -2);
-			$longdate = "$mm$spc$dd$spc$yy"; 
-
-			if (defined $longformat) {
-				$longdate = &text($self, $self->{$longmonth}[--$mm])." $dd $yy";
-			}
-		}
-	}
-
-	$longdate;
-}
-
 1;

Added: trunk/LedgerSMB/Locale.pm
===================================================================
--- trunk/LedgerSMB/Locale.pm	                        (rev 0)
+++ trunk/LedgerSMB/Locale.pm	2006-10-23 20:14:15 UTC (rev 264)
@@ -0,0 +1,134 @@
+#=====================================================================
+#
+# Locale support module for LedgerSMB
+# LedgerSMB::Locale
+#
+# LedgerSMB 
+# Small Medium Business Accounting software
+# http://www.ledgersmb.org/
+# 
+#
+# Copyright (C) 2006
+# This work contains copyrighted information from a number of sources all used
+# with permission.  It is released under the GNU General Public License 
+# Version 2 or, at your option, any later version.  See COPYRIGHT file for 
+# details.
+#
+#
+#======================================================================
+# This package contains locale related functions:
+#
+# get_handle - gets a locale handle
+# text - outputs HTML escaped translation for input text
+# date - formats date for the locale
+#
+#====================================================================
+
+package LedgerSMB::Locale;
+use base 'Locale::Maketext';
+use Locale::Maketext::Lexicon;
+use HTML::Entities;
+use Encode;
+
+$localepath = 'locale/mo';
+Locale::Maketext::Lexicon->import({
+	'*' => [
+		Gettext => "$localepath/*/LC_MESSAGES/LedgerSMB.mo",
+	],
+	_auto => 1,
+	_decode => 1,
+});
+
+sub text {
+	my ($self, $text) = @_;
+	return encode_entities($self->maketext($text));
+}
+
+##sub date {
+##	my ($self, $myconfig, $date, $longformat) = @_;
+##	return $date;
+##}
+sub date {
+	my ($self, $myconfig, $date, $longformat) = @_;
+
+	my @longmonth =  (qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec));
+	@longmonth = ("January", "February", "March", "April", "May ", "June", 
+		"July", "August", "September", "October", "November", 
+		"December") if $longformat;
+	my $longdate = '';
+
+	return '' if not $date;
+
+	my $spc = '';
+	my $yy = '';
+	my $mm = '';
+	my $dd = '';
+
+	# get separator
+	$spc = $myconfig->{dateformat};
+	$spc =~ s/\w//g;
+	$spc = substr($spc, 0, 1);
+
+	if ($date =~ /\D/) {
+
+		if ($myconfig->{dateformat} =~ /^yy/) {
+			($yy, $mm, $dd) = split /\D/, $date;
+		}
+
+		if ($myconfig->{dateformat} =~ /^mm/) {
+			($mm, $dd, $yy) = split /\D/, $date;
+		}
+
+		if ($myconfig->{dateformat} =~ /^dd/) {
+			($dd, $mm, $yy) = split /\D/, $date;
+		}
+
+	} else {
+
+		$date = substr($date, 2);
+		($yy, $mm, $dd) = ($date =~ /(..)(..)(..)/);
+	}
+
+	$dd *= 1;
+	$mm--;
+	$yy += 2000 if length $yy == 2;
+
+	if ($myconfig->{dateformat} =~ /^dd/) {
+
+		$mm++;
+		$dd = substr("0$dd", -2);
+		$mm = substr("0$mm", -2);
+		$longdate = "$dd$spc$mm$spc$yy";
+
+		if (defined $longformat) {
+			$longdate = "$dd";
+			$longdate .= ($spc eq '.') ? ". " : " ";
+			$longdate .= &text($self, $longmonth[--$mm])." $yy";
+		}
+
+	} elsif ($myconfig->{dateformat} =~ /^yy/) {
+
+		$mm++;
+		$dd = substr("0$dd", -2);
+		$mm = substr("0$mm", -2);
+		$longdate = "$yy$spc$mm$spc$dd"; 
+
+		if (defined $longformat) {
+			$longdate = &text($self, $longmonth[--$mm])." $dd $yy";
+		}
+
+	} else {
+
+		$mm++;
+		$dd = substr("0$dd", -2);
+		$mm = substr("0$mm", -2);
+		$longdate = "$mm$spc$dd$spc$yy"; 
+
+		if (defined $longformat) {
+			$longdate = &text($self, $longmonth[--$mm])." $dd $yy";
+		}
+	}
+}
+
+1;
+

Modified: trunk/bin/admin.pl
===================================================================
--- trunk/bin/admin.pl	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/bin/admin.pl	2006-10-23 20:14:15 UTC (rev 264)
@@ -37,13 +37,16 @@
 $menufile = "menu.ini";
 
 use LedgerSMB::Form;
+use LedgerSMB::Locale;
 use LedgerSMB::User;
 
 
 $form = new Form;
 
-$locale = new Locale $language, "admin";
-$form->{charset} = $locale->{charset};
+$locale = LedgerSMB::Locale->get_handle($language);
+$locale->encoding('UTF-8');
+$form->{charset} = 'UTF-8';
+#$form->{charset} = $locale->encoding;
 
 eval { require DBI; };
 $form->error($locale->text('DBI not installed!')) if ($@);

Modified: trunk/bin/am.pl
===================================================================
--- trunk/bin/am.pl	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/bin/am.pl	2006-10-23 20:14:15 UTC (rev 264)
@@ -2050,7 +2050,6 @@
   foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) {
     $countrycodes .= ($myconfig{countrycode} eq $key) ? "<option selected value=$key>$countrycodes{$key}\n" : "<option value=$key>$countrycodes{$key}\n";
   }
-  $countrycodes = qq|<option value="">English\n$countrycodes|;
 
   opendir CSS, "css/.";
   @all = grep /.*\.css$/, readdir CSS;

Modified: trunk/bin/login.pl
===================================================================
--- trunk/bin/login.pl	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/bin/login.pl	2006-10-23 20:14:15 UTC (rev 264)
@@ -39,6 +39,7 @@
 use DBI;
 use LedgerSMB::User;
 use LedgerSMB::Form;
+use LedgerSMB::Locale;
 
 ## will need this later when session_destroy will be used
 #use LedgerSMB::Session;
@@ -46,8 +47,10 @@
 
 $form = new Form;
 
-$locale = new Locale $language, "login";
-$form->{charset} = $locale->{charset};
+$locale = LedgerSMB::Locale->get_handle($language);
+$locale->encoding('UTF-8');
+$form->{charset} = 'UTF-8';
+#$form->{charset} = $locale->encoding;
 
 # customization
 if (-f "bin/custom/$form->{script}") {

Modified: trunk/bin/oe.pl
===================================================================
--- trunk/bin/oe.pl	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/bin/oe.pl	2006-10-23 20:14:15 UTC (rev 264)
@@ -45,6 +45,7 @@
 use LedgerSMB::IS;
 use LedgerSMB::PE;
 use LedgerSMB::Tax;
+use LedgerSMB::Locale;
 
 require "bin/arap.pl";
 require "bin/io.pl";
@@ -1944,7 +1945,10 @@
   $form->{type} = "invoice";
  
   # locale messages
-  $locale = new Locale "$myconfig{countrycode}", "$script";
+  $locale = LedgerSMB::Locale->get_handle($myconfig{countrycode});
+  #$form->{charset} = $locale->encoding;
+  $form->{charset} = 'UTF-8';
+  $locale->encoding('UTF-8');
 
   require "bin/$form->{script}";
 

Added: trunk/locale/mo/en/LC_MESSAGES/LedgerSMB.mo
===================================================================
(Binary files differ)


Property changes on: trunk/locale/mo/en/LC_MESSAGES/LedgerSMB.mo
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: trunk/locale/po/en.po
===================================================================
--- trunk/locale/po/en.po	                        (rev 0)
+++ trunk/locale/po/en.po	2006-10-23 20:14:15 UTC (rev 264)
@@ -0,0 +1,8 @@
+
+msgid ""
+msgstr ""
+"Project-Id-Version: LedgerSMB 1.1.1\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+

Modified: trunk/menu.pl
===================================================================
--- trunk/menu.pl	2006-10-23 19:51:03 UTC (rev 263)
+++ trunk/menu.pl	2006-10-23 20:14:15 UTC (rev 264)
@@ -60,6 +60,7 @@
 $| = 1;
 
 use LedgerSMB::Form;
+use LedgerSMB::Locale;
 use LedgerSMB::Session;
 
 eval { require "ledger-smb.conf"; };
@@ -86,7 +87,10 @@
 # check for user config file, could be missing or ???
 eval { require("$userspath/$form->{login}.conf"); };
 if ($@) {
-	$locale = new Locale "$language", "$script";
+	$locale = LedgerSMB::Locale->get_handle("fr_CA");
+	$form->{charset} = $locale->encoding;
+	$form->{charset} = 'UTF-8';
+	$locale->encoding('UTF-8');
 
 	$form->{callback} = "";
 	$msg1 = $locale->text('You are logged out!');
@@ -95,8 +99,10 @@
 }
 
 # locale messages
-$locale = new Locale "$myconfig{countrycode}", "$script";
-$form->{charset} = $locale->{charset};
+$locale = LedgerSMB::Locale->get_handle($myconfig{countrycode});
+#$form->{charset} = $locale->encoding;
+$form->{charset} = 'UTF-8';
+$locale->encoding('UTF-8');
 
 # send warnings to browser
 $SIG{__WARN__} = sub { $form->info($_[0]) };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.