Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow selection of sub language (eg. ZH_CH or EN_GB) through JSONRPC #758

Conversation

expectingtofly
Copy link
Contributor

Setting the language for a JSONRPC call is achieved through setting the standard HTTP request header 'Accept-Language'

Currently the code only takes the first part of standard iso code (e.g the 'EN' of 'en-US') to match the language to the LMS language.
However, this will never work for the language variations that now exist in LMS (currently EN_GB and ZH_CN) and therefore can never be selected.

This pull request proposes fixing this by also selecting the second part of the iso code and checking to see if that is a matching LMS language with the '_' underscore convention.

Comment on lines 227 to +230
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;
Copy link
Contributor

@mherger mherger Feb 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@parts could also be a list of locale choices supported by the browser (de, en=> 'de','en'). See eg. https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language. You'd probably have to first split by comma to get the various locales, then pick the first and split by the dash.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed. But I was going by the assumption that the original, rather imprecise, way of identifying the language would want to be maintained to limit the chance of impacting integrations. But more than happy to change it to properly parse the 'Accept-Language' header. If that's your view?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually... I believe it doesn't really matter, as you're going to verify whether the concatenated language exists or not. Assuming that a user would usually go from specific (en-GB) to generic (en), there's little chance of a conflict anyway. I'm going to merge this. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I've now added precise Accept-Language parsing (handling it as per standards).
I'll submit that as another pull request you can delete if you are happy with this original more forgiving method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants