$('.uls-trigger').uls({
  quickList: ['en', 'es', 'fr'],
  onSelect: (language) => {
    if (window.currentUser.id !== '') {
      $.post(`/update_locale/${language}`, () => {
        location.reload();
      });
    } else {
      window.location = `?locale=${language}`;
    }
  }
});

if ($().uls) {
  $('.uls-trigger').uls({
    quickList: ['en', 'es', 'fr'],
    onSelect: (language) => {
      if (window.currentUser.id !== '') {
        $.post(`/update_locale/${language}`, () => {
          location.reload();
        });
      } else {
        window.location = `?locale=${language}`;
      }
    }
  });
}

Make sure uls plugin is available before running
Make sure uls plugin is available before running
