New method of translation.
This commit is contained in:
1 parent
220eb6f9ee
commit
45958240f2
4 files changed
+102
No files matched your search
@@ -14,8 +14,10 @@ use Data::Dumper;
|
|||||||
use FindBin qw($Bin);
|
use FindBin qw($Bin);
|
||||||
our $Bin = $Bin;
|
our $Bin = $Bin;
|
||||||
unshift(@INC, "$Bin/../src");
|
unshift(@INC, "$Bin/../src");
|
||||||
|
require API::Std;
|
||||||
#require DB::Flatfile;
|
#require DB::Flatfile;
|
||||||
require Parser::Config;
|
require Parser::Config;
|
||||||
|
require Parser::Lang;
|
||||||
#require Parser::IRC;
|
#require Parser::IRC;
|
||||||
#require IRC::Standard;
|
#require IRC::Standard;
|
||||||
#require Sys::Full;
|
#require Sys::Full;
|
||||||
@@ -30,3 +32,10 @@ use constant {
|
|||||||
|
|
||||||
our $CONF = Parser::Config->new("auto.conf") or print "Failed to open configuration file.\n" and exit;
|
our $CONF = Parser::Config->new("auto.conf") or print "Failed to open configuration file.\n" and exit;
|
||||||
our %SETTINGS = $CONF->parse;
|
our %SETTINGS = $CONF->parse;
|
||||||
|
|
||||||
|
my @lclv = API::Std::conf_get("locale");
|
||||||
|
our $LOCALE = $lclv[0][0];
|
||||||
|
my @lang = split('_', $LOCALE);
|
||||||
|
Parser::Lang::parse($lang[0]) or print ".\n" and exit;
|
||||||
|
undef @lang;
|
||||||
|
undef @lclv;
|
||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
# Auto IRC Bot. An advanced, lightweight and powerful IRC bot.
|
||||||
|
# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS)
|
||||||
|
# This program is free software; rights to this code are stated in doc/LICENSE.
|
||||||
|
|
||||||
|
# English translation file.
|
||||||
|
|
||||||
|
|
||||||
|
# Permission denied - Permission denied
|
||||||
|
msge "Permission_denied" "Permission denied"
|
||||||
|
|
||||||
|
# Access denied - Access denied
|
||||||
|
msge "Access_denied" "Access denied"
|
||||||
|
|
||||||
|
# Not enough parameters - Not enough parameters
|
||||||
|
msge "Not_enough_parameters" "Not enough parameters"
|
||||||
|
|
||||||
|
# Unknown command - Unknown command
|
||||||
|
msge "Unknown_command" "Unknown command"
|
||||||
@@ -11,6 +11,8 @@ package API::Std;
|
|||||||
our @ISA = qw(Exporter);
|
our @ISA = qw(Exporter);
|
||||||
our @EXPORT_OK = qw(conf_get trans);
|
our @EXPORT_OK = qw(conf_get trans);
|
||||||
|
|
||||||
|
my %LANGE;
|
||||||
|
|
||||||
|
|
||||||
# Configuration value getter.
|
# Configuration value getter.
|
||||||
sub conf_get
|
sub conf_get
|
||||||
@@ -49,7 +51,16 @@ sub conf_get
|
|||||||
# Translation subroutine.
|
# Translation subroutine.
|
||||||
sub trans
|
sub trans
|
||||||
{
|
{
|
||||||
|
my ($id) = @_;
|
||||||
|
$id =~ s/ /_/g;
|
||||||
|
|
||||||
|
if (defined $API::Std::LANGE{$id}) {
|
||||||
|
return $API::Std::LANGE{$id};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$id =~ s/_/ /g;
|
||||||
|
return $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
# Auto IRC Bot. An advanced, lightweight and powerful IRC bot.
|
||||||
|
# Copyright (C) 2010-2011 Xelhua Development Team (doc/CREDITS)
|
||||||
|
# This program is free software; rights to this code are stated in doc/LICENSE.
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
# Language file parser.
|
||||||
|
package Parser::Lang;
|
||||||
|
|
||||||
|
|
||||||
|
# Parser.
|
||||||
|
sub parse
|
||||||
|
{
|
||||||
|
my ($lang) = @_;
|
||||||
|
|
||||||
|
# Check that the language file exists.
|
||||||
|
unless (-e "$Auto::Bin/../lang/$lang.alf") {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Open, read and close the file.
|
||||||
|
open ALF, "<$Auto::Bin/../lang/$lang.alf" or return 0;
|
||||||
|
my @fbuf = <ALF>;
|
||||||
|
close ALF;
|
||||||
|
|
||||||
|
# Iterate the file buffer.
|
||||||
|
foreach my $buff (@fbuf) {
|
||||||
|
if (defined $buff) {
|
||||||
|
# Space buffer.
|
||||||
|
my @sbuf = split(' ', $buff);
|
||||||
|
|
||||||
|
# Check for all required values.
|
||||||
|
if (!defined $sbuf[0] or !defined $sbuf[1] or !defined $sbuf[2]) {
|
||||||
|
# Missing a value.
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Make sure the first value is "msge".
|
||||||
|
if ($sbuf[0] ne "msge") {
|
||||||
|
# It isn't.
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $id = $sbuf[1];
|
||||||
|
my $val = $sbuf[2];
|
||||||
|
|
||||||
|
# If the translation is multi-word, continue to parse.
|
||||||
|
if (defined $sbuf[3]) {
|
||||||
|
for (my $i = 3; $i < scalar(@sbuf); $i++) {
|
||||||
|
$val .= " ".$sbuf[$i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Save to memory.
|
||||||
|
$id =~ s/"//g;
|
||||||
|
$val =~ s/"//g;
|
||||||
|
$API::Std::LANGE{$id} = $val;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1;
|
||||||
Reference in new issue
Block a user