qw(
js/jquery.js
js/common.js
+ js/namespace.js
),
$self->SUPER::use_javascript(@_);
}
--- /dev/null
+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<len; ++i) {
+ var key = i + 1;
+ var value = params[i];
+ text = text.split("#"+ key).join(value);
+ }
+ }
+ else if( typeof params == 'object' ) {
+ for(var key in params) {
+ var value = params[key];
+ text = text.split("#{"+ key +"}").join(value);
+ }
+ }
+
+ return text;
+ };
+
+ ns.initLocale = function(localeLang) {
+ ns._localeLang = localeLang;
+ };
+
+});
--- /dev/null
+var namespace = (function() {
+ var namespace = function(nsString, callback) {
+ var nsParts = nsString.split(namespace.namespaceDelimiter);
+
+ var ns = namespace.root;
+
+ var len = nsParts.length;
+ for(var i=0; i<len; ++i)
+ {
+ if( !ns[nsParts[i]] )
+ ns[nsParts[i]] = {__namespaceAutoCreated: true};
+
+ ns = ns[nsParts[i]];
+ }
+
+ if( callback )
+ {
+ var nsExt = callback.call(ns, ns);
+
+ if( nsExt )
+ {
+ if( !ns )
+ ns = {};
+
+ for(var key in nsExt)
+ ns[key] = nsExt[key];
+ }
+
+ ns.__namespaceAutoCreated = false;
+ }
+ else if( namespace.loadNamespace && ns.__namespaceAutoCreated )
+ {
+ var url;
+
+ var len = namespace.namespaceLocations.length;
+ for(var i=0; i<len; ++i)
+ {
+ var entry = namespace.namespaceLocations[i];
+ if( nsString.indexOf(entry.namespace) === 0 )
+ {
+ url = entry.location;
+ break;
+ }
+ }
+
+ url += "/"+ nsString +".js";
+
+ jQuery.ajax({
+ url: url,
+ async: false,
+ dataType: "text",
+ success: function(res) {
+ eval(res);
+ /*
+ var script = window.document.createElement("script");
+ script.type = "text/javascript";
+ script.text = res;
+ window.document.body.appendChild(script);
+ */
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ alert(textStatus +": "+ errorThrown);
+ },
+ });
+ }
+
+ return ns;
+ };
+
+ return namespace;
+})();
+
+window.namespaceRoot = {};
+namespace.root = window.namespaceRoot;
+namespace.namespaceDelimiter = ".";
+namespace.namespaceLocations = [{namespace: "", location: "js"}];
+namespace.loadNamespace = true;
my $dbupdir = "$basedir/sql/Pg-upgrade";
my $dbupdir2 = "$basedir/sql/Pg-upgrade2";
my $menufile = "menu.ini";
+my @javascript_dirs = ($basedir .'/js', $basedir .'/templates/webpages');
my $submitsearch = qr/type\s*=\s*[\"\']?submit/i;
our $self = {};
our $missing = {};
our @lost = ();
-my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit);
+my (%referenced_html_files, %locale, %htmllocale, %alllocales, %cached, %submit, %jslocale);
my ($ALL_HEADER, $MISSING_HEADER, $LOST_HEADER);
init();
handle_file($_, $dbupdir2) for @dbplfiles2;
scanmenu($_) for @menufiles;
+for my $file_name (map({find_files($_)} @javascript_dirs)) {
+ scan_javascript_file($file_name);
+}
+
# merge entries to translate with entries from files 'missing' and 'lost'
merge_texts();
data_sub => 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}) {
while ($rc) {
if (/Locale/) {
unless (/^use /) {
- my ($null, $country) = split /,/;
+ my ($null, $country) = split(/,/);
$country =~ s/^ +[\"\']//;
$country =~ s/[\"\'].*//;
}
$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*
+ ([\'\"])
+ (.*?)
+ (?<!\\)\1
+ /ixg )
+ {
+ my $text = unescape_template_string($2);
+
+ $jslocale{$text} = 1;
+ $alllocales{$text} = 1;
+ }
+ }
+
+ close($fh);
+}
sub search_unused_htmlfiles {
my @unscanned_dirs = ('../../templates/webpages');
return "'" . $val . "'";
}
+sub _double_quote {
+ my $val = shift;
+ $val =~ s/(\"|\\$)/\\$1/g;
+ return '"'. $val .'"';
+}
+
sub _print_line {
my $key = _single_quote(shift);
my $text = _single_quote(shift);