Skip to content

Commit

Permalink
Merge pull request #758 from expectingtofly/fix_language_selection_JS…
Browse files Browse the repository at this point in the history
…ONRPC

Allow selection of sub language (eg. ZH_CH or EN_GB) through JSONRPC
  • Loading branch information
mherger committed Feb 12, 2022
2 parents 8bc9f72 + 242deca commit 6c1b744
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Slim/Web/JSONRPC.pm
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ sub handleURI {
if ( my $lang = $httpResponse->request->header('Accept-Language') ) {
my @parts = split(/[,-]/, $lang);
$context->{lang} = uc $parts[0] if $parts[0];
# We support variation languages for zh and en. Therefore, we record second part as a sub language to try and match later.
$context->{sublang} = uc $parts[1] if (scalar @parts) > 1;
}

if ( my $ua = ( $httpResponse->request->header('X-User-Agent') || $httpResponse->request->header('User-Agent') ) ) {
Expand Down Expand Up @@ -410,8 +412,9 @@ sub requestMethod {
if ($request->isStatusDispatchable) {

# Set language override for this request
my $lang = $context->{lang};
my $ua = $context->{ua};
my $lang = $context->{lang};
my $sublang = $context->{sublang};
my $ua = $context->{ua};

my $finish;

Expand All @@ -423,6 +426,14 @@ sub requestMethod {
};
}

# test if the sub language is an available option
if ( $lang && $sublang ) {
my $all_langs = Slim::Utils::Strings::languageOptions();
if (defined $all_langs->{$lang . '_' . $sublang}) {
$lang .= '_' . $sublang;
}
}

if ( $client && $lang ) {
$client->languageOverride($lang);
$client->controlledBy('squeezeplay');
Expand Down

0 comments on commit 6c1b744

Please sign in to comment.