lib/TWiki/Configure/Checkers/UseLocale.pm
author Colas Nahaboo <colas@nahaboo.net>
Sat, 26 Jan 2008 15:50:53 +0100
changeset 0 414e01d06fd5
child 1 e2915a7cbdfa
permissions -rw-r--r--
RELEASE 4.2.0 freetown
colas@0
     1
#
colas@0
     2
# TWiki Enterprise Collaboration Platform, http://TWiki.org/
colas@0
     3
#
colas@0
     4
# Copyright (C) 2000-2006 TWiki Contributors.
colas@0
     5
#
colas@0
     6
# This program is free software; you can redistribute it and/or
colas@0
     7
# modify it under the terms of the GNU General Public License
colas@0
     8
# as published by the Free Software Foundation; either version 2
colas@0
     9
# of the License, or (at your option) any later version. For
colas@0
    10
# more details read LICENSE in the root of this distribution.
colas@0
    11
#
colas@0
    12
# This program is distributed in the hope that it will be useful,
colas@0
    13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
colas@0
    14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
colas@0
    15
#
colas@0
    16
# As per the GPL, removal of this notice is prohibited.
colas@0
    17
package TWiki::Configure::Checkers::UseLocale;
colas@0
    18
colas@0
    19
use strict;
colas@0
    20
colas@0
    21
use TWiki::Configure::Checker;
colas@0
    22
colas@0
    23
use base 'TWiki::Configure::Checker';
colas@0
    24
colas@0
    25
my @required = (
colas@0
    26
    {
colas@0
    27
        name => 'Locale::Maketext::Lexicon',
colas@0
    28
        usage => 'I18N translations',
colas@0
    29
    },
colas@0
    30
    {
colas@0
    31
        name => 'locale',
colas@0
    32
        usage => "Standard Perl locales module",
colas@0
    33
        requiredVersion => 1,
colas@0
    34
    },
colas@0
    35
    {
colas@0
    36
        name => 'POSIX',
colas@0
    37
        usage => "Standard Perl POSIX module",
colas@0
    38
        requiredVersion => 1,
colas@0
    39
    },
colas@0
    40
   );
colas@0
    41
colas@0
    42
my @perl56 = (
colas@0
    43
    {
colas@0
    44
        name => 'Unicode::String',
colas@0
    45
        usage => 'I18N conversions',
colas@0
    46
        requiredVersion => 1,
colas@0
    47
    },
colas@0
    48
    {
colas@0
    49
        name => 'Unicode::MapUTF8',
colas@0
    50
        usage => "I18N conversions",
colas@0
    51
        requiredVersion => 1,
colas@0
    52
    },
colas@0
    53
    {
colas@0
    54
        name => 'Unicode::Map',
colas@0
    55
        usage => "I18N conversions",
colas@0
    56
        requiredVersion => 1,
colas@0
    57
    },
colas@0
    58
    {
colas@0
    59
        name => 'Unicode::Map8',
colas@0
    60
        usage => "I18N conversions",
colas@0
    61
        requiredVersion => 1,
colas@0
    62
    },
colas@0
    63
    {
colas@0
    64
        name => 'Jcode',
colas@0
    65
        usage => "I18N conversions",
colas@0
    66
        requiredVersion => 1,
colas@0
    67
    },
colas@0
    68
   );
colas@0
    69
colas@0
    70
my @perl58 = (
colas@0
    71
    {
colas@0
    72
        name => 'Encode',
colas@0
    73
        usage => "I18N conversions (core module in Perl 5.8)",
colas@0
    74
        requiredVersion => 1,
colas@0
    75
    },
colas@0
    76
    {
colas@0
    77
        name => 'Unicode::Normalize',
colas@0
    78
        usage => "I18N conversions (Replace 8-bit chars in uploaded files by US-ASCII equivalents)",
colas@0
    79
        requiredVersion => 1,
colas@0
    80
    },
colas@0
    81
   );
colas@0
    82
colas@0
    83
sub check {
colas@0
    84
    my $this = shift;
colas@0
    85
colas@0
    86
    return '' unless $TWiki::cfg{UseLocale};
colas@0
    87
colas@0
    88
    my $n = $this->checkPerlModules( \@required );
colas@0
    89
colas@0
    90
    if ($] >= 5.008) {
colas@0
    91
        $n .= $this->checkPerlModules( \@perl56 );
colas@0
    92
    } else {
colas@0
    93
        $n .= $this->checkPerlModules( \@perl58 );
colas@0
    94
    }
colas@0
    95
colas@0
    96
    if( $TWiki::cfg{OS} eq 'WINDOWS' ) {
colas@0
    97
        # Warn re known broken locale setup
colas@0
    98
        $n .= $this->WARN(<<HERE
colas@0
    99
Using Perl on Windows, which may have missing or incorrect locales (in Cygwin
colas@0
   100
or ActiveState Perl, respectively) - turning off {Site}{LocaleRegexes} is
colas@0
   101
recommended unless you know your version of Perl has working locale support.
colas@0
   102
HERE
colas@0
   103
                  );
colas@0
   104
    }
colas@0
   105
colas@0
   106
    # Warn against Perl 5.6 or lower for UTF-8
colas@0
   107
    if ( $] < 5.008 ) {
colas@0
   108
        $n .= $this->WARN("Perl 5.8 is required if you are using TWiki's",
colas@0
   109
                   "experimental UTF-8 support\n");
colas@0
   110
    }
colas@0
   111
colas@0
   112
    # Check for 'useperlio' in Config on Perl 5.8 or higher - required
colas@0
   113
    # for use of ':utf8' layer.
colas@0
   114
    if ( $] >= 5.008 and 
colas@0
   115
         not ( exists $Config::Config{useperlio} and
colas@0
   116
               $Config::Config{useperlio} eq 'define' ) ) {
colas@0
   117
        $n .= $this->WARN(<<HERE
colas@0
   118
This version of Perl was not compiled to use PerlIO by default ('useperlio'
colas@0
   119
not set in Config.pm, see <i>Perl's Unicode Model</i> in 'perldoc
colas@0
   120
perluniintro') - re-compilation of Perl will be required before it can be
colas@0
   121
used to enable TWiki's experimental UTF-8 support.
colas@0
   122
HERE
colas@0
   123
                  );
colas@0
   124
    }
colas@0
   125
colas@0
   126
    # Check for d_setlocale in Config (same as 'perl -V:d_setlocale')
colas@0
   127
    eval "use Config";
colas@0
   128
    if ( !( exists $Config::Config{d_setlocale} &&
colas@0
   129
            $Config::Config{d_setlocale} eq 'define' ) ) {
colas@0
   130
        $n .= $this->WARN(<<HERE
colas@0
   131
This version of Perl was not compiled with locale support ('d_setlocale' not
colas@0
   132
set in Config.pm) - re-compilation of Perl will be required before it can be
colas@0
   133
used to support TWiki internationalisation.
colas@0
   134
HERE
colas@0
   135
                  );
colas@0
   136
    }
colas@0
   137
    return $n;
colas@0
   138
}
colas@0
   139
colas@0
   140
1;