Skip to content

Commit

Permalink
bugfix in brain answer : keep only 2 first character of user language
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Apr 10, 2017
1 parent 5909929 commit c4f5412
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions api/core/brain/brain.answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ module.exports = function answer(result, user) {

sails.log.info(`Brain : answer : Answering with label ${result.response.label} in language ${user.language}`);

return gladys.utils.sql(queries.getAnswers, [user.language, result.response.label])
// put language in lower case and only with 2 first characters
var language = user.language.substr(0,2).toLowerCase();

return gladys.utils.sql(queries.getAnswers, [language, result.response.label])
.then((answers) => {

sails.log.debug(`Brain : answer : Found ${answers.length} possible.`);
Expand All @@ -20,7 +23,7 @@ module.exports = function answer(result, user) {
result.response.needAnswer = answers[randomRow].needAnswer;
}
else {
result.response.text = sails.__({ phrase: 'default-answer-gladys-brain', locale: user.language});
result.response.text = sails.__({ phrase: 'default-answer-gladys-brain', locale: language});
result.response.needAnswer = false;
}

Expand Down
2 changes: 1 addition & 1 deletion api/core/brain/brain.classify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function classify(user, message){
.then((scope) => {

// add language to scope so that called module can adapt to the current language
scope.language = user.language;
scope.language = user.language.substr(0, 2).toLowerCase();

// add user to scope so that called module can adapt to current user
scope.user = user;
Expand Down

0 comments on commit c4f5412

Please sign in to comment.