summaryrefslogtreecommitdiff
path: root/LedgerSMB
diff options
context:
space:
mode:
authortetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-28 01:21:21 +0000
committertetragon <tetragon@4979c152-3d1c-0410-bac9-87ea11338e46>2006-11-28 01:21:21 +0000
commit72c5ed68eebe56378a17dec99dec9b76e050ac67 (patch)
tree1ba7dd14c57ac3fd485066db393daeba28a2ae07 /LedgerSMB
parente75e42e423e167157228bc5bc2960e4380263e81 (diff)
Updating Danish locale with Num2text rules from Mads Kiilerich
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@699 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB')
-rwxr-xr-xLedgerSMB/Num2text.pm96
1 files changed, 95 insertions, 1 deletions
diff --git a/LedgerSMB/Num2text.pm b/LedgerSMB/Num2text.pm
index 74ed8a4a..8382df5c 100755
--- a/LedgerSMB/Num2text.pm
+++ b/LedgerSMB/Num2text.pm
@@ -31,6 +31,14 @@
#
#=====================================================================
+# The conversion routines can be tested with for example:
+# perl <<EOF
+# use LedgerSMB::CP;
+# my $c = CP->new('da');
+# $c->init;
+# for(0 .. 202, 999 .. 1002, 1999 .. 2002, 999999 .. 1000002, 999999999 .. 1000000002)
+# {print $_.":".$c->num2text($_)."\n";};'
+# EOF
sub init {
my $self = shift;
@@ -38,7 +46,7 @@ sub init {
my $langtag = substr($locale->language_tag, 0, 2);
$self->{'numrules'} = 'en';
$self->{'numrules'} = $langtag if
- grep {/$langtag/} (qw/ca de es et fr hu it nl ru/);
+ grep {/$langtag/} (qw/ca de es et fr hu it nl ru da/);
$self->{'numrules'} = 'es' if $self->{'numrules'} eq 'ca';
$self->{'numrules'} = 'de' if $self->{'numrules'} eq 'ru';
@@ -106,6 +114,7 @@ sub num2text {
return $self->num2text_et($amount) if $self->{'numrules'} eq 'et';
return $self->num2text_fr($amount) if $self->{'numrules'} eq 'fr';
return $self->num2text_it($amount) if $self->{'numrules'} eq 'it';
+ return $self->num2text_da($amount) if $self->{'numrules'} eq 'da';
return $self->num2text_en($amount);
}
@@ -929,5 +938,90 @@ sub format_ten_it {
}
+# A special (swedish-like) spelling of danish check numbers
+sub num2text_da {
+ my ($self, $amount) = @_;
+
+ # Handle 0
+ return $self->{numbername}{0} unless $amount;
+
+ # List of collected digits
+ my @textnumber = ();
+
+ # split amount into chunks of 3
+ my @num = reverse split //, abs($amount);
+ my @numblock = ();
+ my @a = ();
+ while (@num) {
+ @a = ();
+ for (1 .. 3) {
+ push @a, shift @num;
+ }
+ push @numblock, join / /, reverse @a;
+ }
+
+ my $i;
+ my $bigplural;
+ while (@numblock) {
+ $i = $#numblock;
+ $numblock[$i] *= 1;
+
+ if ($numblock[$i] == 0) {
+ pop @numblock;
+ next;
+ }
+
+ # Plural suffix "er" for million and up, not for tusinde
+ $bigpluralsuffix = "";
+ $bigpluralsuffix = "er" if ($i > 1 && $numblock[$i] > 1);
+
+ if ($numblock[$i] > 99) {
+ @num = split //, $numblock[$i];
+
+ # the one from hundreds
+ push @textnumber, $self->{numbername}{$num[0]};
+
+ # add hundred designation
+ push @textnumber, $self->{numbername}{100};
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 100;
+ }
+
+ if ($numblock[$i] > 9) {
+ @num = split //, $numblock[$i];
+
+ # the one from tens
+ push @textnumber, $self->{numbername}{$num[0]};
+
+ # add ten designation
+ push @textnumber, $self->{numbername}{10};
+
+ # reduce numblock
+ $numblock[$i] -= $num[0] * 10;
+ }
+
+ if ($numblock[$i] > 0) {
+ # the ones left in the block
+ if($numblock[$i] == 1 && $i != 1) {
+ push @textnumber, $self->{numbername}{'1o'}; # Special case for "Et" tusinde
+ } else {
+ push @textnumber, $self->{numbername}{$numblock[$i]};
+ }
+ }
+
+ # add thousand, million, etc
+ if ($i) {
+ $amount = 10**($i * 3);
+ push @textnumber, $self->{numbername}{$amount}.$bigpluralsuffix;
+ }
+
+ pop @numblock;
+ }
+
+ join '', @textnumber;
+
+}
+
1;