diff options
author | Yorhel <git@yorhel.nl> | 2009-08-14 13:05:59 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-08-17 16:27:14 +0200 |
commit | 4b918796f8d85d40d55dbf2674a2b691d802ff02 (patch) | |
tree | d8247ab322ef03d5ff072a2c329f7e2cb0cd0461 /lib | |
parent | dc9ff373251c7a0f543216173939a8bf02f519be (diff) |
Started on a framework for interface I18N
You can ignore the entries in lang.txt, those are simply for testing
purposes.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/VNDB/Func.pm | 9 | ||||
-rw-r--r-- | lib/VNDB/L10N.pm | 86 |
2 files changed, 94 insertions, 1 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index 4ca20dc5..31a04f8a 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -6,7 +6,7 @@ use warnings; use YAWF ':html'; use Exporter 'import'; use POSIX 'strftime', 'ceil', 'floor'; -our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon tagscore|; +our @EXPORT = qw| shorten age date datestr monthstr userstr bb2html gtintype liststat clearfloat cssicon tagscore mt |; # I would've done this as a #define if this was C... @@ -267,5 +267,12 @@ sub tagscore { } +# short wrapper around maketext() +# (not thread-safe, in the same sense as YAWF::XML. But who cares about threads, anyway?) +sub mt { + return $YAWF::OBJ->{l10n}->maketext(@_); +} + + 1; diff --git a/lib/VNDB/L10N.pm b/lib/VNDB/L10N.pm new file mode 100644 index 00000000..cbf6a239 --- /dev/null +++ b/lib/VNDB/L10N.pm @@ -0,0 +1,86 @@ + +use strict; +use warnings; + +{ + package VNDB::L10N; + use base 'Locale::Maketext'; + + sub fallback_languages { ('en') }; + + # can be called as either a subroutine or a method + sub loadfile { + my %lang = ( + en => \%VNDB::L10N::en::Lexicon, + ru => \%VNDB::L10N::ru::Lexicon, + ); + + open my $F, '<:utf8', $VNDB::ROOT.'/data/lang.txt' or die "Opening language file: $!\n"; + my($empty, $line, $key, $lang) = (0, 0); + while(<$F>) { + chomp; + $line++; + + # ignore intro + if(!defined $key) { + $key = 0 if /^\/intro$/; + next; + } + # ignore comments + next if /^#/; + # key + if(/^:(.+)$/) { + $key = $1; + $lang = undef; + $empty = 0; + next; + } + # locale string + if(/^([a-z_-]{2,7})[ *]: (.+)$/) { + $lang = $1; + die "Unknown language on #$line: $lang\n" if !$lang{$lang}; + die "Unknown key for locale on #$line\n" if !$key; + $lang{$lang}{$key} = $2; + $empty = 0; + next; + } + # multi-line locale string + if($lang && /^\s+([^\s].*)$/) { + $lang{$lang}{$key} .= ''.("\n"x$empty)."\n$1"; + $empty = 0; + next; + } + # empty string (count them in case they're part of a multi-line locale string) + if(/^\s*$/) { + $empty++; + next; + } + # something we didn't expect + die "Don't know what to do with line $line\n"; + } + close $F; + + # dev. + use Data::Dumper 'Dumper'; + warn Dumper \%lang; + } +} + + +{ + package VNDB::L10N::en; + use base 'VNDB::L10N'; + our %Lexicon = ( + _AUTO => 1 + ); +} + +{ + package VNDB::L10N::ru; + use base 'VNDB::L10N::en'; + our %Lexicon; +} + + +1; + |