- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 11:02 PM
Hi All,
I have added language switch widget into my custom portal home page, and it shows multiple options to select. I need to restrict the dropdown values to have only 3 languages. Can anyone help me on this please?
Regards,
Aswathy Muraleedharan
Solved! Go to Solution.
- Labels:
-
Service Portal Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:28 AM
Hi Bhavana,
It worked , Thank you.
I was trying to clone the OOB language switch widget to achieve this, and could see that the client script is calling some API.
Anyway, the requirement is to enable the dropdown only for few languages.
Regards,
Aswathy Muraleedharan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-13-2021 11:20 PM
Hello,
Yes it is possible to exclude other langugaes that u dont need.
In the widget server script just exclude those languages like below.
Server script:
// Language Switch for login page
var util = new I18nUtils();
data.language = gs.getUser().getLanguage();
if (data.language == 'en'){
data.language = 'English';
}
else{
var currentLang = new GlideRecord("sys_language");
currentLang.addEncodedQuery('active=true^name!=German^name!=Japanese');
var userLang = '';
if(gs.getSession().isLoggedIn()){
userLang = gs.getUser().getPreference("user.language");
}
else {
userLang = util.getLanguage();
}
currentLang.addQuery('id', userLang);
currentLang.query();
while (currentLang.next()) {
data.language = currentLang.name.getDisplayValue();
}
}
var languages = [];
var lang = new GlideRecord("sys_language");
lang.addEncodedQuery('active=true^name!=German^name!=Japanese');
//lang.addEncodedQuery("active=true^id!=de^ORid!=it^ORid!=pt^ORid!=es");
lang.orderBy('name');
lang.query();
while (lang.next()) {
var language = {};
language.label = lang.name.getDisplayValue();
language.value = lang.getValue('id');
languages.push(language);
}
data.languages = languages;
if(input.newLanguage){
if(gs.getSession().isLoggedIn()){
var user = gs.getUser();
user.setPreference("user.language", input.newLanguage);
user.savePreferences();
}
else{
util.setLanguage(input.newLanguage);
}
}
Please modify according to your requirement.
Thanks,
Bhavana
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:09 AM
Hi Bhavana,
Thank you for the response!
Do we need to modify the client script as well?
Regards
Aswathy Muraleedharan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:18 AM
Hello,
We havent modified the client script, let me give you the complete code for the widget.
Client side:
function ($scope, $window, $timeout) {
$scope.setLanguage = function(value,label) {
$scope.data.newLanguage = value;
$scope.server.update();
$timeout(windowRefresh, 250);
function windowRefresh() {
$window.location.reload();
}
};
}
HTML :
<div><ul class="nav navbar-nav">
<li class="dropdown">
<a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">
<div class="text-body">${Language}:${{{data.language}}}</div>
</a>
<ul class="dropdown-menu">
<li><a ng-click="setLanguage('en')">English</a></li>
<li ng-repeat="lang in data.languages"><a ng-click="setLanguage(lang.value)">{{lang.label}}</a></li>
</ul>
</li>
</ul></div>
CSS:
.list-group-item {
border: none;
}
.text-body {
text-align: -webkit-match-parent;
color: #000000;
font-size: 14px;
font-family: "SourceSansPro", Helvetica, Arial, sans-serif;
}
.list-group {
margin-bottom: 0px;
}
#lang{
height: 50px;
}
i have already shared the server code
Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-14-2021 12:28 AM
Hi Bhavana,
It worked , Thank you.
I was trying to clone the OOB language switch widget to achieve this, and could see that the client script is calling some API.
Anyway, the requirement is to enable the dropdown only for few languages.
Regards,
Aswathy Muraleedharan