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
mr10.0
Victor Tsvetov 4 years ago
parent c6a6427ab9
commit 21bbb382d6

@ -10,7 +10,7 @@ sub new {
die __PACKAGE__ . " is abstract" if __PACKAGE__ eq $class;
my $self = {};
$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;
}
@ -26,6 +26,7 @@ sub template {
sub render {
my $self = shift;
return unless $self->{c};
my $output = '';

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

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

@ -53,13 +53,16 @@ sub dummy::loc { shift; return shift; };
my %unique_strings;
foreach my $mod(@files){
my $modname = $mod =~ s!lib/!!r =~ s!/!::!gr =~ s!\.pm$!!r;
eval {
require $mod;
my $form = $modname->new;
my $strings = NGCP::Panel::Utils::I18N->translate_form($dummy, $form, 1);
print $fh " #$modname\n";
@unique_strings{@$strings} = 1;
} || print $fh " #$modname: error\n";
if (eval "require $modname; 1;") {
eval {
my $form = $modname->new;
my $strings = NGCP::Panel::Utils::I18N->translate_form($dummy, $form, 1);
print $fh " #$modname\n";
@unique_strings{@$strings} = 1;
} || print $fh " #$modname: error: $@\n";
} else {
print $fh "#'$modname' could not be loaded. Skipping it...\n";
}
}
for my $s (keys %unique_strings) {
@ -75,10 +78,34 @@ print $fh <<FOOTER_END;
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
This library is free software. You can redistribute it and/or modify
it under the same terms as Perl itself.
This software is Copyright 2021 by Sipwise GmbH, Austria.
All rights reserved. You may not copy, distribute
or modify without prior written permission from
Sipwise GmbH, Austria.
=cut

Loading…
Cancel
Save