Skip to content

Instantly share code, notes, and snippets.

@blmarket
Last active February 11, 2016 07:47
Show Gist options
  • Save blmarket/056b4337b55656b1a3b1 to your computer and use it in GitHub Desktop.
Save blmarket/056b4337b55656b1a3b1 to your computer and use it in GitHub Desktop.
libtranslate NAVER service description

translate.naver.com service description file for libtranslate

HOW to use

put services.xml file into ~/.libtranslate, then naver engine is enabled

echo "안녕하세요" | translate-bin -s naver -f ko -t ja

Also, I've created node.js version of naver translation. you need to install some dependencies, npm install request raw-body command-line-args would be sufficient.

$ echo 안녕하세요 | ./trans-naver.js -f ko -t ja
{konnichiha}
$
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE services SYSTEM "services.dtd">
<services>
<service nick="naver" name="naver">
<group>
<language to="ja" tag="ko"/>
<language to="ko" tag="ja"/>
<text-translation url="http://translate.naver.com/translate.dic" post="query=${text:charset=UTF-8,escape}&amp;srcLang=${from}&amp;tarLang=${to}">
<pre-marker text="{ &quot;resultData&quot;: &quot;"/>
<post-marker text="\n&quot;"/>
</text-translation>
</group>
</service>
</services>
#!/usr/bin/env node
const request = require('request');
const rawBody = require('raw-body');
const args = require('command-line-args');
const options = args([
{ name: 'from', alias: 'f', type: String },
{ name: 'to', alias: 't', type: String }
]).parse()
if (!options.from || !options.to) {
throw new Error("from and to should be specified");
}
rawBody(process.stdin, (err, res) => {
if (err) throw err;
request.post({
uri: 'http://translate.naver.com/translate.dic',
form: {
query: res,
srcLang: options.from,
tarLang: options.to
}
}, (err, res, body) => {
if (err) throw err;
console.log(JSON.parse(body).resultData);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment