-
Notifications
You must be signed in to change notification settings - Fork 38
/
LANGUAGE.pm
143 lines (112 loc) · 4.32 KB
/
LANGUAGE.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# See bottom of file for license and copyright information
package Foswiki::Configure::Checkers::LANGUAGE;
use strict;
use warnings;
use Assert;
require Foswiki::Configure::Checker;
our @ISA = ('Foswiki::Configure::Checker');
=begin TML
---++ ObjectMethod check() -> $checkmsg
This is a generic (item-independent) checker for LANGUAGE items.
These have keys of the form {Languages}{ language }{Enabled}.
=cut
sub check_current_value {
my ( $this, $reporter ) = @_;
return unless ( $Foswiki::cfg{UserInterfaceInternationalisation} );
my $enabled = $this->checkExpandedValue($reporter);
return unless $enabled;
my $dir = $Foswiki::cfg{LocalesDir};
Foswiki::Configure::Load::expandValue($dir);
my $compress = $Foswiki::cfg{LanguageFileCompression};
my $lang = $this->{item}->{keys};
unless ( $lang =~ s/^\{Languages\}\{'?([\w-]+)'?\}\{Enabled\}$/$1/ ) {
die "Invalid item key $lang for LANGUAGE";
}
return $reporter->ERROR("Missing language file $dir/$lang.po")
unless ( -r "$dir/$lang.po" );
if ($compress) {
my $ok = -r "$dir/$lang.mo" && -M "$dir/$lang.po" >= -M "$dir/$lang.mo";
unless ($ok) {
eval("require Locale::Msgfmt;");
if ($@) {
return $reporter->ERROR(
"Locale::Msgfmt can not be loaded, unable to compile strings."
);
}
my $umask =
umask( oct(777) - $Foswiki::cfg{Store}{filePermission} );
eval {
Locale::Msgfmt::msgfmt(
{
in => "$dir/$lang.po",
out => "$dir/$lang.mo",
verbose => 0
, # verbose is not documented, but prints results to STDERR
}
);
};
if ($@) {
$reporter->ERROR(
"Unable to compress strings: compilation failed.");
}
else {
$reporter->NOTE("Successfully compressed strings");
}
umask($umask);
}
}
else {
if ( -f "$dir/$lang.mo" ) {
if ( unlink("$dir/$lang.mo") ) {
$reporter->NOTE("Removed compressed strings");
}
else {
$reporter->ERROR(
"Unable to remove compressed strings in $dir/$lang.mo: $!");
}
}
}
}
=begin TML
---++ ObjectMethod onSave()
This routine is called during the Save wizard, for any key that being
saved, regardless of whether or not it has actually changed. This
is enabled by including the ONSAVE key in the Spec. (In this case it is
automatically enabled by the =Pluggable/LANGUAGES.pm=
This will remove the languages.cache file from the WorkingDir, so that
the cache can be regenerated.
=cut
sub onSave {
my ( $this, $reporter, $key, $val ) = @_;
if ( $Foswiki::cfg{UserInterfaceInternationalisation} ) {
my $dir = $Foswiki::cfg{WorkingDir};
if ( -f "$dir/languages.cache" ) {
if ( unlink("$dir/languages.cache") ) {
$reporter->NOTE("Flushed languages cache");
}
else {
$reporter->ERROR("Failed to remove $dir/languages.cache: $!");
}
}
}
}
1;
__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/
Copyright (C) 2008-2014 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.
Additional copyrights apply to some or all of the code in this
file as follows:
Copyright (C) 2000-2006 TWiki Contributors. All Rights Reserved.
TWiki Contributors are listed in the AUTHORS file in the root
of this distribution. NOTE: Please extend that file, not this notice.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version. For
more details read LICENSE in the root of this distribution.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
As per the GPL, removal of this notice is prohibited.