From eb17562f4d9071132208a48bb5b2a9934170fa9c Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Sun, 14 Aug 2016 23:08:37 +0100 Subject: [PATCH] NLS the palette editor --- editor/js/ui/palette-editor.js | 76 ++++++++++++------------------- editor/templates/index.mst | 2 +- red/api/locales/en-US/editor.json | 43 +++++++++++++++++ 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/editor/js/ui/palette-editor.js b/editor/js/ui/palette-editor.js index b4e3c5afd..59932642c 100644 --- a/editor/js/ui/palette-editor.js +++ b/editor/js/ui/palette-editor.js @@ -118,65 +118,51 @@ RED.palette.editor = (function() { function formatUpdatedAt(dateString) { var now = new Date(); var d = new Date(dateString); - var delta = now.getTime() - d.getTime(); - - delta /= 1000; + var delta = (Date.now() - new Date(dateString).getTime())/1000; if (delta < 60) { - return "seconds ago"; + return RED._('palette.editor.times.seconds'); } - delta = Math.floor(delta/60); - if (delta < 10) { - return "minutes ago"; + return RED._('palette.editor.times.minutes'); } if (delta < 60) { - return delta+" minutes ago"; + return RED._('palette.editor.times.minutesV',{count:delta}); } delta = Math.floor(delta/60); if (delta < 24) { - return delta+" hour"+(delta>1?"s":"")+" ago"; + return RED._('palette.editor.times.hoursV',{count:delta}); } delta = Math.floor(delta/24); if (delta < 7) { - return delta+" day"+(delta>1?"s":"")+" ago"; + return RED._('palette.editor.times.daysV',{count:delta}) } var weeks = Math.floor(delta/7); var days = delta%7; if (weeks < 4) { - if (days === 0) { - return weeks+" week"+(weeks>1?"s":"")+" ago"; - } else { - return weeks+" week"+(weeks>1?"s":"")+", "+days+" day"+(days>1?"s":"")+" ago"; - } + return RED._('palette.editor.times.weeksV',{count:weeks}) } var months = Math.floor(weeks/4); weeks = weeks%4; if (months < 12) { - if (weeks === 0) { - return months+" month"+(months>1?"s":"")+" ago"; - } else { - return months+" month"+(months>1?"s":"")+", "+weeks+" week"+(weeks>1?"s":"")+" ago"; - } + return RED._('palette.editor.times.monthsV',{count:months}) } - var years = Math.floor(months/12); months = months%12; if (months === 0) { - return years+" year"+(years>1?"s":"")+" ago"; + return RED._('palette.editor.times.yearsV',{count:years}) } else { - return years+" year"+(years>1?"s":"")+", "+months+" month"+(months>1?"s":"")+" ago"; + return RED._('palette.editor.times.year'+(years>1?'s':'')+'MonthsV',{y:years,count:months}) } - } @@ -235,33 +221,33 @@ RED.palette.editor = (function() { nodeEntries[module].totalUseCount += inUseCount; if (inUseCount > 0) { - setElements.enableButton.html('in use'); + setElements.enableButton.html(RED._('palette.editor.inuse')); setElements.enableButton.addClass('disabled'); } else { setElements.enableButton.removeClass('disabled'); if (set.enabled) { - setElements.enableButton.html('disable'); + setElements.enableButton.html(RED._('palette.editor.disable')); } else { - setElements.enableButton.html('enable'); + setElements.enableButton.html(RED._('palette.editor.enable')); } } setElements.setRow.toggleClass("palette-module-set-disabled",!set.enabled); } } var nodeCount = (activeTypeCount === typeCount)?typeCount:activeTypeCount+" / "+typeCount; - nodeEntry.setCount.html(nodeCount+" node"+(typeCount>1?"s":"")); + nodeEntry.setCount.html(RED._('palette.editor.nodeCount',{count:typeCount,label:nodeCount})); if (nodeEntries[module].totalUseCount > 0) { - nodeEntry.enableButton.html("in use"); + nodeEntry.enableButton.html(RED._('palette.editor.inuse')); nodeEntry.enableButton.addClass('disabled'); nodeEntry.removeButton.hide(); } else { nodeEntry.enableButton.removeClass('disabled'); nodeEntry.removeButton.show(); if (activeTypeCount === 0) { - nodeEntry.enableButton.html("enable all"); + nodeEntry.enableButton.html(RED._('palette.editor.enableall')); } else { - nodeEntry.enableButton.html("disable all"); + nodeEntry.enableButton.html(RED._('palette.editor.disableall')); } nodeEntry.container.toggleClass("disabled",(activeTypeCount === 0)); } @@ -329,7 +315,7 @@ RED.palette.editor = (function() { } searchInput.searchBox('count',loadedList.length); if (catalogueCount > 1) { - $(".palette-module-shade-status").html("Loading catalogues...
"+catalogueLoadStatus.length+"/"+catalogueCount); + $(".palette-module-shade-status").html(RED._('palette.editor.loading')+"
"+catalogueLoadStatus.length+"/"+catalogueCount); } if (catalogueLoadStatus.length === catalogueCount) { var delta = 250-(Date.now() - catalogueLoadStart); @@ -343,12 +329,12 @@ RED.palette.editor = (function() { if (loadedList.length === 0) { loadedList = []; packageList.editableList('empty'); - $(".palette-module-shade-status").html("Loading catalogues..."); + $(".palette-module-shade-status").html(RED._('palette.editor.loading')); var catalogues = RED.settings.theme('palette.catalogues')||['http://catalogue.nodered.org/catalogue.json']; catalogueLoadStatus = []; catalogueCount = catalogues.length; if (catalogues.length > 1) { - $(".palette-module-shade-status").html("Loading catalogues...
0/"+catalogues.length); + $(".palette-module-shade-status").html(RED._('palette.editor.loading')+"
0/"+catalogues.length); } $("#palette-module-install-shade").show(); catalogueLoadStart = Date.now(); @@ -427,8 +413,7 @@ RED.palette.editor = (function() { editorTabs.addTab({ id: 'nodes', - label: 'Nodes', - name: 'Nodes', + label: RED._('palette.editor.tab-nodes'), content: modulesTab }) @@ -466,7 +451,7 @@ RED.palette.editor = (function() { var setButton = $(' ').appendTo(buttonRow); var setCount = $('').appendTo(setButton); var buttonGroup = $('
',{class:"palette-module-button-group"}).appendTo(buttonRow); - var removeButton = $('').html('remove').appendTo(buttonGroup); + var removeButton = $('').html(RED._('palette.editor.remove')).appendTo(buttonGroup); removeButton.click(function() { shade.show(); removeNodeModule(entry.name, function(xhr) { @@ -476,7 +461,7 @@ RED.palette.editor = (function() { if (!entry.local) { removeButton.hide(); } - var enableButton = $('').html('disable all').appendTo(buttonGroup); + var enableButton = $('').html(RED._('palette.editor.disableall')).appendTo(buttonGroup); var contentRow = $('
',{class:"palette-module-content"}).appendTo(container); var shade = $('
').appendTo(container); @@ -550,8 +535,7 @@ RED.palette.editor = (function() { editorTabs.addTab({ id: 'install', - label: 'Install', - name: 'Install', + label: RED._('palette.editor.tab-install'), content: installTab }) @@ -581,10 +565,10 @@ RED.palette.editor = (function() { }); - $('').html('sort: ').appendTo(toolBar); + $('').html(RED._("palette.editor.sort")+' ').appendTo(toolBar); var sortGroup = $(' ').appendTo(toolBar); - var sortAZ = $('a-z').appendTo(sortGroup); - var sortRecent = $('recent').appendTo(sortGroup); + var sortAZ = $('').appendTo(sortGroup); + var sortRecent = $('').appendTo(sortGroup); sortAZ.click(function(e) { e.preventDefault(); @@ -623,7 +607,7 @@ RED.palette.editor = (function() { if (object.more) { container.addClass('palette-module-more'); var moreRow = $('
',{class:"palette-module-header palette-module"}).appendTo(container); - var moreLink = $('').html("+ "+object.more+" more").appendTo(moreRow); + var moreLink = $('').html(RED._('palette.editor.more',{count:object.more})).appendTo(moreRow); moreLink.click(function(e) { e.preventDefault(); packageList.editableList('removeItem',object); @@ -650,13 +634,13 @@ RED.palette.editor = (function() { var buttonRow = $('
',{class:"palette-module-meta"}).appendTo(headerRow); var buttonGroup = $('
',{class:"palette-module-button-group"}).appendTo(buttonRow); var shade = $('
').appendTo(container); - var installButton = $('').html('install').appendTo(buttonGroup); + var installButton = $('').html(RED._('palette.editor.install')).appendTo(buttonGroup); installButton.click(function(e) { e.preventDefault(); installNodeModule(entry.id,shade,function(xhr) { if (xhr) { if (xhr.responseJSON) { - RED.notify("Failed to install: "+entry.id+"
"+xhr.responseJSON.message+"
Check the log for more information","error",false,8000); + RED.notify(RED._('palette.editor.errors.installFailed',{module: entry.id,message:xhr.responseJSON.message})); } } }) diff --git a/editor/templates/index.mst b/editor/templates/index.mst index 92d6464b6..0d9bdb313 100644 --- a/editor/templates/index.mst +++ b/editor/templates/index.mst @@ -62,7 +62,7 @@
-
  • Manage palette
+
    diff --git a/red/api/locales/en-US/editor.json b/red/api/locales/en-US/editor.json index c28b0512d..176f54274 100644 --- a/red/api/locales/en-US/editor.json +++ b/red/api/locales/en-US/editor.json @@ -200,6 +200,49 @@ "nodeEnabled_plural": "Nodes enabled:", "nodeDisabled": "Node disabled:", "nodeDisabled_plural": "Nodes disabled:" + }, + "editor": { + "title": "Manage palette", + "times": { + "seconds": "seconds ago", + "minutes": "minutes ago", + "minutesV": "__count__ minutes ago", + "hoursV": "__count__ hour ago", + "hoursV_plural": "__count__ hours ago", + "daysV": "__count__ day ago", + "daysV_plural": "__count__ days ago", + "weeksV": "__count__ week ago", + "weeksV_plural": "__count__ weeks ago", + "monthsV": "__count__ month ago", + "monthsV_plural": "__count__ months ago", + "yearsV": "__count__ year ago", + "yearsV_plural": "__count__ years ago", + + "yearMonthsV": "__y__ year, __count__ month ago", + "yearMonthsV_plural": "__y__ year, __count__ months ago", + "yearsMonthsV": "__y__ years, __count__ month ago", + "yearsMonthsV_plural": "__y__ years, __count__ months ago" + }, + "nodeCount": "__label__ node", + "nodeCount_plural": "__label__ nodes", + "inuse": "in use", + "enableall": "enable all", + "disableall": "disable all", + "enable": "enable", + "disable": "disable", + "remove": "remove", + "install": "install", + "loading": "Loading catalogues...", + "tab-nodes": "Nodes", + "tab-install": "Install", + "sort": "sort:", + "sortAZ": "a-z", + "sortRecent": "recent", + "more": "+ __count__ more", + "errors": { + "installFailed": "Failed to install: __module__
    __message__
    Check the log for more information" + } + } }, "sidebar": {