lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


2013/9/21 Geoff Smith <spammealot1@live.co.uk>:
> I was pondering how to automate a process that I will need in the future, it
> struck me that there is probably a neat solution using Lua. I  am fairly
> sure that this is technically possible without it being a huge amount of
> work (no new Lua API's needed)
>
> Basically I have a Lua file containing a simple table something like this
>
> local TRANSLATE_T0   = "French"
>
> local translateTable = {
> -- English                                     Foreign
>
> "The cat sat on the mat",    "Undefined"
> "The dog bit the cat",           "Undefined"
> "The cat ran off",                   "Undefined"
>
> .... repeat a few hundred lines
> }
>
> I envisaged a Lua script that reads through the rows and uses LuaSocket and
> one of the Text translation API's that exist to look up the foreign
> translated text (French in the above example) and writes it back out to a
> disk file
>
> -- English                                      Foreign
>  "The cat sat on the mat",       "Le chat assis sur le tapis"
>
> It would appear that there are bunch of API's that could potentially be used
> http://blog.programmableweb.com/2013/01/15/63-translation-apis-bing-google-translate-and-google-ajax-language/
>
> Its a shame the Google one is now a paid only service, as I would much
> prefer a free solution.
>
> I hope I don't get flamed for posting this message here, but I wondered if
> this might appeal to one of the ninja Lua coders here as a fun little
> technical challenge that they might enjoy to keep their skills honed ?
>
> My problem is twofold, I currently have no free time to work on this, and
> secondly this is probably a bit past my current skill level to be able to
> implement successfully. (I have never used LuaSocket and don't know anything
> about REST or SOAP)
>

lua-Spore fully handles the REST stuff, see http://fperrad.github.io/lua-Spore

when the Google's service was free, the following code works :

    local Spore = require 'Spore'
    local client = Spore.new_from_spec
'https://raw.github.com/SPORE/api-description/master/services/googletranslate.json'
    client:enable 'Format.JSON'
    client:enable('Parameter.Force', { key =
'===========<INSERT-YOUR-KEY>===========' })

    local r = client:translate{ source='en', target='fr', q=[[Hello World]] }
    for _, v in ipairs(r.body.data.translations) do
        print(v.translatedText)
    end

François

> Apologies, but this wouldn't be a paid gig, just posting in case it
> interests someone. Dons flame proof overall, and runs off now !!
>
> Regards Geoff
>