From 224291ddfd1633e2e3a47632cca24c1039fcb105 Mon Sep 17 00:00:00 2001 From: Thomas Heck Date: Wed, 27 Feb 2013 14:06:27 +0100 Subject: [PATCH] =?utf8?q?scripts/locales.pl=20um=20JS-=C3=9Cbersetzung=20?= =?utf8?q?erweitert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Layout/None.pm | 1 + js/kivi.js | 48 +++++++++++++++++++++++++++++ js/namespace.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++ locale/de/js.js | 2 ++ scripts/locales.pl | 50 ++++++++++++++++++++++++++++-- 5 files changed, 176 insertions(+), 2 deletions(-) create mode 100644 js/kivi.js create mode 100644 js/namespace.js create mode 100644 locale/de/js.js diff --git a/SL/Layout/None.pm b/SL/Layout/None.pm index 50ab2f854..25ea9161a 100644 --- a/SL/Layout/None.pm +++ b/SL/Layout/None.pm @@ -13,6 +13,7 @@ sub use_javascript { qw( js/jquery.js js/common.js + js/namespace.js ), $self->SUPER::use_javascript(@_); } diff --git a/js/kivi.js b/js/kivi.js new file mode 100644 index 000000000..db9904b53 --- /dev/null +++ b/js/kivi.js @@ -0,0 +1,48 @@ +namespace("kivi", function(ns) { + + ns._localeLang = false; + ns._locales = {}; + + ns.t8 = function(text, params) { + if( ns._localeLang ) { + if( !ns._locales[ns._localeLang] ) { + jQuery.ajax({ + url: "locale/"+ ns._localeLang +"/js.js", + async: false, + dataType: "json", + success: function(res) { + ns._locales[ns._localeLang] = res; + }, + error: function(xhr, textStatus, errorThrown) { + alert(textStatus +": "+ errorThrown); + }, + }); + } + + text = ns._locales[ns._localeLang][text] || text; + } + + if( Object.prototype.toString.call( params ) === '[object Array]' ) { + var len = params.length; + + for(var i=0; i sub { _print_line($_, $self->{texts}{$_}, @_) for sort keys %alllocales }, ); +open(my $js_file, '>:encoding(utf8)', $locales_dir .'/js.js') || die; +print $js_file '{'."\n"; +my $first_entry = 1; +for my $key (sort(keys(%jslocale))) { + print $js_file (!$first_entry ? ',' : '') . _double_quote($key) .':'. _double_quote($self->{texts}{$key}) ."\n"; + $first_entry = 0; +} +print $js_file '}'."\n"; +close($js_file); + foreach my $text (keys %$missing) { if ($locale{$text} || $htmllocale{$text}) { unless ($self->{texts}{$text}) { @@ -385,7 +400,7 @@ sub scanfile { while ($rc) { if (/Locale/) { unless (/^use /) { - my ($null, $country) = split /,/; + my ($null, $country) = split(/,/); $country =~ s/^ +[\"\']//; $country =~ s/[\"\'].*//; } @@ -577,6 +592,31 @@ sub scanhtmlfile { $referenced_html_files{$_} = 1 for keys %{$cached{$file}{scanh}}; } +sub scan_javascript_file { + my ($file) = @_; + + open(my $fh, $file) || die('can not open file: '. $file); + + while( my $line = readline($fh) ) { + while( $line =~ m/ + kivi.t8 + \s* + \( + \s* + ([\'\"]) + (.*?) + (?