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

[FIX] Normalize TAPi18n language string on Livechat widget #14012

Merged
merged 2 commits into from
Apr 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion packages/rocketchat-livechat/.app/client/views/livechatWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ Template.livechatWindow.onCreated(function() {
});
};

const normalizeLanguageString = (languageString) => {
let [languageCode, countryCode] = languageString.split ? languageString.split(/[-_]/) : [];
if (!languageCode || languageCode.length !== 2) {
return 'en';
}
languageCode = languageCode.toLowerCase();

if (!countryCode || countryCode.length !== 2) {
countryCode = null;
} else {
countryCode = countryCode.toUpperCase();
}

return countryCode ? `${ languageCode }-${ countryCode }` : languageCode;
};

this.autorun(() => {
// get all needed live chat info for the user
Meteor.call('livechat:getInitialData', visitor.getToken(), Livechat.department, (err, result) => {
Expand Down Expand Up @@ -201,7 +217,7 @@ Template.livechatWindow.onCreated(function() {
Livechat.agent = result.agentData;
}

let language = result.language || defaultAppLanguage();
let language = normalizeLanguageString(result.language || defaultAppLanguage());

if (!availableLanguages[language]) {
language = language.split('-').shift();
Expand Down