From 59e666c52010fe4657a597ea7414680ff9af0290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no> Date: Tue, 25 Oct 2011 12:05:01 +0000 Subject: [PATCH] Adding support for localization to DiscoJuice git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@2950 44740490-163a-0410-bde0-09ae8108e29a --- .../www/discojuice/discojuice.control.js | 8 +- .../www/discojuice/discojuice.ui.js | 113 ++++++++++++++++-- 2 files changed, 104 insertions(+), 17 deletions(-) diff --git a/modules/discojuice/www/discojuice/discojuice.control.js b/modules/discojuice/www/discojuice/discojuice.control.js index 012819a13..12f585fd7 100644 --- a/modules/discojuice/www/discojuice/discojuice.control.js +++ b/modules/discojuice/www/discojuice/discojuice.control.js @@ -840,13 +840,13 @@ DiscoJuice.Control = { if (filterOptions[preset]) choice = preset; } - var ftext = '<p class="discojuice_filter_country">Show providers in ' + + var ftext = '<p class="discojuice_filter_country">' + DiscoJuice.Dict.showIn+ ' ' + '<select class="discojuice_filterCountrySelect" name="filterCountrySelect">'; if (choice) { - ftext += '<option value="all">all countries</option>'; + ftext += '<option value="all">' + DiscoJuice.Dict.allCountries+ '</option>'; } else { - ftext += '<option value="all" selected="selected">all countries</option>'; + ftext += '<option value="all" selected="selected">' + DiscoJuice.Dict.allCountries+ '</option>'; } for (key in this.parent.Constants.Countries) { @@ -858,7 +858,7 @@ DiscoJuice.Control = { } } ftext += '</select>'; - ftext += ' <a class="discojuice_showall textlink" href="">show all countries</a>'; + ftext += ' <a class="discojuice_showall textlink" href="">' + DiscoJuice.Dict.showAllCountries+ '</a>'; ftext += '</p>'; this.ui.addFilter(ftext).find("select").change(function(event) { diff --git a/modules/discojuice/www/discojuice/discojuice.ui.js b/modules/discojuice/www/discojuice/discojuice.ui.js index 86c506278..9ee5b6b4b 100644 --- a/modules/discojuice/www/discojuice/discojuice.ui.js +++ b/modules/discojuice/www/discojuice/discojuice.ui.js @@ -43,6 +43,92 @@ DiscoJuice.UI = { this.alreadyLoaded = {}; }, + "sprintf": function() { + if (!arguments || arguments.length < 1 || !RegExp) + { + return; + } + var str = arguments[0]; + var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/; + var a = b = [], numSubstitutions = 0, numMatches = 0; + while (a = re.exec(str)) + { + var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4]; + var pPrecision = a[5], pType = a[6], rightPart = a[7]; + + numMatches++; + if (pType == '%') + { + subst = '%'; + } + else + { + numSubstitutions++; + if (numSubstitutions >= arguments.length) + { + alert('Error! Not enough function arguments (' + (arguments.length - 1) + + ', excluding the string)\n' + + 'for the number of substitution parameters in string (' + + numSubstitutions + ' so far).'); + } + var param = arguments[numSubstitutions]; + var pad = ''; + if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1); + else if (pPad) pad = pPad; + var justifyRight = true; + if (pJustify && pJustify === "-") justifyRight = false; + var minLength = -1; + if (pMinLength) minLength = parseInt(pMinLength); + var precision = -1; + if (pPrecision && pType == 'f') + precision = parseInt(pPrecision.substring(1)); + var subst = param; + switch (pType) + { + case 'b': + subst = parseInt(param).toString(2); + break; + case 'c': + subst = String.fromCharCode(parseInt(param)); + break; + case 'd': + subst = parseInt(param) ? parseInt(param) : 0; + break; + case 'u': + subst = Math.abs(param); + break; + case 'f': + subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision) : parseFloat(param); + break; + case 'o': + subst = parseInt(param).toString(8); + break; + case 's': + subst = param; + break; + case 'x': + subst = ('' + parseInt(param).toString(16)).toLowerCase(); + break; + case 'X': + subst = ('' + parseInt(param).toString(16)).toUpperCase(); + break; + } + var padLeft = minLength - subst.toString().length; + if (padLeft > 0) + { + var arrTmp = new Array(padLeft+1); + var padding = arrTmp.join(pad?pad:" "); + } + else + { + var padding = ""; + } + } + str = leftpart + padding + subst + rightPart; + } + return str; + }, + "addItem": function(item, countrydef, search, distance, quickentry, enabled) { var textLink = ''; var classes = (enabled ? 'enabled' : 'disabled'); @@ -100,7 +186,7 @@ DiscoJuice.UI = { if (distance != undefined) { if (distance < 1) { - textLink += '<span class="distance">Nearby</span>'; + textLink += '<span class="distance">' + DiscoJuice.Dict.Nearby + '</span>'; } else { textLink += '<span class="distance">' + Math.round(distance) + ' km' + '</span>'; } @@ -209,7 +295,8 @@ DiscoJuice.UI = { }); if (showmore) { - var moreLink = '<a class="discojuice_showmore textlink" href="">Results limited to ' + show + ' entries – show more…</a>'; + + var moreLink = '<a class="discojuice_showmore textlink" href="">' + this.sprintf(DiscoJuice.Dict.moreLink, show, listcount)+ '…</a>'; this.popup.find("p.discojuice_moreLinkContainer").empty().append(moreLink); this.popup.find("p.discojuice_moreLinkContainer a.discojuice_showmore").click(function(event) { event.preventDefault(); @@ -233,9 +320,9 @@ DiscoJuice.UI = { "enable": function(control) { var imgpath = this.parent.Utils.options.get('discoPath', '') + 'images/'; - var textSearch = this.parent.Utils.options.get('textSearch', 'or search for a provider, in example Univerity of Oslo'); - var textHelp = this.parent.Utils.options.get('textHelp', 'Help me, I cannot find my provider'); - var textHelpMore = this.parent.Utils.options.get('textHelpMore', 'If your institusion is not connected to Foodle, you may create a new account using any of the Guest providers, such as <strong>OpenIdP (Guest users)</strong>.'); + var textSearch = this.parent.Utils.options.get('textSearch', DiscoJuice.Dict.orSearch); + var textHelp = this.parent.Utils.options.get('textHelp', DiscoJuice.Dict.help); + var textHelpMore = this.parent.Utils.options.get('textHelpMore', DiscoJuice.Dict.helpMore); var subtitleText = this.parent.Utils.options.get('subtitle', null); var subtitleHTML = (subtitleText !== null ? '<p class="discojuice_subtitle">' + subtitleText + '</p>' : ''); @@ -249,7 +336,7 @@ DiscoJuice.UI = { '<div class="discojuice_listContent" style="">' + '<div class="scroller">' + - '<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> Loading list of providers...</div>' + + '<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> ' + DiscoJuice.Dict.loading + '...</div>' + '</div>' + '<p class="discojuice_moreLinkContainer" style="margin: 0px; padding: 4px"> </p>' + '</div>' + @@ -261,7 +348,7 @@ DiscoJuice.UI = { '<div id="discojuice_page_return" style="display: none" class="" >' + '<div class="" style="">' + - '<input id="discojuice_returntoproviderlist" type="submit" value="« Return to list of providers" />' + + '<input id="discojuice_returntoproviderlist" type="submit" value="« ' + DiscoJuice.Dict.pageReturn + '" />' + '</div>' + '</div>' + @@ -283,7 +370,7 @@ DiscoJuice.UI = { '<div class="locatemebefore">' + '<p style="margin-top: 10px"><a id="locateme" href="">' + '<img style="float: left; margin-right: 5px; margin-top: -10px" src="' + imgpath + 'target.png" alt="locate me..." />' + - 'Locate me and show nearby providers</a>' + + DiscoJuice.Dict.locateMe + '</a>' + '</p>' + '<p style="color: #999" id="locatemeinfo"></p>' + '</div>' + @@ -330,11 +417,11 @@ DiscoJuice.UI = { this.popup.find("p#dj_help").click(function() { that.setScreen( - '<h2>About DiscoJuice</h2>' + - '<p style="margin: .5em 0px">DiscoJuice is a user interface to help users select which provider to login with. DiscoJuice is created by <a href="http://uninett.no">UNINETT</a></p>' + + '<h2>' + DiscoJuice.Dict.about + '</h2>' + + '<p style="margin: .5em 0px">' + that.sprintf(DiscoJuice.Dict.aboutDescr, '<a href="http://uninett.no">', '</a>') + '</p>' + - '<p style="margin: .5em 10px"><a href="http://discojuice.org" target="_blank">Read more about DiscoJuice</a></p>' + - '<p style="margin: .5em 0px; font-size: 80%">Version: ' + DiscoJuice.Version); + '<p style="margin: .5em 10px"><a href="http://discojuice.org" target="_blank">' + DiscoJuice.Dict.aboutMore + '</a></p>' + + '<p style="margin: .5em 0px; font-size: 80%">' + DiscoJuice.Dict.version + ': ' + DiscoJuice.Version); }); this.popup.find("#discojuiceextesion_listener").click(function() { @@ -366,7 +453,7 @@ DiscoJuice.UI = { event.preventDefault(); event.stopPropagation(); $("div.locatemebefore").hide(); - $("div.locatemeafter").html('<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> Getting your location...</div>'); + $("div.locatemeafter").html('<div class="loadingData" ><img src="' + imgpath + 'spinning.gif" /> ' + DiscoJuice.Dict.locating + '...</div>'); that.control.locateMe(); }); } -- GitLab