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