From 1e1712f9b4b5d8aab04f88f4981ab3e57507df40 Mon Sep 17 00:00:00 2001 From: George Clark Date: Tue, 6 Sep 2016 11:53:58 -0400 Subject: [PATCH 1/2] Item13897: Locale typo - spelled Local This needs some review. Even with this change, I cannot get core/tools/xgettext to run. Initially it was failing with unknown package Local::Maketext. Now it has an issue with the catch clause. I think it's missing Try::Tiny, but then it fails with undefined $app, so not sure where to go from here. Fails now with: Missing required arguments: app at (eval 61) line 36. --- core/lib/Foswiki/I18N.pm | 2 +- core/lib/Foswiki/I18N/Extract.pm | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/lib/Foswiki/I18N.pm b/core/lib/Foswiki/I18N.pm index 424576fe8c..8c117340cc 100644 --- a/core/lib/Foswiki/I18N.pm +++ b/core/lib/Foswiki/I18N.pm @@ -237,7 +237,7 @@ around BUILDARGS => sub { Constructor. Gets the language object corresponding to the current users language. If $app is not a Foswiki::App object reference, just calls -Local::Maketext::new (the superclass constructor) +Locale::Maketext::new (the superclass constructor) =cut diff --git a/core/lib/Foswiki/I18N/Extract.pm b/core/lib/Foswiki/I18N/Extract.pm index 927ce402d3..d9e331fe70 100644 --- a/core/lib/Foswiki/I18N/Extract.pm +++ b/core/lib/Foswiki/I18N/Extract.pm @@ -12,6 +12,9 @@ Depends on Locale::Maketext::Extract (part of CPAN::Locale::Maketext::Lexicon). package Foswiki::I18N::Extract; use v5.14; +use Assert; +use Try::Tiny; + use Moo; extends qw(Foswiki::Object); with qw(Foswiki::AppObject); @@ -58,7 +61,7 @@ around BUILDARGS => sub { my $orig = shift; try { - Foswiki::load_package('Local::Maketext::Extract'); + Foswiki::load_package('Locale::Maketext::Extract'); } catch { $initError = ref($_) ? $_->stringify : $_; From 883e7cb2ae207df6b817710d1f9f33c20b4c8247 Mon Sep 17 00:00:00 2001 From: Vadim Belman Date: Tue, 6 Sep 2016 12:58:22 -0400 Subject: [PATCH 2/2] Item13897: Fixed xgettext to work with OO model. - CLI engine checks for action validity and enforces 'view' if action wasn't found in the SwitchBoard. --- core/lib/Foswiki/App.pm | 5 +---- core/lib/Foswiki/Engine/CLI.pm | 5 +++-- core/lib/Foswiki/I18N/Extract.pm | 3 +-- core/tools/xgettext | 18 ++++++++++++++++-- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/core/lib/Foswiki/App.pm b/core/lib/Foswiki/App.pm index 2f93f7d75f..1b14636c16 100644 --- a/core/lib/Foswiki/App.pm +++ b/core/lib/Foswiki/App.pm @@ -1503,10 +1503,7 @@ sub _prepareDispatcher { status => 404, header => 'Not Found', text => 'The requested URL ' - . ( - $this->engine->request->uri - // 'action:' . $this->engine->pathData->{action} - ) + . ( $this->request->uri // 'action:' . $this->request->action ) . ' was not found on this server.', ); } diff --git a/core/lib/Foswiki/Engine/CLI.pm b/core/lib/Foswiki/Engine/CLI.pm index 5c6dee30ef..76af0c044f 100644 --- a/core/lib/Foswiki/Engine/CLI.pm +++ b/core/lib/Foswiki/Engine/CLI.pm @@ -20,8 +20,7 @@ use Foswiki::Request (); use Foswiki::Request::Upload (); use Foswiki::Response (); -use Moo; -use namespace::clean; +use Foswiki::Class; extends qw(Foswiki::Engine); use constant HTTP_COMPLIANT => 0; @@ -123,6 +122,8 @@ around _preparePath => sub { $path_info = $this->pathInfo; $this->clear_pathInfo; } + $action = 'view' + unless defined $this->app->cfg->data->{SwitchBoard}{$action}; return { action => $action, path_info => $path_info, diff --git a/core/lib/Foswiki/I18N/Extract.pm b/core/lib/Foswiki/I18N/Extract.pm index d9e331fe70..8d3d5046ec 100644 --- a/core/lib/Foswiki/I18N/Extract.pm +++ b/core/lib/Foswiki/I18N/Extract.pm @@ -15,9 +15,8 @@ use v5.14; use Assert; use Try::Tiny; -use Moo; +use Foswiki::Class qw(app); extends qw(Foswiki::Object); -with qw(Foswiki::AppObject); our $initError; diff --git a/core/tools/xgettext b/core/tools/xgettext index 654ab8b947..2c8f3cc014 100755 --- a/core/tools/xgettext +++ b/core/tools/xgettext @@ -3,6 +3,7 @@ # Script to extract strings from Foswiki sources and templates use strict; +use v5.14; # force the use from the root -d 'core' @@ -11,7 +12,12 @@ use strict; ); use File::Spec; +use Try::Tiny; +use Foswiki::App (); +use Foswiki::Exception (); + +$ENV{PATH}; my $cwd = `pwd`; chomp($cwd); unshift( @INC, File::Spec->catfile( $cwd, 'core/lib' ) ); @@ -80,7 +86,9 @@ sub extract { my ( $target, @sources ) = @_; print "I: Extracting strings into $target.\n"; - my $extractor = new Foswiki::I18N::Extract; + local %ENV = %ENV; + my $app = Foswiki::App->new( env => \%ENV ); + my $extractor = $app->create('Foswiki::I18N::Extract'); die( "Could not create an extractor. Is Locale::Maketext installed? (see above messages)" ) unless $extractor; @@ -123,7 +131,13 @@ if ( $ARGV[0] eq '--list' ) { } # extract the strings to the template POT file. -extract( $newpotfile, @sources ); +try { + extract( $newpotfile, @sources ); +} +catch { + say STDERR Foswiki::Exception::errorStr($_); + exit 1; +}; # merge with old POT file if ( -e $potfile ) {