From 2052c466e9c0a6515813d6f6d59d591638faf2ca Mon Sep 17 00:00:00 2001 From: Flaviu Mates Date: Tue, 15 Oct 2019 17:39:36 +0300 Subject: [PATCH] TT#68752 - Implement translation handling of 'Select' form field * Create new 'Select' field type that includes 'translate' attribute which shows is a field should be translated * Change fields that should not be translated to the new field type Change-Id: I723e82e609a7b4fc879e4fe708227c012cba1923 --- lib/NGCP/Panel/Field/Select.pm | 9 +++++++++ lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm | 3 ++- lib/NGCP/Panel/Form/DestinationSet.pm | 3 ++- lib/NGCP/Panel/Form/Domain/ResellerPbx.pm | 3 ++- lib/NGCP/Panel/Form/Peering/Server.pm | 3 ++- lib/NGCP/Panel/Form/Preferences.pm | 8 +++++--- lib/NGCP/Panel/Form/Statistics.pm | 6 ++++-- lib/NGCP/Panel/Form/Subscriber/LocationEntry.pm | 3 ++- lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm | 3 ++- lib/NGCP/Panel/Utils/I18N.pm | 2 +- 10 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 lib/NGCP/Panel/Field/Select.pm diff --git a/lib/NGCP/Panel/Field/Select.pm b/lib/NGCP/Panel/Field/Select.pm new file mode 100644 index 0000000000..5fab6a8de9 --- /dev/null +++ b/lib/NGCP/Panel/Field/Select.pm @@ -0,0 +1,9 @@ +package NGCP::Panel::Field::Select; +use HTML::FormHandler::Moose; + +extends 'HTML::FormHandler::Field::Select'; + +has 'translate' => (isa => 'Bool', is => 'rw', default => 1 ); + +no Moose; +1; diff --git a/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm b/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm index 7e19398461..958018a4c5 100644 --- a/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm +++ b/lib/NGCP/Panel/Form/Customer/PbxFieldDevice.pm @@ -11,7 +11,7 @@ sub build_render_list {[qw/submitid fields actions/]} sub build_form_element_class {[qw(form-horizontal)]} has_field 'profile_id' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', required => 1, label => 'Device', options_method => \&build_profiles, @@ -19,6 +19,7 @@ has_field 'profile_id' => ( rel => ['tooltip'], title => ['The PBX device.'] }, + translate => 0, ); sub build_profiles { my ($self) = @_; diff --git a/lib/NGCP/Panel/Form/DestinationSet.pm b/lib/NGCP/Panel/Form/DestinationSet.pm index 828b71191d..202b646a4b 100644 --- a/lib/NGCP/Panel/Form/DestinationSet.pm +++ b/lib/NGCP/Panel/Form/DestinationSet.pm @@ -105,12 +105,13 @@ has_field 'destination.priority' => ( ); has_field 'destination.announcement_id' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', #widget => 'RadioGroup', label => 'Custom announcement', options_method => \&build_announcements, wrapper_class => [qw/hfh-rep-field ngcp-destination ngcp-destination-customhours/], required => 0, + translate => 0, ); diff --git a/lib/NGCP/Panel/Form/Domain/ResellerPbx.pm b/lib/NGCP/Panel/Form/Domain/ResellerPbx.pm index e4f3108076..90f5b569ed 100644 --- a/lib/NGCP/Panel/Form/Domain/ResellerPbx.pm +++ b/lib/NGCP/Panel/Form/Domain/ResellerPbx.pm @@ -4,10 +4,11 @@ use HTML::FormHandler::Moose; extends 'NGCP::Panel::Form::Domain::Reseller'; has_field 'rwr_set' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Rewrite Rule Set', options_method => \&build_rwr_sets, default => undef, + translate => 0, ); sub build_rwr_sets { diff --git a/lib/NGCP/Panel/Form/Peering/Server.pm b/lib/NGCP/Panel/Form/Peering/Server.pm index 24096070df..24b8b060ac 100644 --- a/lib/NGCP/Panel/Form/Peering/Server.pm +++ b/lib/NGCP/Panel/Form/Peering/Server.pm @@ -53,9 +53,10 @@ has_field 'weight' => ( ); has_field 'via_route' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Via Route', options_method => \&build_via_routes, + translate => 0, ); sub build_via_routes { diff --git a/lib/NGCP/Panel/Form/Preferences.pm b/lib/NGCP/Panel/Form/Preferences.pm index a0d00300ae..cea10cc987 100644 --- a/lib/NGCP/Panel/Form/Preferences.pm +++ b/lib/NGCP/Panel/Form/Preferences.pm @@ -48,8 +48,9 @@ sub field_list { unshift @options, {label => '', value => ''}; $field = { name => $meta->attribute, - type => 'Select', + type => '+NGCP::Panel::Field::Select', options => \@options, + translate => 0, }; } elsif($meta->attribute eq "cdr_export_sclidui_rwrs") { my @options = map {{label => $_->name, value => $_->id}} @@ -66,8 +67,9 @@ sub field_list { unshift @options, {label => '', value => ''}; $field = { name => $meta->attribute, - type => 'Select', + type => '+NGCP::Panel::Field::Select', options => \@options, + translate => 0, }; } elsif ($meta->attribute eq "ncos" || $meta->attribute eq "adm_ncos" || @@ -95,7 +97,7 @@ sub field_list { unshift @options, {label => '', value => ''}; $field = { name => $meta->attribute, - type => 'Select', + type => '+NGCP::Panel::Field::Select', options => \@options, }; } elsif ($meta->attribute eq "contract_sound_set") { diff --git a/lib/NGCP/Panel/Form/Statistics.pm b/lib/NGCP/Panel/Form/Statistics.pm index 4352fa6b60..77449e02fb 100644 --- a/lib/NGCP/Panel/Form/Statistics.pm +++ b/lib/NGCP/Panel/Form/Statistics.pm @@ -11,10 +11,11 @@ sub build_render_list {[qw/submitid host folder select/]} sub build_form_element_class {[qw(form-horizontal)]} has_field 'host' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Host:', options_method => \&set_hosts, required => 1, + translate => 0, ); sub set_hosts { @@ -31,10 +32,11 @@ sub set_hosts { } has_field 'folder' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Category:', options_method => \&set_folders, required => 1, + translate => 0, ); sub set_folders { diff --git a/lib/NGCP/Panel/Form/Subscriber/LocationEntry.pm b/lib/NGCP/Panel/Form/Subscriber/LocationEntry.pm index 08b78b6012..95e598a99e 100644 --- a/lib/NGCP/Panel/Form/Subscriber/LocationEntry.pm +++ b/lib/NGCP/Panel/Form/Subscriber/LocationEntry.pm @@ -44,7 +44,7 @@ has_field 'q' => ( ); has_field 'socket' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Outbound socket', required => 0, options_method => \&build_socket_options, @@ -52,6 +52,7 @@ has_field 'socket' => ( rel => ['tooltip'], title => ['Points to the LB interface from which the incoming calls to this registration should be sent out.'] }, + translate => 0 ); sub build_socket_options { diff --git a/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm b/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm index bc0cb9e814..186a88a1fe 100644 --- a/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm +++ b/lib/NGCP/Panel/Form/Subscriber/SpeedDial.pm @@ -14,11 +14,12 @@ sub build_render_list {[qw/submitid fields actions/]} sub build_form_element_class { [qw/form-horizontal/] } has_field 'slot' => ( - type => 'Select', + type => '+NGCP::Panel::Field::Select', label => 'Slot', options_method => \&set_slots, required => 1, wrapper_class => [qw/hfh-rep-field/], + translate => 0, ); sub set_slots { diff --git a/lib/NGCP/Panel/Utils/I18N.pm b/lib/NGCP/Panel/Utils/I18N.pm index 488f7e0327..5601ae8423 100644 --- a/lib/NGCP/Panel/Utils/I18N.pm +++ b/lib/NGCP/Panel/Utils/I18N.pm @@ -29,7 +29,7 @@ sub _translate_fields_recursive { if ($field->isa('HTML::FormHandler::Field::Select')) { for my $option (@{ $field->options }) { push @strings, $option->{label} if $extract_strings; - $option->{label} = $c->loc($option->{label}) if $option->{label}; + $option->{label} = $c->loc($option->{label}) if ( $option->{label} && (($field->can('translate') && $field->translate) || !$field->can('translate')) ); } } if ($field->element_attr->{title}[0]) {