~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/I18N/Fallback.pm

  • Committer: James Michael DuPont
  • Date: 2009-07-18 19:58:49 UTC
  • Revision ID: jamesmikedupont@gmail.com-20090718195849-vgbmaht2ys791uo2
added foswiki

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# See bottom of file for license and copyright information
 
2
# Foswiki::I18N::Fallback - a fallback class for when
 
3
# Locale::Maketext isn't available.
 
4
 
 
5
package Foswiki::I18N::Fallback;
 
6
use base 'Foswiki::I18N';
 
7
 
 
8
sub new {
 
9
    my $class = shift;
 
10
    my $this = bless( {}, $class );
 
11
    return $this;
 
12
}
 
13
 
 
14
sub finish {
 
15
 
 
16
    # No data, nothing to do.
 
17
    # Must call SUPER finish to avoid memory leaks
 
18
    my $this = shift;
 
19
    $this->SUPER::finish(@_);
 
20
}
 
21
 
 
22
sub maketext {
 
23
    my ( $this, $text, @args ) = @_;
 
24
 
 
25
    return '' unless $text;
 
26
 
 
27
    # substitute parameters:
 
28
    $text =~ s/\[\_(\d+)\]/$args[$1-1]/ge;
 
29
 
 
30
    # unescape escaped square brackets:
 
31
    $text =~ s/~(\[|\])/$1/g;
 
32
 
 
33
    #plurals:
 
34
    $text =~
 
35
      s/\[\*,\_(\d+),([^,]+)(,([^,]+))?\]/_handlePlurals($args[$1-1],$2,$4)/ge;
 
36
 
 
37
    return $text;
 
38
}
 
39
 
 
40
sub _handlePlurals {
 
41
    my ( $number, $singular, $plural ) = @_;
 
42
 
 
43
    # bad hack, but Locale::Maketext does it the same way ;)
 
44
    return
 
45
      $number . ' '
 
46
      . ( ( $number == 1 )
 
47
        ? $singular
 
48
        : ( $plural ? ($plural) : ( $singular . 's' ) ) );
 
49
}
 
50
 
 
51
sub language {
 
52
    return 'en';
 
53
}
 
54
 
 
55
sub enabled_languages {
 
56
    my $this = shift;
 
57
    return $this->{enabled_languages};
 
58
}
 
59
 
 
60
sub fromSiteCharSet {
 
61
    my ( $this, $text ) = @_;
 
62
    return $text;
 
63
}
 
64
 
 
65
sub toSiteCharSet {
 
66
    my ( $this, $text ) = @_;
 
67
    return $text;
 
68
}
 
69
 
 
70
1;
 
71
__DATA__
 
72
# Module of Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
73
#
 
74
# Copyright (C) 2008-2009 Foswiki Contributors. All Rights Reserved.
 
75
# Foswiki Contributors are listed in the AUTHORS file in the root
 
76
# of this distribution. NOTE: Please extend that file, not this notice.
 
77
#
 
78
# Additional copyrights apply to some or all of the code in this
 
79
# file as follows:
 
80
#
 
81
# Copyright (C) 1999-2007 TWiki Contributors. All Rights Reserved.
 
82
# TWiki Contributors are listed in the AUTHORS file in the root
 
83
# of this distribution. NOTE: Please extend that file, not this notice.
 
84
#
 
85
# This program is free software; you can redistribute it and/or
 
86
# modify it under the terms of the GNU General Public License
 
87
# as published by the Free Software Foundation; either version 2
 
88
# of the License, or (at your option) any later version. For
 
89
# more details read LICENSE in the root of this distribution.
 
90
#
 
91
# This program is distributed in the hope that it will be useful,
 
92
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
93
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
94
#
 
95
# As per the GPL, removal of this notice is prohibited.