summaryrefslogtreecommitdiff
path: root/lib/VNDB
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VNDB')
-rw-r--r--lib/VNDB/Func.pm9
-rw-r--r--lib/VNDB/L10N.pm86
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;
+