Skip to content

Commit

Permalink
Localised missing strings in application.js
Browse files Browse the repository at this point in the history
  • Loading branch information
aron committed May 3, 2012
1 parent 8660c03 commit 298bbad
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
46 changes: 26 additions & 20 deletions ckan/public/scripts/application.js
Expand Up @@ -819,7 +819,7 @@ CKAN.View.ResourceAddUpload = Backbone.View.extend({
uploadFile: function(e) {
e.preventDefault();
if (!this.fileData) {
alert('No file selected');
alert(CKAN.Strings.storageNoFile);
return;
}
var jqXHR = this.fileData.submit();
Expand Down Expand Up @@ -853,8 +853,7 @@ CKAN.View.ResourceAddUpload = Backbone.View.extend({
}
, {
error: function(model, error) {
var msg = 'Filed uploaded OK but error adding resource: ' + error + '.';
msg += 'You may need to create a resource directly. Uploaded file at: ' + data._location;
var msg = CKAN.Strings.storageError.replace('%error%', error).replace('%location%', data._location);
self.setMessage(msg, 'error');
}
}
Expand Down Expand Up @@ -1159,7 +1158,11 @@ CKAN.Utils = function($, my) {
my.relatedSetup = function(form) {
$('[rel=popover]').popover();

function addAlert(msg) {
function addAlert(title, message) {
var msg = _.template('<strong><%= title %></strong> <%= msg %>', {
title: title,
msg: message
});
$('<div class="alert alert-error" />').html(msg).hide().prependTo(form).fadeIn();
}

Expand All @@ -1172,7 +1175,7 @@ CKAN.Utils = function($, my) {
data: data ? JSON.stringify(data) : undefined,
error: function(err, txt, w) {
// This needs to be far more informative.
addAlert('<strong>Error:</strong> Unable to ' + action + ' related item');
addAlert(CKAN.Strings.error, CKAN.Strings.relatedError.replace('%action%', action));
}
});
}
Expand Down Expand Up @@ -1241,20 +1244,21 @@ CKAN.Utils = function($, my) {
event.preventDefault();

// Validate the form
var form = $(this), data = {};
var form = $(this), data = {}, message;

jQuery.each(form.serializeArray(), function () {
data[this.name] = this.value;
});

form.find('.alert').remove();
form.find('.error').removeClass('error');
if (!data.title) {
addAlert('<strong>Missing field:</strong> A title is required');
addAlert(CKAN.Strings.missingField, CKAN.Strings.requiredField.replace('%field%', 'title'));
$('[name=title]').parent().addClass('error');
return;
}
if (!data.url) {
addAlert('<strong>Missing field:</strong> A url is required');
addAlert(CKAN.Strings.missingField, CKAN.Strings.requiredField.replace('%field%', 'url'));
$('[name=url]').parent().addClass('error');
return;
}
Expand Down Expand Up @@ -1422,18 +1426,19 @@ CKAN.DataPreview = function ($, my) {
// then passes the constructed Dataset, the constructed View, and the
// reclineState into the DataExplorer constructor.
my.loadEmbeddedPreview = function(resourceData, reclineState) {
my.$dialog.html('<h4>Loading ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="loading-spinner" /></h4>');

// Restore the Dataset from the given reclineState.
var dataset = recline.Model.Dataset.restore(reclineState);
var dataset = recline.Model.Dataset.restore(reclineState),
lang = CKAN.Strings;

my.$dialog.html('<h4>' + lang.loading + ' <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="loading-spinner" /></h4>');

// Only create the view defined in reclineState.currentView.
// TODO: tidy this up.
var views = null;
if (reclineState.currentView === 'grid') {
views = [ {
id: 'grid',
label: 'Grid',
label: lang.grid,
view: new recline.View.Grid({
model: dataset,
state: reclineState['view-grid']
Expand All @@ -1442,7 +1447,7 @@ CKAN.DataPreview = function ($, my) {
} else if (reclineState.currentView === 'graph') {
views = [ {
id: 'graph',
label: 'Graph',
label: lang.graph,
view: new recline.View.Graph({
model: dataset,
state: reclineState['view-graph']
Expand All @@ -1451,7 +1456,7 @@ CKAN.DataPreview = function ($, my) {
} else if (reclineState.currentView === 'map') {
views = [ {
id: 'map',
label: 'Map',
label: lang.map,
view: new recline.View.Map({
model: dataset,
state: reclineState['view-map']
Expand Down Expand Up @@ -1500,27 +1505,28 @@ CKAN.DataPreview = function ($, my) {
//
// Returns nothing.
my.loadPreviewDialog = function(resourceData) {
my.$dialog.html('<h4>Loading ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="loading-spinner" /></h4>');
var lang = CKAN.Strings;
my.$dialog.html('<h4>' + lang.loading + ' ... <img src="http://assets.okfn.org/images/icons/ajaxload-circle.gif" class="loading-spinner" /></h4>');

function initializeDataExplorer(dataset) {
var views = [
{
id: 'grid',
label: 'Grid',
label: lang.grid,
view: new recline.View.Grid({
model: dataset
})
},
{
id: 'graph',
label: 'Graph',
label: lang.graph,
view: new recline.View.Graph({
model: dataset
})
},
{
id: 'map',
label: 'Map',
label: lang.map,
view: new recline.View.Map({
model: dataset
})
Expand Down Expand Up @@ -1688,8 +1694,8 @@ CKAN.DataPreview = function ($, my) {
var timer = setTimeout(function error() {
callback({
error: {
title: 'Request Error',
message: 'Dataproxy server did not respond after ' + (timeout / 1000) + ' seconds'
title: CKAN.Strings.dataProxyGetResourceErrorTitle,
message: CKAN.Strings.dataProxyGetResourceErrorMessage.replace('%seconds%', timeout / 1000)
}
});
}, timeout);
Expand Down
14 changes: 12 additions & 2 deletions ckan/templates/js_strings.html
Expand Up @@ -39,7 +39,6 @@
documentation = _('Documentation'),
code = _('Code'),
example = _('Example'),

upload = _('Upload'),
cancel = _('Cancel'),
name = _('Name'),
Expand All @@ -60,14 +59,25 @@
edit = _('Edit'),
preview = _('Preview'),
resourceFormatPlaceholder = _('e.g. csv, html, xls, rdf, ...'),
grid = _('Grid'),
graph = _('Graph'),
map = _('Map'),
error = _('Error:'),
unknown = _('Unknown'),
requiredField = _('A %field% is required'),
missingField = _('Missing Field'),
extraFields = _('Extra Fields'),
addExtraField = _('Add Extra Field'),
deleteResource = _('Delete Resource'),
youCanUseMarkdown = _('You can use %aMarkdown formatting%b here.'),
shouldADataStoreBeEnabled = _('Should a %aDataStore table and Data API%b be enabled for this resource?'),
datesAreInISO = _('Dates are in %aISO Format%b &mdash; eg. %c2012-12-25%d or %c2010-05-31T14:30%d.'),
dataFileUploaded = _('Data File (Uploaded)')
dataFileUploaded = _('Data File (Uploaded)'),
dataProxyGetResourceErrorTitle = _('Request Error'),
dataProxyGetResourceErrorMessage = _('Dataproxy server did not respond after %seconds% seconds'),
relatedError = _('Unable to %action% related item'),
storageError = _('Filed uploaded OK but error adding resource: %error%. You may need to create a resource directly. Uploaded file at: %location%'),
storageNoFile = _('No file selected'),
), indent=4)}

</script>
Expand Down

0 comments on commit 298bbad

Please sign in to comment.