~kosova/+junk/tuxfamily-twiki

« back to all changes in this revision

Viewing changes to foswiki/lib/Foswiki/Configure/Checkers/Site/Locale.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
package Foswiki::Configure::Checkers::Site::Locale;
 
3
use base 'Foswiki::Configure::Checker';
 
4
 
 
5
use strict;
 
6
 
 
7
my @required = (
 
8
 
 
9
);
 
10
 
 
11
sub check {
 
12
    my $this = shift;
 
13
 
 
14
    my $e = '';
 
15
    if ( $Foswiki::cfg{UseLocale} ) {
 
16
        eval "use locale;use POSIX";
 
17
        if ($@) {
 
18
            $Foswiki::cfg{UseLocale} = 0;
 
19
            return $this->WARN( 'Disabling locales. Error was: ' . $@ );
 
20
        }
 
21
        my $locale = $Foswiki::cfg{Site}{Locale};
 
22
        POSIX::setlocale( &POSIX::LC_CTYPE, $locale );
 
23
        my $currentLocale = POSIX::setlocale(&POSIX::LC_CTYPE);
 
24
        if ( $currentLocale ne $locale ) {
 
25
            $e .= $this->WARN(<<HERE);
 
26
Unable to set locale to '$locale'. The actual locale is '$currentLocale'
 
27
- please test your locale settings. This warning can be ignored if you are
 
28
not planning to use locales (e.g. your site uses English only) - or you can
 
29
set  {Site}{Locale} to 'C', which should always work.
 
30
HERE
 
31
        }
 
32
        if ( $locale !~ /[a-z]/i && $Foswiki::cfg{UseLocale} ) {
 
33
            $e = $this->WARN(<<HERE);
 
34
UseLocale set but {Site}{Locale} '$locale' has no alphabetic characters
 
35
HERE
 
36
        }
 
37
    }
 
38
 
 
39
    # Set the default site charset
 
40
    unless ( defined( $Foswiki::cfg{Site}{CharSet} ) ) {
 
41
        $Foswiki::cfg{Site}{CharSet} = 'iso-8859-1';
 
42
    }
 
43
 
 
44
    # Check for unusable multi-byte encodings as site character set
 
45
    # - anything that enables a single ASCII character such as '[' to be
 
46
    # matched within a multi-byte character cannot be used for Foswiki.
 
47
    # Refuse to work with character sets that allow Foswiki syntax
 
48
    # to be recognised within multi-byte characters.
 
49
    # FIXME: match other problematic multi-byte character sets
 
50
    if (   $Foswiki::cfg{UseLocale}
 
51
        && $Foswiki::cfg{Site}{CharSet} =~
 
52
m/^(?:iso-?2022-?|hz-?|gb2312|gbk|gb18030|.*big5|.*shift_?jis|ms.kanji|johab|uhc)/i
 
53
      )
 
54
    {
 
55
 
 
56
        $e .= $this->ERROR(
 
57
            <<HERE
 
58
Cannot use this multi-byte encoding ('$Foswiki::cfg{Site}{CharSet}') as site character
 
59
encoding. Please set a different character encoding in the {Site}{Locale}
 
60
setting.
 
61
HERE
 
62
        );
 
63
    }
 
64
 
 
65
    return $e;
 
66
}
 
67
 
 
68
1;
 
69
__DATA__
 
70
#
 
71
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
 
72
#
 
73
# Copyright (C) 2008 Foswiki Contributors. All Rights Reserved.
 
74
# Foswiki Contributors are listed in the AUTHORS file in the root
 
75
# of this distribution. NOTE: Please extend that file, not this notice.
 
76
#
 
77
# Additional copyrights apply to some or all of the code in this
 
78
# file as follows:
 
79
#
 
80
# Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
 
81
# TWiki Contributors are listed in the AUTHORS file in the root
 
82
# of this distribution. NOTE: Please extend that file, not this notice.
 
83
#
 
84
# This program is free software; you can redistribute it and/or
 
85
# modify it under the terms of the GNU General Public License
 
86
# as published by the Free Software Foundation; either version 2
 
87
# of the License, or (at your option) any later version. For
 
88
# more details read LICENSE in the root of this distribution.
 
89
#
 
90
# This program is distributed in the hope that it will be useful,
 
91
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
92
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
93
#
 
94
# As per the GPL, removal of this notice is prohibited.