Skip to content

Commit

Permalink
Issue #205: translate the country code
Browse files Browse the repository at this point in the history
in the customer information widget of the ticket zoom page
  • Loading branch information
bschmalhofer committed Dec 9, 2023
1 parent a81e49f commit d9f9a31
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Kernel/Output/HTML/Layout/Ticket.pm
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,30 @@ sub AgentCustomerViewTable {
# build table
FIELD:
for my $Field (@MapNew) {
if ( $Field->[3] && $Field->[3] >= $ShownType && $Param{Data}->{ $Field->[0] } ) {
next FIELD unless $Field->[3];
next FIELD unless $Field->[3] >= $ShownType;
next FIELD unless $Param{Data}->{ $Field->[0] }; # TODO: value '0' is not shown

{
my %Record = (
%{ $Param{Data} },
Key => $Field->[1],
Value => $Param{Data}->{ $Field->[0] },
);

# handle special case of translatable customer countries
if (
$ConfigObject->Get('ReferenceData::TranslatedCountryNames')
&&
$Field->[0] =~ m/^CustomerCompanyCountry/i
)
{
$Record{Value} = $Kernel::OM->Get('Kernel::System::ReferenceData')->CountryCode2Name(
CountryCode => $Record{Value},
Language => $Self->{UserLanguage},
);
}

# render dynamic field values
if ( $Field->[5] eq 'dynamic_field' ) {
if ( !IsArrayRefWithData( $Record{Value} ) ) {
Expand All @@ -154,7 +171,7 @@ sub AgentCustomerViewTable {

my $DynamicFieldConfig = $DynamicFieldLookup{ $Field->[2] };

next FIELD if !$DynamicFieldConfig;
next FIELD unless $DynamicFieldConfig;

my @RenderedValues;
VALUE:
Expand Down Expand Up @@ -211,6 +228,7 @@ sub AgentCustomerViewTable {
Data => \%Record,
);

# Mark invalid companies
if (
$Param{Data}->{Config}->{CustomerCompanySupport}
&& $Field->[0] eq 'CustomerCompanyName'
Expand Down
31 changes: 31 additions & 0 deletions Kernel/System/ReferenceData.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,35 @@ sub TranslatedCountryList {
return \%Code2Name;
}

=head1 CountryCode2Name()
Get a translated country name for a country code.
my $CountryName = $ReferenceDataObject->CountryCode2Name(
CountryCode => 'AF',
Language => 'de',
);
Returns:
$CountryName = 'Afghanistan';
=cut

sub CountryCode2Name {
my ( $Self, %Param ) = @_;

my $Code = $Param{CountryCode};

return $Code unless $Code =~ m/^[A-Z]{2}$/;

my $MainObject = $Kernel::OM->Get('Kernel::System::Main');

return $Code unless $MainObject->Require('Locale::CLDR');

my $Locale = Locale::CLDR->new( language_id => $Param{Language} );

return $Locale->region_name($Code); # English per default
}

1;

0 comments on commit d9f9a31

Please sign in to comment.