Commit c8741429 c8741429cad3227faee2b6fff169eea23d4c8f19 by Nicolas Perriault

added translate.js and translate.coffee samples

1 parent 49d45064
...@@ -35,6 +35,7 @@ casper.evaluate(function(a, b) { ...@@ -35,6 +35,7 @@ casper.evaluate(function(a, b) {
35 - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist) 35 - added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
36 - added `Tester.assertFalse()` as an alias of `Tester.assertNot()` 36 - added `Tester.assertFalse()` as an alias of `Tester.assertNot()`
37 - added `page.resource.requested` and `page.resource.received` events 37 - added `page.resource.requested` and `page.resource.received` events
38 - added [`translate.js`](https://github.com/n1k0/casperjs/tree/master/samples/translate.js) and [`translate.coffee`](https://github.com/n1k0/casperjs/tree/master/samples/translate.coffee) samples
38 39
39 2012-10-31, v1.0.0-RC4 40 2012-10-31, v1.0.0-RC4
40 ---------------------- 41 ----------------------
......
1 Subproject commit 7407e89f51ffa7c95f85c017654a82de86239a17 1 Subproject commit cd0d5fc3efd4279e0ac4062d012cb16d77cbc708
......
1 ###
2 Translation using the Google Translate Service.
3
4 Usage:
5
6 $ casperjs translate.coffee --target=fr "hello world"
7 bonjour tout le monde
8 ###
9 system = require("system")
10 casper = require("casper").create()
11 format = require("utils").format
12 source = casper.cli.get("source") or "auto"
13 target = casper.cli.get("target")
14 text = casper.cli.get(0)
15 result = undefined
16
17 casper.warn("The --target option is mandatory.").exit 1 unless target
18
19 casper.start(format("http://translate.google.com/#%s/%s/%s", source, target, text), ->
20 @fill "form#gt-form", text: text
21 ).waitForSelector "span.hps", -> @echo @fetchText("#result_box")
22
23 casper.run()
1 /**
2 * Translation using the Google Translate Service.
3 *
4 * Usage:
5 *
6 * $ casperjs translate.js --target=fr "hello world"
7 * bonjour tout le monde
8 */
9 var system = require('system'),
10 casper = require('casper').create(),
11 format = require('utils').format,
12 source = casper.cli.get('source') || 'auto',
13 target = casper.cli.get('target'),
14 text = casper.cli.get(0),
15 result;
16
17 if (!target) {
18 casper.warn('The --target option is mandatory.').exit(1);
19 }
20
21 casper.start(format('http://translate.google.com/#%s/%s/%s', source, target, text), function() {
22 this.fill('form#gt-form', {text: text});
23 }).waitForSelector('span.hps', function() {
24 this.echo(this.fetchText("#result_box"));
25 });
26
27 casper.run();