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) {
- added [`Tester.assertTextDoesntExist()`](http://casperjs.org/api.html#tester.assertTextDoesntExist)
- added `Tester.assertFalse()` as an alias of `Tester.assertNot()`
- added `page.resource.requested` and `page.resource.received` events
- 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
2012-10-31, v1.0.0-RC4
----------------------
......
Subproject commit 7407e89f51ffa7c95f85c017654a82de86239a17
Subproject commit cd0d5fc3efd4279e0ac4062d012cb16d77cbc708
......
###
Translation using the Google Translate Service.
Usage:
$ casperjs translate.coffee --target=fr "hello world"
bonjour tout le monde
###
system = require("system")
casper = require("casper").create()
format = require("utils").format
source = casper.cli.get("source") or "auto"
target = casper.cli.get("target")
text = casper.cli.get(0)
result = undefined
casper.warn("The --target option is mandatory.").exit 1 unless target
casper.start(format("http://translate.google.com/#%s/%s/%s", source, target, text), ->
@fill "form#gt-form", text: text
).waitForSelector "span.hps", -> @echo @fetchText("#result_box")
casper.run()
/**
* Translation using the Google Translate Service.
*
* Usage:
*
* $ casperjs translate.js --target=fr "hello world"
* bonjour tout le monde
*/
var system = require('system'),
casper = require('casper').create(),
format = require('utils').format,
source = casper.cli.get('source') || 'auto',
target = casper.cli.get('target'),
text = casper.cli.get(0),
result;
if (!target) {
casper.warn('The --target option is mandatory.').exit(1);
}
casper.start(format('http://translate.google.com/#%s/%s/%s', source, target, text), function() {
this.fill('form#gt-form', {text: text});
}).waitForSelector('span.hps', function() {
this.echo(this.fetchText("#result_box"));
});
casper.run();