There are numerous users of SUSI.AI globally. Most of the users use skills in English languages while some prefer their native languages. Also,there are some users who want SUSI skills of multiple languages. So the process of fetching skills from multiple languages has been explained in this blog.
Server side implementation
The language parameter in ListSkillService.java is modified to accept a string that contains the required languages separated by a comma. Then this parameter is split by comma symbol which returns an array of the required languages.
String language_list = call.get("language", "en"); String[] language_names = language_list.split(",");
Then simple loop over this array language by language and keep adding the the skills’ metadata, in that language into the response object.
for (String language_name : language_names) { // fetch the skills in this language. }
CMS side implementation
Convert the state variable languageValue, in BrowseSkill.js, from strings to an array so that multiple languages can be kept in it.
languageValue: ['en']
Change the language dropdown menu to allow selection of multiple values and attach an onChange listener to it. Its value is the same as that of state variable languageValue and its content is filled by calling a function languageMenuItems().
<SelectField multiple={true} hintText="Languages" value={languageValue} onChange={this.handleLanguageChange} > {this.languageMenuItems(languageValue)} </SelectField>
The languageMenuItems() function gets the list of checked languages as a parameter. The whole list of languages are stored in a global variable called languages. So this function loops over the list of all the languages and check / uncheck them based on the values passed in the argument. It build a menu item for each language and put the ISO6391 native name of that language into the menu item.
languageMenuItems(values) { return languages.map(name => ( <MenuItem insetChildren={true} checked={values && values.indexOf(name) > -1} value={name} primaryText={ ISO6391.getNativeName(name) ? ISO6391.getNativeName(name) : 'Universal' } /> )); }
While the language change handler gets the values of the selected languages in the form of an array, from the drop down menu. It simply assigns this value to the state variable languageValue and calls the loadCards() function to load the skills based on the new filter.
this.setState({ languageValue: values }, function() { this.loadCards(); });
References
- Material UI Docs – https://material-ui.com/api/select/