Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1 from madpilot/master

Add _t shortcut function
  • Loading branch information...
commit c562dc471230202b616912e8a3289a5e35ada61c 2 parents 4cbae0f + 1de9498
Dave Perrett authored November 21, 2011
12  README.markdown
Source Rendered
@@ -28,6 +28,12 @@ Once you’ve initialised it with a dictionary, you can translate strings using
28 28
 $('div#example').text($.i18n._('some text'));
29 29
 ```
30 30
 
  31
+or using $('selector')._t() function
  32
+
  33
+```javascript
  34
+$('div#example')._t('some text');
  35
+```
  36
+
31 37
 Wildcards
32 38
 ---------
33 39
 
@@ -46,6 +52,12 @@ Next, pass an array of values in as the second argument when you perform the tra
46 52
 $('div#example').text($.i18n._('wildcard example', [100, 200]));
47 53
 ```
48 54
 
  55
+or
  56
+
  57
+```javascript
  58
+$('div#example')._t('wildcard example', [100, 200]);
  59
+```
  60
+
49 61
 This will output _We have been passed two values : 100 and 200._
50 62
 
51 63
 Building From Scratch
18  jquery.i18n.js
@@ -7,7 +7,7 @@
7 7
  * Licensed under the MIT license:
8 8
  *   http://www.opensource.org/licenses/mit-license.php
9 9
  *
10  
- * Version: 0.9.1 (201012171436)
  10
+ * Version: 0.9.1 (201109152239)
11 11
  */
12 12
  (function($) {
13 13
 /**
@@ -127,5 +127,19 @@ $.i18n = {
127 127
 
128 128
 };
129 129
 
  130
+/*
  131
+ * _t
  132
+ * Allows you to translate a jQuery selector
  133
+ *
  134
+ * eg $('h1')._t('some text')
  135
+ * 
  136
+ * @param string str : The string to translate 
  137
+ * @param property_list params : params for using printf() on the string
  138
+ * @return element : chained and translated element(s)
  139
+*/
  140
+$.fn._t = function(str, params) {
  141
+  return $(this).text($.i18n._(str, params));
  142
+};
  143
+
130 144
 
131  
-})(jQuery);
  145
+})(jQuery);
16  src/jquery.i18n.js
@@ -127,5 +127,19 @@ $.i18n = {
127 127
 
128 128
 };
129 129
 
  130
+/*
  131
+ * _t
  132
+ * Allows you to translate a jQuery selector
  133
+ *
  134
+ * eg $('h1')._t('some text')
  135
+ * 
  136
+ * @param string str : The string to translate 
  137
+ * @param property_list params : params for using printf() on the string
  138
+ * @return element : chained and translated element(s)
  139
+*/
  140
+$.fn._t = function(str, params) {
  141
+  return $(this).text($.i18n._(str, params));
  142
+};
  143
+
130 144
 
131  
-})(jQuery);
  145
+})(jQuery);

0 notes on commit c562dc4

Please sign in to comment.
Something went wrong with that request. Please try again.