i18n_screwdriver 8.1 → 9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3bcf4a98f37390d173a9fa6a82f3c595c17c98b4
4
- data.tar.gz: 74c3c6b1abf2d63d27c1a081033f782c15af896d
3
+ metadata.gz: ae34d34467f474ed51aaf14508a7569f50e84d44
4
+ data.tar.gz: b1935c8c5f8743e349e097ee4cd83cf8aa3b7f55
5
5
  SHA512:
6
- metadata.gz: d92d15d612024f28392ebd6bf74f8951826a53842cb70ff0e2d5aeff5f6cbf5354c7893cb2ee8112179fe0d164fab85428a40299cb59a4cd4c7266963448a31d
7
- data.tar.gz: d56782ac7f4b2b693b3cd741dfa9acb4f9a7a13d824159390668dc4186137419bb9768d00dea432c4dee2d7178b73591a51b32918377b788baca9d379350bd5b
6
+ metadata.gz: 4acb1cb5883d7069a673a3363a1d1a30689f6504bcc5db65f284e9a73d1e70b6de16c4f0a4d3622bb14fa78d5dfbcd83d01cb28c063203623ad014a1a075bedc
7
+ data.tar.gz: 47ca12e1726ee22647a04b8fb7a243d579ffafdbd0c325cd3c7d7ea23d75d540c5f56fd3ebc69bff0655595ad12bf3021b861eedbc1fb139bb1a30e0910b42d1
@@ -0,0 +1 @@
1
+ I18n.locale = $("html").attr("lang")
@@ -0,0 +1,276 @@
1
+ /*
2
+ * JavaScript MD5
3
+ * https://github.com/blueimp/JavaScript-MD5
4
+ *
5
+ * Copyright 2011, Sebastian Tschan
6
+ * https://blueimp.net
7
+ *
8
+ * Licensed under the MIT license:
9
+ * http://www.opensource.org/licenses/MIT
10
+ *
11
+ * Based on
12
+ * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
13
+ * Digest Algorithm, as defined in RFC 1321.
14
+ * Version 2.2 Copyright (C) Paul Johnston 1999 - 2009
15
+ * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
16
+ * Distributed under the BSD License
17
+ * See http://pajhome.org.uk/crypt/md5 for more info.
18
+ */
19
+
20
+ /*jslint bitwise: true */
21
+ /*global unescape, define, module */
22
+
23
+ (function ($) {
24
+ 'use strict';
25
+
26
+ /*
27
+ * Add integers, wrapping at 2^32. This uses 16-bit operations internally
28
+ * to work around bugs in some JS interpreters.
29
+ */
30
+ function safe_add(x, y) {
31
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
32
+ msw = (x >> 16) + (y >> 16) + (lsw >> 16);
33
+ return (msw << 16) | (lsw & 0xFFFF);
34
+ }
35
+
36
+ /*
37
+ * Bitwise rotate a 32-bit number to the left.
38
+ */
39
+ function bit_rol(num, cnt) {
40
+ return (num << cnt) | (num >>> (32 - cnt));
41
+ }
42
+
43
+ /*
44
+ * These functions implement the four basic operations the algorithm uses.
45
+ */
46
+ function md5_cmn(q, a, b, x, s, t) {
47
+ return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
48
+ }
49
+ function md5_ff(a, b, c, d, x, s, t) {
50
+ return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
51
+ }
52
+ function md5_gg(a, b, c, d, x, s, t) {
53
+ return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
54
+ }
55
+ function md5_hh(a, b, c, d, x, s, t) {
56
+ return md5_cmn(b ^ c ^ d, a, b, x, s, t);
57
+ }
58
+ function md5_ii(a, b, c, d, x, s, t) {
59
+ return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
60
+ }
61
+
62
+ /*
63
+ * Calculate the MD5 of an array of little-endian words, and a bit length.
64
+ */
65
+ function binl_md5(x, len) {
66
+ /* append padding */
67
+ x[len >> 5] |= 0x80 << (len % 32);
68
+ x[(((len + 64) >>> 9) << 4) + 14] = len;
69
+
70
+ var i, olda, oldb, oldc, oldd,
71
+ a = 1732584193,
72
+ b = -271733879,
73
+ c = -1732584194,
74
+ d = 271733878;
75
+
76
+ for (i = 0; i < x.length; i += 16) {
77
+ olda = a;
78
+ oldb = b;
79
+ oldc = c;
80
+ oldd = d;
81
+
82
+ a = md5_ff(a, b, c, d, x[i], 7, -680876936);
83
+ d = md5_ff(d, a, b, c, x[i + 1], 12, -389564586);
84
+ c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
85
+ b = md5_ff(b, c, d, a, x[i + 3], 22, -1044525330);
86
+ a = md5_ff(a, b, c, d, x[i + 4], 7, -176418897);
87
+ d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
88
+ c = md5_ff(c, d, a, b, x[i + 6], 17, -1473231341);
89
+ b = md5_ff(b, c, d, a, x[i + 7], 22, -45705983);
90
+ a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
91
+ d = md5_ff(d, a, b, c, x[i + 9], 12, -1958414417);
92
+ c = md5_ff(c, d, a, b, x[i + 10], 17, -42063);
93
+ b = md5_ff(b, c, d, a, x[i + 11], 22, -1990404162);
94
+ a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
95
+ d = md5_ff(d, a, b, c, x[i + 13], 12, -40341101);
96
+ c = md5_ff(c, d, a, b, x[i + 14], 17, -1502002290);
97
+ b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
98
+
99
+ a = md5_gg(a, b, c, d, x[i + 1], 5, -165796510);
100
+ d = md5_gg(d, a, b, c, x[i + 6], 9, -1069501632);
101
+ c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
102
+ b = md5_gg(b, c, d, a, x[i], 20, -373897302);
103
+ a = md5_gg(a, b, c, d, x[i + 5], 5, -701558691);
104
+ d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
105
+ c = md5_gg(c, d, a, b, x[i + 15], 14, -660478335);
106
+ b = md5_gg(b, c, d, a, x[i + 4], 20, -405537848);
107
+ a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
108
+ d = md5_gg(d, a, b, c, x[i + 14], 9, -1019803690);
109
+ c = md5_gg(c, d, a, b, x[i + 3], 14, -187363961);
110
+ b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
111
+ a = md5_gg(a, b, c, d, x[i + 13], 5, -1444681467);
112
+ d = md5_gg(d, a, b, c, x[i + 2], 9, -51403784);
113
+ c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
114
+ b = md5_gg(b, c, d, a, x[i + 12], 20, -1926607734);
115
+
116
+ a = md5_hh(a, b, c, d, x[i + 5], 4, -378558);
117
+ d = md5_hh(d, a, b, c, x[i + 8], 11, -2022574463);
118
+ c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
119
+ b = md5_hh(b, c, d, a, x[i + 14], 23, -35309556);
120
+ a = md5_hh(a, b, c, d, x[i + 1], 4, -1530992060);
121
+ d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
122
+ c = md5_hh(c, d, a, b, x[i + 7], 16, -155497632);
123
+ b = md5_hh(b, c, d, a, x[i + 10], 23, -1094730640);
124
+ a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
125
+ d = md5_hh(d, a, b, c, x[i], 11, -358537222);
126
+ c = md5_hh(c, d, a, b, x[i + 3], 16, -722521979);
127
+ b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
128
+ a = md5_hh(a, b, c, d, x[i + 9], 4, -640364487);
129
+ d = md5_hh(d, a, b, c, x[i + 12], 11, -421815835);
130
+ c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
131
+ b = md5_hh(b, c, d, a, x[i + 2], 23, -995338651);
132
+
133
+ a = md5_ii(a, b, c, d, x[i], 6, -198630844);
134
+ d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
135
+ c = md5_ii(c, d, a, b, x[i + 14], 15, -1416354905);
136
+ b = md5_ii(b, c, d, a, x[i + 5], 21, -57434055);
137
+ a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
138
+ d = md5_ii(d, a, b, c, x[i + 3], 10, -1894986606);
139
+ c = md5_ii(c, d, a, b, x[i + 10], 15, -1051523);
140
+ b = md5_ii(b, c, d, a, x[i + 1], 21, -2054922799);
141
+ a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
142
+ d = md5_ii(d, a, b, c, x[i + 15], 10, -30611744);
143
+ c = md5_ii(c, d, a, b, x[i + 6], 15, -1560198380);
144
+ b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
145
+ a = md5_ii(a, b, c, d, x[i + 4], 6, -145523070);
146
+ d = md5_ii(d, a, b, c, x[i + 11], 10, -1120210379);
147
+ c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
148
+ b = md5_ii(b, c, d, a, x[i + 9], 21, -343485551);
149
+
150
+ a = safe_add(a, olda);
151
+ b = safe_add(b, oldb);
152
+ c = safe_add(c, oldc);
153
+ d = safe_add(d, oldd);
154
+ }
155
+ return [a, b, c, d];
156
+ }
157
+
158
+ /*
159
+ * Convert an array of little-endian words to a string
160
+ */
161
+ function binl2rstr(input) {
162
+ var i,
163
+ output = '';
164
+ for (i = 0; i < input.length * 32; i += 8) {
165
+ output += String.fromCharCode((input[i >> 5] >>> (i % 32)) & 0xFF);
166
+ }
167
+ return output;
168
+ }
169
+
170
+ /*
171
+ * Convert a raw string to an array of little-endian words
172
+ * Characters >255 have their high-byte silently ignored.
173
+ */
174
+ function rstr2binl(input) {
175
+ var i,
176
+ output = [];
177
+ output[(input.length >> 2) - 1] = undefined;
178
+ for (i = 0; i < output.length; i += 1) {
179
+ output[i] = 0;
180
+ }
181
+ for (i = 0; i < input.length * 8; i += 8) {
182
+ output[i >> 5] |= (input.charCodeAt(i / 8) & 0xFF) << (i % 32);
183
+ }
184
+ return output;
185
+ }
186
+
187
+ /*
188
+ * Calculate the MD5 of a raw string
189
+ */
190
+ function rstr_md5(s) {
191
+ return binl2rstr(binl_md5(rstr2binl(s), s.length * 8));
192
+ }
193
+
194
+ /*
195
+ * Calculate the HMAC-MD5, of a key and some data (raw strings)
196
+ */
197
+ function rstr_hmac_md5(key, data) {
198
+ var i,
199
+ bkey = rstr2binl(key),
200
+ ipad = [],
201
+ opad = [],
202
+ hash;
203
+ ipad[15] = opad[15] = undefined;
204
+ if (bkey.length > 16) {
205
+ bkey = binl_md5(bkey, key.length * 8);
206
+ }
207
+ for (i = 0; i < 16; i += 1) {
208
+ ipad[i] = bkey[i] ^ 0x36363636;
209
+ opad[i] = bkey[i] ^ 0x5C5C5C5C;
210
+ }
211
+ hash = binl_md5(ipad.concat(rstr2binl(data)), 512 + data.length * 8);
212
+ return binl2rstr(binl_md5(opad.concat(hash), 512 + 128));
213
+ }
214
+
215
+ /*
216
+ * Convert a raw string to a hex string
217
+ */
218
+ function rstr2hex(input) {
219
+ var hex_tab = '0123456789abcdef',
220
+ output = '',
221
+ x,
222
+ i;
223
+ for (i = 0; i < input.length; i += 1) {
224
+ x = input.charCodeAt(i);
225
+ output += hex_tab.charAt((x >>> 4) & 0x0F) +
226
+ hex_tab.charAt(x & 0x0F);
227
+ }
228
+ return output;
229
+ }
230
+
231
+ /*
232
+ * Encode a string as utf-8
233
+ */
234
+ function str2rstr_utf8(input) {
235
+ return unescape(encodeURIComponent(input));
236
+ }
237
+
238
+ /*
239
+ * Take string arguments and return either raw or hex encoded strings
240
+ */
241
+ function raw_md5(s) {
242
+ return rstr_md5(str2rstr_utf8(s));
243
+ }
244
+ function hex_md5(s) {
245
+ return rstr2hex(raw_md5(s));
246
+ }
247
+ function raw_hmac_md5(k, d) {
248
+ return rstr_hmac_md5(str2rstr_utf8(k), str2rstr_utf8(d));
249
+ }
250
+ function hex_hmac_md5(k, d) {
251
+ return rstr2hex(raw_hmac_md5(k, d));
252
+ }
253
+
254
+ function md5(string, key, raw) {
255
+ if (!key) {
256
+ if (!raw) {
257
+ return hex_md5(string);
258
+ }
259
+ return raw_md5(string);
260
+ }
261
+ if (!raw) {
262
+ return hex_hmac_md5(key, string);
263
+ }
264
+ return raw_hmac_md5(key, string);
265
+ }
266
+
267
+ if (typeof define === 'function' && define.amd) {
268
+ define(function () {
269
+ return md5;
270
+ });
271
+ } else if (typeof module === 'object' && module.exports) {
272
+ module.exports = md5;
273
+ } else {
274
+ $.md5 = md5;
275
+ }
276
+ }(this));
@@ -0,0 +1,10 @@
1
+ #= require i18n_screwdriver/md5
2
+
3
+ interpolate = (message, data) ->
4
+ message.replace(/%{([^{}]*)}/g, (a, b) -> data[b])
5
+
6
+ I18n.screw = (message, data) ->
7
+ md5 = window.md5(message)
8
+ translation = I18n.translations[I18n.locale][md5]
9
+ translation ?= ""
10
+ interpolate(translation, data)
@@ -45,6 +45,13 @@ module I18nScrewdriver
45
45
  string.scan(/_\((:[a-z][a-z0-9_]*)\)/).flatten
46
46
  end
47
47
 
48
+ def self.grab_js_texts_to_be_translated(string)
49
+ [].tap do |texts|
50
+ texts.concat(string.scan(/\bI18n\.screw\(?\s*(?<!\\)"(.*?)(?<!\\)"/).map{ |v| unescape_string(v[0]) })
51
+ texts.concat(string.scan(/\bI18n\.screw\(?\s*(?<!\\)'(.*?)(?<!\\)'/).map{ |v| unescape_string(v[0]) })
52
+ end
53
+ end
54
+
48
55
  def self.in_utf8(hash)
49
56
  {}.tap do |result|
50
57
  hash.sort.each do |k, v|
@@ -87,11 +94,18 @@ module I18nScrewdriver
87
94
  def self.gather_translations
88
95
  texts = []
89
96
  symbols = []
97
+
90
98
  Dir.glob("**/*.{haml,erb,slim,rb}").each do |file|
91
99
  input = File.read(file)
92
100
  texts.concat(grab_texts_to_be_translated(input))
93
101
  symbols.concat(grab_symbols_to_be_translated(input))
94
102
  end
103
+
104
+ Dir.glob("**/*.{js,coffee,hamlc,ejs,erb}").each do |file|
105
+ input = File.read(file)
106
+ texts.concat(grab_js_texts_to_be_translated(input))
107
+ end
108
+
95
109
  translations = Hash[texts.uniq.map{ |text| [generate_key(text), extract_text(text)] }]
96
110
  translations.merge(Hash[symbols.uniq.map{ |symbol| [generate_key(symbol), ""] }])
97
111
  end
@@ -1,3 +1,3 @@
1
1
  module I18nScrewdriver
2
- VERSION = "8.1"
2
+ VERSION = "9.0"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe I18nScrewdriver do
4
+ describe "grab_js_texts_to_be_translated" do
5
+ it "properly parses the passed string" do
6
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw("test!")|)).to eq(["test!"])
7
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw( "test!")|)).to eq(["test!"])
8
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw("Hi %{name}!", name: "gucki")|)).to eq(["Hi %{name}!"])
9
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw "test!"|)).to eq(["test!"])
10
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw "Hi %{name}!", name: "gucki"|)).to eq(["Hi %{name}!"])
11
+
12
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw('test!')|)).to eq(["test!"])
13
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw( 'test!')|)).to eq(["test!"])
14
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw('Hi %{name}!', name: "gucki")|)).to eq(["Hi %{name}!"])
15
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw 'test!'|)).to eq(["test!"])
16
+ expect(I18nScrewdriver.grab_js_texts_to_be_translated(%|=I18n.screw 'Hi %{name}!', name: "gucki"|)).to eq(["Hi %{name}!"])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ require "bundler/setup"
2
+ Bundler.setup
3
+
4
+ require "i18n_screwdriver"
5
+
6
+ RSpec.configure do |config|
7
+ # some (optional) config here
8
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: i18n_screwdriver
3
3
  version: !ruby/object:Gem::Version
4
- version: '8.1'
4
+ version: '9.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Miesel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-02-04 00:00:00.000000000 Z
12
+ date: 2016-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -53,6 +53,9 @@ files:
53
53
  - LICENSE.txt
54
54
  - README.rdoc
55
55
  - Rakefile
56
+ - app/assets/javascrips/i18n_screwdriver/config.coffee
57
+ - app/assets/javascrips/i18n_screwdriver/md5.js
58
+ - app/assets/javascrips/i18n_screwdriver/screw.coffee
56
59
  - i18n_screwdriver.gemspec
57
60
  - lib/i18n_screwdriver.rb
58
61
  - lib/i18n_screwdriver/rails.rb
@@ -61,6 +64,8 @@ files:
61
64
  - lib/i18n_screwdriver/translation_helper.rb
62
65
  - lib/i18n_screwdriver/version.rb
63
66
  - lib/tasks/i18n.rake
67
+ - spec/i18n_screwdriver_spec.rb
68
+ - spec/spec_helper.rb
64
69
  homepage: https://github.com/agileapplications/i18n_screwdriver
65
70
  licenses:
66
71
  - MIT