The CreatorCon Call for Content is officially open! Get started here.

Self service portal: Add language option on login page

lomouhamadou
Kilo Guru

Hi all,

Is it any simple way on the new Self service portal for adding the language option on the login page as we have on the backend?

thanks in advance

Regs,

Lô Mouhamadou

1 ACCEPTED SOLUTION

brett_karl
ServiceNow Employee
ServiceNow Employee

I completed a widget solution that ties into the Service Portal Header.



  1. Import the widget record that is attached to this reply
  2. Navigate to your header
  3. Find the following code in the Body HTML Template:

<ul ng-if="::user.logged_in" class="nav navbar-nav">


              <!-- chat, avatar, and logout -->


              <li ng-if="::data.connect_support_queue_id"><a href ng-click="openPopUp()">${Live Chat}</a></li>


         


              <li class="dropdown hidden-xs">


                  <a href="javascript:void(0)" class="dropdown-toggle" data-toggle="dropdown">


                      <span class="navbar-avatar"><sn-avatar class="avatar-small-medium" primary="userID" /></span>


                      <span class="visible-lg-inline">{{::user.name}}</span>


                  </a>



        Add the following code (to line 4):


<li><sp-widget widget="data.languagePicker"></sp-widget></li>



Navigate down to Server Script and add the following line.



  data.languageSelector = $sp.getWidget("language-picker", {});



The end result will look like this:


Screen Shot 2016-08-19 at 2.50.27 PM.png


Please let me know if you any more help!


View solution in original post

44 REPLIES 44

Hi Fred,



I'm not sure why the setLanguage function of I18nUtils() isn't working for you, though I am using it in Istanbul so maybe it's something recently enabled for the guest user?


Other than that, we have the same setup, the widget containing the language setter is global, and is being called from a header in a custom scope.



The only thing I can think of is to check whether the user is logged in before doing anything.


i.e.


if(gs.getSession().isLoggedIn()){  


            userLang = gs.getUser().getPreference("user.language");  


  }  


  else {  


            userLang = util.getLanguage();  


  }


and


if(gs.getSession().isLoggedIn()){  


            var user = gs.getUser();  


            user.setPreference("user.language", input.newLanguage);  


            user.savePreferences();  


  }  


  else{  


            util.setLanguage(input.newLanguage);      


  }


Dear thomaswright



Thanks for attempting to help.



I made some tests and could observe that I18nUtils is working fine on my developer instance running Istanbul.


However, the same code on Helsinki is not working.



I have opened an incident on HI and am now waiting for an answer (so far I got an off-topic suggestion about GlideAjax... well...)



It looks like some other people had issues with different versions
Re: How to change system language in script


I'd like to add to this thread that in order to change the language automatically to a static language (my customer wants different languages as default in portal and backend) just add an empty widget to the portals homepage, and only include these two lines in the server script:



var util = new I18nUtils();


util.setLanguage("lang");



Where lang = code of language like "en", "fr" or whatever.



This also works for non-logged in users


Robert_Cartwrig
Tera Expert

Wow...lots of really good info here...for a widget that isn't the same as what is available on the share. This is all about version 1.0, but 1.02 is what is available on the share.

 

Does the 1.02 version of the Language Picker work in newer versions of the SN platform?

 

How would one add this picker that is currently available to the header menu? 

 

Also, while I can add it to the page and it works, knowledge base articles are not sorted.

 

Any updates to this thread?


Thanks,

Robert

MR7
Kilo Expert

It is perfectly working for Madrid version but on Kingston adding the above code causes all the header menu to disappear and only language picker is visible. Attached is the reference screen shot. Can anyone help on this issue?