calling an api from a stack?

Mike Bonner bonnmike at gmail.com
Fri Jun 15 12:24:35 EDT 2018


/*
A quick and dirty example of using yandex translator
Fill in your key then use the 2 functions to try things out.
Put this in your card or stack script, then call the desired function
passing in the required parameters.
*/
constant kKey="put your key here"

constant kGetTransURL="
https://translate.yandex.net/api/v1.5/tr.json/translate?key=[[kKey]]&text=[[urlencode(pText)]]&lang=[[pLang]]&format=plain&options=1
"
constant kGuessLanguageUrl="
https://translate.yandex.net/api/v1.5/tr.json/detect?key=[[kKey]]&text=[[urlencode(pText)]]&hint=[[pHints]]
"

/* The translate function.
pText is the text to translate
pLange is the target language. It can either be in "source-target" version,
or just target, allowing the system to guess the source language
Returns json and pops it into the message box.
It also has the option turned on to tell you its best guess language,
so that if you use the version (for example) en-es to go from english to
spanish
you can see if it agrees with you on the source language.
If you look at the constant kGetTransUrl, you can see
that when the merge is done, the text is urlencoded as part of the merge.
Do this for all text being sent for translation/analysis.
*/

function translate pText,pLang
   get URL merge(kGetTransUrl)
   return it & cr & the result
end translate

/*
 Just tries to guess the source language.
 pText again, is the text to send
 pHints is an optional comma delimited list
 of languages that you suspect might be the source.
 IE "es,fr" It is safe to send an empty string for pHints
 and let yandex check against all languages.
*/
function guessLanguage pText,pHints
   get URL merge(kGuessLanguageUrl)
   return it & cr & the result
end guessLanguage

On Fri, Jun 15, 2018 at 8:19 AM Eric A. Engle via use-livecode <
use-livecode at lists.runrev.com> wrote:

> I am trying to make a call to the yandex translate api for a stack i am
> working on.
> i could do this pretty handily in HTML but I want to do it in livecode.
>
> I tried working with this but using yandex api instead of google
>
>
> https://stackoverflow.com/questions/35957054/is-it-possible-to-create-a-translator-in-livecode-for-my-app-which-translates-an
>
> no joy; this got me no further.
>
> https://forums.livecode.com/viewtopic.php?t=14451
>
>
> thanks for any ideas. yandex api is here
> https://tech.yandex.com/translate/
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



More information about the use-livecode mailing list