refactoring

optimize imports
reformat source code
remove unused cpu and memory log functionality
This commit is contained in:
Milan
2018-08-29 00:10:15 +02:00
parent c37c71f29e
commit 05b1251c1a
81 changed files with 9242 additions and 9962 deletions

View File

@@ -1,15 +1,15 @@
package localization;
package localization;
use warnings "all";
use strict;
use Data::Dumper;
use uac;
use user_settings;
use uac();
use user_settings();
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(get getJavascript);
our %EXPORT_TAGS = ( 'all' => [ @EXPORT_OK ] );
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(get getJavascript);
our %EXPORT_TAGS = ( 'all' => [@EXPORT_OK] );
sub debug;
@@ -18,93 +18,98 @@ sub debug;
# language : get for selected language
# user : get from user settings
# loc : add to existing localization, optional
sub get{
my $config =shift;
my $options=shift;
sub get {
my $config = shift;
my $options = shift;
#print STDERR Dumper($options);
#print STDERR Dumper($options);
#get pot file
unless (defined $options->{file}){
print STDERR "missing po file\n";
return $options->{loc}||{};
}
#get pot file
unless ( defined $options->{file} ) {
print STDERR "missing po file\n";
return $options->{loc} || {};
}
my $language=undef;
#get language from options
$language=$options->{language} if (defined $options->{language});
my $language = undef;
#get language from user
if ( (!(defined $language)) && (defined $options->{user})){
my $user_settings=user_settings::get($config, {user=>$options->{user}});
$language=$user_settings->{language};
}
$language='en' unless defined $language;
$language='en' unless $language eq 'de';
#get language from options
$language = $options->{language} if ( defined $options->{language} );
my $loc={};
$loc=$options->{loc} if defined $options->{loc};
#get language from user
if ( ( !( defined $language ) ) && ( defined $options->{user} ) ) {
my $user_settings = user_settings::get( $config, { user => $options->{user} } );
$language = $user_settings->{language};
}
$language = 'en' unless defined $language;
$language = 'en' unless $language eq 'de';
my $files=$options->{file};
$files=~s/[^a-zA-Z\,\_\-]//g;
#get all comma separated po files
for my $file (split/\,/,$files){
#read default language
#my $po_file=$config->{locations}->{admin_pot_dir}.'/en/'.$file.'.po';
#$loc=read_po_file($po_file, $loc);
my $loc = {};
$loc = $options->{loc} if defined $options->{loc};
#read selected language
#if($language ne 'en'){
my $po_file=$config->{locations}->{admin_pot_dir}.'/'.$language.'/'.$file.'.po';
$loc=read_po_file($po_file, $loc);
#}
}
return $loc;
my $files = $options->{file};
$files =~ s/[^a-zA-Z\,\_\-]//g;
#get all comma separated po files
for my $file ( split /\,/, $files ) {
#read default language
#my $po_file=$config->{locations}->{admin_pot_dir}.'/en/'.$file.'.po';
#$loc=read_po_file($po_file, $loc);
#read selected language
#if($language ne 'en'){
my $po_file = $config->{locations}->{admin_pot_dir} . '/' . $language . '/' . $file . '.po';
$loc = read_po_file( $po_file, $loc );
#}
}
return $loc;
}
sub read_po_file{
my $po_file=shift;
my $loc =shift;
sub read_po_file {
my $po_file = shift;
my $loc = shift;
unless (-e $po_file){
print STDERR "po file $po_file does not exist\n";
return $loc;
}
unless (-r $po_file){
print STDERR "cannot read po file $po_file\n";
return $loc;
}
my $key='';
open my $file, '<:encoding(UTF-8)', $po_file;
while (<$file>){
my $line=$_;
#print STDERR $line;
if ($line=~/^msgid\s*\"(.*)\"\s*$/){
$key=$1;
$key=~s/\'//g;
$key=~s/\"//g;
}
if ($line=~/^msgstr\s*\"(.*)\"\s*$/){
my $val=$1;
$val=~s/\'//g;
$val=~s/\"//g;
$loc->{$key}=$val;
}
}
return $loc;
unless ( -e $po_file ) {
print STDERR "po file $po_file does not exist\n";
return $loc;
}
unless ( -r $po_file ) {
print STDERR "cannot read po file $po_file\n";
return $loc;
}
my $key = '';
open my $file, '<:encoding(UTF-8)', $po_file;
while (<$file>) {
my $line = $_;
#print STDERR $line;
if ( $line =~ /^msgid\s*\"(.*)\"\s*$/ ) {
$key = $1;
$key =~ s/\'//g;
$key =~ s/\"//g;
}
if ( $line =~ /^msgstr\s*\"(.*)\"\s*$/ ) {
my $val = $1;
$val =~ s/\'//g;
$val =~ s/\"//g;
$loc->{$key} = $val;
}
}
return $loc;
}
sub getJavascript{
my $loc=shift;
sub getJavascript {
my $loc = shift;
my $out='<script>';
$out.="var loc={};\n";
for my $key (sort keys %$loc){
$out.=qq{loc['$key']='$loc->{$key}';}."\n";
}
$out.="</script>\n";
return $out;
my $out = '<script>';
$out .= "var loc={};\n";
for my $key ( sort keys %$loc ) {
$out .= qq{loc['$key']='$loc->{$key}';} . "\n";
}
$out .= "</script>\n";
return $out;
}
1;