diff options
| author | czaks <marcin@6irc.net> | 2013-07-02 23:10:00 -0400 |
|---|---|---|
| committer | czaks <marcin@6irc.net> | 2013-07-02 23:10:00 -0400 |
| commit | 74f4c7da18aa96aecfbe92d234b09d697f7a268a (patch) | |
| tree | 04c6e8334acd9c7a421245cb27f1efb9df98f1c2 /templates | |
| parent | 7ab1ec4caa74fc017948829dbd57c91a659a4b4b (diff) | |
main.js: added preliminary translation functions for javascript
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/main.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/templates/main.js b/templates/main.js index 9ec0025f..b3e773a3 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/locale_compile.php)
+ * > alert(_("Hello!"));
+ * Witaj!
+ */
+function _(s) {
+ return (typeof tb_l10n != 'undefined' && typeof tb_l10n[s] != 'undefined') ? tb_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 = {};
|
