robsmart.co.uk

Emerging technology, Open Source and the Internet
  • rss
  • Home
  • About
  • Press

OpenSim Web 2.0 contribution

Rob Smart | September 14, 2008

As described over on Eightbar I have made my first contribution to the OpenSim opensource project. The contribution is in the form of a new scripting function called osParseJSON. This function allows a c# script in OpenSim to consume the JSON notation provided by many of the major Web 2.0 APIs provided by services such as Flickr and Google translation.

The following example is a script that uses the Google Translate API to let an OpenSim avatar translate ther conversations between 23 different languages.

(disclaimer – please read the terms of conditions of the Google translate API and abide by them)


//c#
// This script is written as an example use of the osParseJSON method
// it uses the Google translate API
// ensure you have read the terms and conditions of the Google translate API
// http://code.google.com/apis/ajaxlanguage/documentation/

LSL_Types.key requestID;
string sourceLang = "en";
string targetLang = "fr";

public void default_event_state_entry()
{
llSay(0,"translator running say '/1 sentence' to translate something");
llSay(0,"translator running say '/2 source langage' to change target language e.g. '/2 fr'");
llSay(0,"translator running say '/3 target langage' to change source language e.g. '/3 en'");
llSay(0,"translator running say '/4 help', to list languages");
llListen(1, "", NULL_KEY, "");
llListen(2, "", NULL_KEY, "");
llListen(3, "", NULL_KEY, "");
llListen(4, "", NULL_KEY, "");
}

public void default_event_touch_start(LSL_Types.LSLInteger total_number)
{
llSay(0,"translator running say '/1 sentence' to translate something");
llSay(0,"translator running say '/2 source langage' to change target language e.g. '/2 fr'");
llSay(0,"translator running say '/3 target langage' to change source language e.g. '/3 en'");
llSay(0,"translator running say '/4 help', to list languages");
}

public void default_event_http_response(LSL_Types.LSLString request_id, LSL_Types.LSLInteger status, LSL_Types.list metadata, LSL_Types.LSLString body)
{
if (requestID == request_id)
{
// the Google JSON string returned wil be of the format
// {"responseData": {"translatedText":"Bonjour"}, "responseDetails": null, "responseStatus": 200}
// call the osParseJSON method so we can read the contents
System.Collections.Hashtable response = (System.Collections.Hashtable) osParseJSON(body);
System.Collections.Hashtable responsedata = (System.Collections.Hashtable) response["responseData"];

llSay(0,(string)responsedata["translatedText"]);
}
}

public void default_event_listen(LSL_Types.LSLInteger channelIn, LSL_Types.LSLString name, LSL_Types.LSLString id, LSL_Types.LSLString message)
{
if(channelIn==1)
{
string toTranslate = (string) message;
requestID = llHTTPRequest( "http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q="+toTranslate+"&langpair="+sourceLang+"%7C"+targetLang, new LSL_Types.list(), "" );

}
else if(channelIn==2)
{
sourceLang = (string) message;
}
else if(channelIn==3)
{
targetLang = (string)message;
}
else if(channelIn==4)
{
llOwnerSay("LANGUAGE (CODE)");
llOwnerSay("* Arabic (ar)");
llOwnerSay("* Bulgarian (bg)");
llOwnerSay("* Chinese (zh)");
llOwnerSay("* Croatian (hr)");
llOwnerSay("* Czech (cs)");
llOwnerSay("* Danish (da)");
llOwnerSay("* Dutch (nl)");
llOwnerSay("* English (en)");
llOwnerSay("* Finnish (fi)");
llOwnerSay("* French (fr)");
llOwnerSay("* German (de)");
llOwnerSay("* Greek (el)");
llOwnerSay("* Hindi (hi)");
llOwnerSay("* Italian (it)");
llOwnerSay("* Japanese (ja)");
llOwnerSay("* Korean (ko)");
llOwnerSay("* Norwegian(no) ");
llOwnerSay("* Polish (pl)");
llOwnerSay("* Portuguese (pt-PT)");
llOwnerSay("* Romanian (ro)");
llOwnerSay("* Russian (ru)");
llOwnerSay("* Spanish (es)");
llOwnerSay("* Swedish (sv)");

}
}

Categories
Tags
c#, opensim, opensource, scripting, secondlife, translation
Comments rss
Comments rss
Trackback
Trackback

« Google ate my blog Thoughts on OpenSim, interview on UgoTrade »

6 Responses to “OpenSim Web 2.0 contribution”

  1. eightbar » Blog Archive » Web 2.0 to OpenSim made easy (JSON support added) says:
    September 14, 2008 at 10:45 pm

    [...] now I’ve written a simple example, that uses Googles translation API. The example lets you translate between 23 different [...]

  2. OpenSim Scripting Languages: LSL and OSSL « justincc’s opensim blog says:
    October 24, 2008 at 10:43 pm

    [...] good example as the HashTable return type probably makes it unusable currently in LSL scripts (the example here is a script in compiled C#).  However, I think it could be extended to return a data [...]

  3. C# scripting in OpenSim « justincc’s opensim blog says:
    November 21, 2008 at 5:40 pm

    [...] There is a more complex example of a C# script that uses osParseJSON() here. [...]

  4. pastowej says:
    July 29, 2011 at 6:20 pm

    C# is prominent nowadays. I’m learning it for a sideline income in the future.

  5. Sergio Lubo says:
    August 8, 2011 at 4:53 pm

    I use Dev OpenSim 7.0.2, running the code shows me a message “supplied then the key was not found in the dictionary”

  6. E Lawler says:
    July 13, 2012 at 1:17 am

    I doubt anyone will look at this considering the article was written so long ago,
    BUT I was wondering if it would be possible to see the code with proper formatting?

    The way it appears in my browser and when copied is as a block of text that ends up being one giant comment. I could make out the lines by putting in a basic structure but this became confusing near the end.

    I’d appreciate it.

Leave a Reply

Click here to cancel reply.

Tags

3d aberdeen anime api arabic art avatar c# drawing environment ets ets hursley ibm press flickr google hursley ibm ibm hursley ets rockets filming photography image processing jeddah lsl machinima openid opensim pervasive photography press saudi scripting secondlife security simile sony home streaming timeline transliteration twister video virtualworlds virtualworlds secondlife ibm linden wacom wacom concept art deviantart graphics wave power weather web 2.0 webmaster

  • Andy Piper
  • Dale Lane
  • Darren Shaw
  • Eightbar
  • Feeding Edge
  • Gareth Jones
  • Hannah Parker
  • Ian Hughes
  • Ian Smith
  • Irving Wladawsky-Berger
  • James Taylor
  • John Tolva
  • Kelly Smith
  • Martin Gale
  • Michael Rowe
  • Michael Rowe
  • Mo Hax
  • Nick O’Leary
  • Penny Glazzard – Zzing marketing
  • Pranab Sharma
  • Rita J. King
  • Roo Reynolds
  • Rosemary Gardening

  • Photography

Twitter feed

  • No public Twitter messages.

Recent Comments

  • try this article on Transliteration again … now complete
  • sip trunking service provider on Home VOIP system using FreeSwitch and a Linksys 3102 voice gateway (UK Guide)
  • Isobel on Transliteration again … now complete
  • Blog on The problem with OpenID
  • Check my reference on Home VOIP system using FreeSwitch and a Linksys 3102 voice gateway (UK Guide)
rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox