Skip to content

Commit

Permalink
Item9697: implement Enhancei18nArchitecture
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/trunk@14959 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed Jun 11, 2012
1 parent 7b2e8da commit c0b3ecb
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions core/lib/Foswiki/I18N.pm
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@ sub _normalize_language_tag {
return $tag;
}

sub _loadLexicon {
my ( $lang, $dir ) = @_;

$dir ||= $Foswiki::cfg{LocalesDir};

my $langFile = "$dir/$lang.po";

#print STDERR "langFile=$langFile\n";

# Use the compressed version if it exists
if ( $langFile =~ m/^(.*)\.po$/
&& -f "$1.mo" )
{
$langFile = "$1.mo";
}
if ( -f $langFile ) {
unless (
eval {
Locale::Maketext::Lexicon->import(
{ $lang => [ Gettext => $langFile ] } );
1;
}
)
{
push( @initErrors, "I18N - Error loading language $lang: $@\n" );
}
}
}

# initialisation block
BEGIN {

Expand Down Expand Up @@ -98,33 +127,15 @@ BEGIN {
. "Install Locale::Maketext::Lexicon or turn off {UserInterfaceInternationalisation}"
);
}
foreach my $lang (@languages) {
my $langFile = "$Foswiki::cfg{LocalesDir}/$lang.po";

# Use the compressed version if it exists
if ( $langFile =~ m/^(.*)\.po$/
&& -f "$1.mo" )
{
$langFile = "$1.mo";
}
if ( -f $langFile ) {
unless (
eval {
Locale::Maketext::Lexicon->import(
{ $lang => [ Gettext => $langFile ] } );
1;
}
)
{
push( @initErrors,
"I18N - Error loading language $lang: $@\n" );
}
}
else {
push( @initErrors,
"I18N - Ignoring enabled language $lang as $langFile does not exist.\n"
);
}
opendir( my $dh, "$Foswiki::cfg{LocalesDir}/" ) || next;
my @subDirs =
grep { !/^\./ && -d "$Foswiki::cfg{LocalesDir}/$_" } readdir $dh;
closedir $dh;

foreach my $lang (@languages) {
_loadLexicon($lang);
_loadLexicon( $lang, "$Foswiki::cfg{LocalesDir}/$_" ) foreach @subDirs;
}
}

Expand Down

0 comments on commit c0b3ecb

Please sign in to comment.