Skip to content

Commit

Permalink
Automatic extraction of translatable strings using xgettext possible.…
Browse files Browse the repository at this point in the history
… It uses the new stellarium-remotecontrol domain. Strings that are already present in the stellarium domain are automatically excluded, if possible, to reduce duplication issues.

Translations now use PHP-style tags, i.e. <?= tr("Translation") ?>, this allows xgettext support.
Translations support optional placeholder arguments (  <?= tr("This %1 will be", "replaced") ?> )
Translation from JS code using the Main.tr method. This requires converting the xgettext-extracted strings to JS file which can then be used as a template to be filled with translated values by the server. The conversion is done by a python script through the RemoteControl-update-translationdata target.
Made JS code pass JSHint validation
  • Loading branch information
fschauk committed Jul 13, 2015
1 parent ba58a5d commit 4091a02
Show file tree
Hide file tree
Showing 25 changed files with 1,006 additions and 187 deletions.
20 changes: 11 additions & 9 deletions data/webroot/actions.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"use strict";

var Actions = (new function ($) {

var Actions = (function ($) {
"use strict";

//Private variables
var $actionlist;
var actionsInitialized = false;
Expand Down Expand Up @@ -63,7 +65,7 @@ var Actions = (new function ($) {
var id = e.options[e.selectedIndex].value;

Actions.execute(id);
}
};

$actionlist.change(function () {
$("#bt_doaction").prop("disabled", false);
Expand Down Expand Up @@ -170,9 +172,9 @@ var Actions = (new function ($) {
},
error: function (xhr, status, errorThrown) {
console.log("Error updating action list");
console.log("Error: " + errorThrown);
console.log("Error: " + errorThrown.message);
console.log("Status: " + status);
alert("Could not retrieve action list")
alert(Main.tr("Could not retrieve action list"));
}
});
}
Expand Down Expand Up @@ -205,9 +207,9 @@ var Actions = (new function ($) {
},
error: function (xhr, status, errorThrown) {
console.log("Error posting action " + actionName);
console.log("Error: " + errorThrown);
console.log("Error: " + errorThrown.message);
console.log("Status: " + status);
alert("Could not call server")
alert(Main.tr("Error sending action to server: ") + errorThrown.message);
}
});
}
Expand Down Expand Up @@ -292,5 +294,5 @@ var Actions = (new function ($) {

//Connects all checkbox input elements below this container to the StelAction that corresponds to its value
connectActionContainer: connectActionContainer
}
}(jQuery));
};
})(jQuery);
147 changes: 74 additions & 73 deletions data/webroot/index.html

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions data/webroot/location.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
var Locations = (function($) {
"use strict";

var Locations = (new function($) {
//Private variables
var $loc_mapimg;
var $loc_mappointer;
Expand Down Expand Up @@ -73,7 +73,7 @@ var Locations = (new function($) {
editMode = false;
});

scope = "input.ui-spinner-input"
scope = "input.ui-spinner-input";
$("#loc_inputs").on("spin", scope, function(evt, ui) {
var field = $(this).data("field");
queueData(field,ui.value);
Expand Down Expand Up @@ -149,7 +149,7 @@ var Locations = (new function($) {
var op = document.createElement("option");
op.innerHTML = data[i];
$loc_list[0].appendChild(op);
};
}

parent.prepend($loc_list);

Expand All @@ -158,9 +158,9 @@ var Locations = (new function($) {
},
error: function(xhr, status, errorThrown) {
console.log("Error updating location list");
console.log("Error: " + errorThrown);
console.log("Error: " + errorThrown.message);
console.log("Status: " + status);
alert("Could not retrieve location list");
alert(Main.tr("Could not retrieve location list"));
}
});
}
Expand Down Expand Up @@ -193,15 +193,15 @@ var Locations = (new function($) {
op.innerHTML = data[i].name_i18n; //translated
op.value = data[i].name;
$loc_country[0].appendChild(op);
};
}

parent.append($loc_country);
},
error: function(xhr, status, errorThrown) {
console.log("Error updating country list");
console.log("Error: " + errorThrown);
console.log("Error: " + errorThrown.message);
console.log("Status: " + status);
alert("Could not retrieve country list");
alert(Main.tr("Could not retrieve country list"));
}
});
}
Expand All @@ -223,15 +223,15 @@ var Locations = (new function($) {
op.innerHTML = data[i].name_i18n; //translated
op.value = data[i].name;
$loc_planet[0].appendChild(op);
};
}

parent.append($loc_planet);
},
error: function(xhr, status, errorThrown) {
console.log("Error updating planet list");
console.log("Error: " + errorThrown);
console.log("Status: " + status);
alert("Could not retrieve planet list");
alert(Main.tr("Could not retrieve planet list"));
}
});
}
Expand Down Expand Up @@ -296,5 +296,5 @@ var Locations = (new function($) {
movePointer(loc.latitude, loc.longitude);
}
}
}
}(jQuery));
};
})(jQuery);
60 changes: 37 additions & 23 deletions data/webroot/remotecontrol.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
"use strict";
/* jshint expr: true */

var UISettings = (new function($) {
var UISettings = (function() {
"use strict";

var data = {};

// Automatically poll the server for updates? Otherwise, only updated after commands are sent.
this.updatePoll = true;
data.updatePoll = true;
//the interval for automatic polling
this.updateInterval = 1000;
data.updateInterval = 1000;
//use the Browser's requestAnimationFrame for animation instead of setTimeout
this.useAnimationFrame = true;
data.useAnimationFrame = true;
//If animation frame is not used, this is the delay between 2 animation steps
this.animationDelay = 500;
data.animationDelay = 500;
//If no user changes happen after this time, the changes are sent to the Server
this.editUpdateDelay = 500;
data.editUpdateDelay = 500;
//This is the delay after which the AJAX request spinner is shown.
this.spinnerDelay = 100;

data.spinnerDelay = 100;

}(jQuery));
return data;
})();

//DOM-ready hook, starting the GUI
$(document).ready(function() {
Expand All @@ -38,7 +41,9 @@ $(window).load(function() {
});

// The main functionality including communication with the server
var Main = (new function($) {
var Main = (function($) {
"use strict";

//Private variables
var connectionLost = false;
var animationSupported;
Expand All @@ -53,6 +58,15 @@ var Main = (new function($) {

var sel_infostring;

/* Translates a string using Stellariums current locale. String must be present in translationdata.js */
function tr(str) {
if(str in TranslationData) {
return TranslationData[str];
}
console.log("Error: string '" +str + "' not present in translation data");
return str;
}

function animate() {

Time.updateAnimation();
Expand Down Expand Up @@ -85,7 +99,7 @@ var Main = (new function($) {
sel_infostring.innerHTML = data.selectioninfo;
sel_infostring.className = "";
} else {
sel_infostring.innerHTML = "No current selection";
sel_infostring.innerHTML = tr("No current selection");
sel_infostring.className = "bold";
}

Expand Down Expand Up @@ -144,7 +158,7 @@ var Main = (new function($) {
// Firefox wraps long text (possibly a rounding bug)
// so we add 1px to avoid the wrapping (#7513)
ul.width("").outerWidth() + 1,
this.options.position.of == null ? this.element.outerWidth() : this.options.position.of.outerWidth()
this.options.position.of === null ? this.element.outerWidth() : this.options.position.of.outerWidth()
));
}
});
Expand Down Expand Up @@ -240,11 +254,11 @@ var Main = (new function($) {
}
}, this));
}, this), UISettings.editUpdateDelay);

};

//Public stuff
return {
tr: tr,
init: function() {
initControls();

Expand All @@ -261,9 +275,9 @@ var Main = (new function($) {
animationSupported = (window.requestAnimationFrame !== undefined);

if (!animationSupported) {
console.log("animation frame not supported")
console.log("animation frame not supported");
} else {
console.log("animation frame supported")
console.log("animation frame supported");
}
//kick off animation
animate();
Expand Down Expand Up @@ -294,7 +308,7 @@ var Main = (new function($) {
console.log("Error posting command " + url);
console.log("Error: " + errorThrown);
console.log("Status: " + status);
alert("Could not update the server!")
alert(tr("Error sending command to server: ") + errorThrown.message);
},
complete: completeFunc
});
Expand All @@ -303,15 +317,15 @@ var Main = (new function($) {
forceUpdate: function() {
update();
},

UpdateQueue: UpdateQueue

}
}(jQuery));
};
})(jQuery);


//some custom controls
(function($) {
"use strict";

$.widget("custom.combobox", {
_create: function() {
this.wrapper = $("<span>")
Expand Down Expand Up @@ -366,7 +380,7 @@ var Main = (new function($) {

$("<a>")
.attr("tabIndex", -1)
.attr("title", "Show All Items")
.attr("title", Main.tr("Show All Items"))
.tooltip()
.appendTo(this.wrapper)
.button({
Expand Down Expand Up @@ -432,7 +446,7 @@ var Main = (new function($) {
// Remove invalid value
this.input
.val("")
.attr("title", value + " didn't match any item")
.attr("title", Main.tr("Input did not match any item"))
.tooltip("open");
this.element.val("");
this._delay(function() {
Expand Down
12 changes: 6 additions & 6 deletions data/webroot/scripts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";
var Scripts = (function($) {
"use strict";

var Scripts = (new function($) {
//Private variables
var $activescript;
var $bt_runscript;
Expand Down Expand Up @@ -61,7 +61,7 @@ var Scripts = (new function($) {
console.log("Error updating script list");
console.log("Error: " + errorThrown);
console.log("Status: " + status);
alert("Could not retrieve script list")
alert(Main.tr("Could not retrieve script list"));
}
});
},
Expand All @@ -70,11 +70,11 @@ var Scripts = (new function($) {
if (script.scriptIsRunning) {
$activescript.text(script.runningScriptId);
} else {
$activescript.text("-none-");
$activescript.text(Main.tr("-none-"));
}
$bt_stopscript.prop({
disabled: !script.scriptIsRunning
});
}
}
}(jQuery));
};
})(jQuery);
Loading

0 comments on commit 4091a02

Please sign in to comment.