TT#115002 Fix collecting i18n strings from Forms

Fix ngcp_panel_dump_db_strings.pl to load Forms modules properly.
Make modules not to fail when they are called without ctx context.

Change-Id: I695978b1831068f37198bce9f6a5b9e406d79ede
(cherry picked from commit 21bbb382d6)
mr9.5.4
Victor Tsvetov 4 years ago
parent 80e0734a04
commit e4bded2d27

@ -10,7 +10,7 @@ sub new {
die __PACKAGE__ . " is abstract" if __PACKAGE__ eq $class; die __PACKAGE__ . " is abstract" if __PACKAGE__ eq $class;
my $self = {}; my $self = {};
$self->{form} = $args{form}; $self->{form} = $args{form};
$self->{c} = $args{form}->{ctx} or die "form context required for $class"; $self->{c} = $args{form}->{ctx};
return bless $self, $class; return bless $self, $class;
} }
@ -26,6 +26,7 @@ sub template {
sub render { sub render {
my $self = shift; my $self = shift;
return unless $self->{c};
my $output = ''; my $output = '';

@ -172,9 +172,11 @@ sub build_announcements {
my ($self) = @_; my ($self) = @_;
my @options = (); my @options = ();
my $c = $self->form->ctx; my $c = $self->form->ctx;
push @options, { label => 'Select announcement', value => '' }; if(defined $c) {
foreach($c->stash->{custom_announcements_rs}->all){ push @options, { label => 'Select announcement', value => '' };
push @options, { label => $_->name, value => $_->id }; foreach($c->stash->{custom_announcements_rs}->all){
push @options, { label => $_->name, value => $_->id };
}
} }
return \@options; return \@options;
} }

@ -146,9 +146,11 @@ sub build_announcements {
my ($self) = @_; my ($self) = @_;
my @options = (); my @options = ();
my $c = $self->form->ctx; my $c = $self->form->ctx;
push @options, { label => 'Select announcement', value => '' }; if(defined $c) {
foreach($c->stash->{custom_announcements_rs}->all){ push @options, { label => 'Select announcement', value => '' };
push @options, { label => $_->name, value => $_->id }; foreach($c->stash->{custom_announcements_rs}->all){
push @options, { label => $_->name, value => $_->id };
}
} }
return \@options; return \@options;
} }

@ -53,13 +53,16 @@ sub dummy::loc { shift; return shift; };
my %unique_strings; my %unique_strings;
foreach my $mod(@files){ foreach my $mod(@files){
my $modname = $mod =~ s!lib/!!r =~ s!/!::!gr =~ s!\.pm$!!r; my $modname = $mod =~ s!lib/!!r =~ s!/!::!gr =~ s!\.pm$!!r;
eval { if (eval "require $modname; 1;") {
require $mod; eval {
my $form = $modname->new; my $form = $modname->new;
my $strings = NGCP::Panel::Utils::I18N->translate_form($dummy, $form, 1); my $strings = NGCP::Panel::Utils::I18N->translate_form($dummy, $form, 1);
print $fh " #$modname\n"; print $fh " #$modname\n";
@unique_strings{@$strings} = 1; @unique_strings{@$strings} = 1;
} || print $fh " #$modname: error\n"; } || print $fh " #$modname: error: $@\n";
} else {
print $fh "#'$modname' could not be loaded. Skipping it...\n";
}
} }
for my $s (keys %unique_strings) { for my $s (keys %unique_strings) {
@ -75,10 +78,34 @@ print $fh <<FOOTER_END;
1; 1;
=head1 NAME
NGCP::Panel::Utils::DbStrings
=head1 VERSION
Version UNRELEASED_VERSION
=head1 SYNOPSIS
Localization strings from DB and Forms
=head1 DESCRIPTION
Dump strings from DataBase and Forms to a dummy module, for localisation.
Strings are collected later by extract_i18n.sh script.
=head1 AUTHOR
Sipwise Development Team <support\@sipwise.com>
=head1 LICENSE =head1 LICENSE
This library is free software. You can redistribute it and/or modify This software is Copyright 2021 by Sipwise GmbH, Austria.
it under the same terms as Perl itself.
All rights reserved. You may not copy, distribute
or modify without prior written permission from
Sipwise GmbH, Austria.
=cut =cut

Loading…
Cancel
Save