-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxLang.pm
More file actions
74 lines (55 loc) · 1.11 KB
/
xLang.pm
File metadata and controls
74 lines (55 loc) · 1.11 KB
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
#!/usr/bin/perl
use strict;
use warnings;
use Encode;
use Cwd;
use File::Basename;
package xLang;
our $language = {};
my $default = '';
sub initialize
{
my $directory = Cwd::getcwd() . '/Lang';
opendir (my $dir, $directory)
or return 0;
while (my $file = readdir($dir))
{
my $module = File::Basename::basename($file);
if ($module eq '.' || $module eq '..')
{
next;
}
$module = 'Lang/' . $module;
require $module;
}
closedir($dir);
return 1;
}
sub setDefault
{
$default = shift;
}
sub isValid
{
my $lang = shift;
if (!exists $::language{$lang})
{
return $default;
}
return $lang;
}
sub get
{
my($lang, $index) = @_;
if (!exists $::language{$lang})
{
return xLang::get($default, $index);
}
if (!exists $::language{$lang}{$index})
{
return $index;
}
return Encode::encode_utf8($::language{$lang}{$index});
}
1
__END__