From 56aefde186c4eba2ddd34017980d35683985417a Mon Sep 17 00:00:00 2001 From: tetragon Date: Mon, 23 Oct 2006 20:14:15 +0000 Subject: Convert locales to Locale::Maketext::Lexicon git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@264 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB/Form.pm | 108 --------------------------- LedgerSMB/Locale.pm | 134 ++++++++++++++++++++++++++++++++++ bin/admin.pl | 7 +- bin/am.pl | 1 - bin/login.pl | 7 +- bin/oe.pl | 6 +- locale/mo/en/LC_MESSAGES/LedgerSMB.mo | Bin 0 -> 184 bytes locale/po/en.po | 8 ++ menu.pl | 12 ++- 9 files changed, 166 insertions(+), 117 deletions(-) create mode 100644 LedgerSMB/Locale.pm create mode 100644 locale/mo/en/LC_MESSAGES/LedgerSMB.mo create mode 100644 locale/po/en.po diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index deb374d2..b42f68bb 100755 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -3110,112 +3110,4 @@ sub audittrail { $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; diff --git a/LedgerSMB/Locale.pm b/LedgerSMB/Locale.pm new file mode 100644 index 00000000..80e2043e --- /dev/null +++ b/LedgerSMB/Locale.pm @@ -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; + diff --git a/bin/admin.pl b/bin/admin.pl index deac8655..ce96cd6e 100755 --- a/bin/admin.pl +++ b/bin/admin.pl @@ -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 ($@); diff --git a/bin/am.pl b/bin/am.pl index 76506f71..cdc5959e 100755 --- a/bin/am.pl +++ b/bin/am.pl @@ -2050,7 +2050,6 @@ sub config { foreach $key (sort { $countrycodes{$a} cmp $countrycodes{$b} } keys %countrycodes) { $countrycodes .= ($myconfig{countrycode} eq $key) ? "