summaryrefslogtreecommitdiff
path: root/templates/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'templates/main.js')
-rw-r--r--templates/main.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/templates/main.js b/templates/main.js
index b0a96393..31c0254a 100644
--- a/templates/main.js
+++ b/templates/main.js
@@ -1,5 +1,27 @@
{% raw %}
+/* gettext-compatible _ function, example of usage:
+ *
+ * > // Loading pl_PL.json here (containing polish translation strings generated by tools/i18n_compile.php)
+ * > alert(_("Hello!"));
+ * Witaj!
+ */
+function _(s) {
+ return (typeof l10n != 'undefined' && typeof l10n[s] != 'undefined') ? l10n[s] : s;
+}
+
+/* printf-like formatting function, example of usage:
+ *
+ * > alert(fmt("There are {0} birds on {1} trees", [3,4]));
+ * There are 3 birds on 4 trees
+ * > // Loading pl_PL.json here (containing polish translation strings generated by tools/locale_compile.php)
+ * > alert(fmt(_("{0} users"), [3]));
+ * 3 uzytkownikow
+ */
+function fmt(s,a) {
+ return s.replace(/\{([0-9]+)\}/g, function(x) { return a[x[1]]; });
+}
+
var saved = {};
@@ -105,7 +127,7 @@ function generatePassword() {
function dopost(form) {
if (form.elements['name']) {
- localStorage.name = form.elements['name'].value.replace(/ ##.+$/, '');
+ localStorage.name = form.elements['name'].value.replace(/( |^)## .+$/, '');
}
if (form.elements['email'] && form.elements['email'].value != 'sage') {
localStorage.email = form.elements['email'].value;