Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 23.08.2010
Hi i am editing a script called iTranslate and i am trying to get it to work with the inbuilt HTTP system rather that pwncurl, but i cant seem to get it to work :S
I feel there isnt enough information about the new HTTP system available.
pawn Код:
forward Inter_SendClientMessage(playerid,color,msg[]);
forward translate(playerid,string[],fromplayer);
forward iTranslate_OnPlayerConnect(playerid);
new ppl_ip[MAX_PLAYERS][32],cntryname[MAX_PLAYERS][128],preppp,preppp2,url[255];
new gettranslation[2048];
new sendtranslation[2048];
new rawdata[120000];
public iTranslate_OnPlayerConnect(playerid)
{
GetPlayerIp(playerid,ppl_ip[playerid],32);
GetCountryCode(ppl_ip[playerid], cntryname[playerid], 128);
// printf("ID %d comes from %s",playerid,cntryname[playerid]);
return 1;
}
forward MyHttpResponse(index, response_code, data[]);
public MyHttpResponse(index, response_code, data[])
{
strmid(rawdata,data,0,120000,120000);
/* preppp = strfind(data,"this.style.backgroundColor");
if(preppp == -1)
{
print(" - iTranslate Functional Error1 - ");
fremove("src.txt");
new File:handd = fopen("src.txt");
fwrite(handd,data);
fclose(handd);
return 0;
}
strdel(data,0,preppp);
strdel(data,0,9+76);
preppp2 = strfind(data,"<");
if(preppp2 == -1)
{
print(" - iTranslate Functional Error2 - ");
return 0;
}
strdel(data,preppp2,strlen(data));
//strdel(data,strlen(data)-1,strlen(data));
strpack(gettranslation,data,strlen(data));
printf("%s to %s",sendtranslation,gettranslation);*/
SendClientMessage(index,COLOR_GREEN,data);
new File:handd = fopen("src.txt");
fwrite(handd,data);
fclose(handd);
return 1;
}
public Inter_SendClientMessage(playerid,color,msg[])
{
// if(translate(playerid,msg,-1)) SendClientMessage(playerid,color,gettranslation);
// translate(playerid,msg,-1);
if(strfind(msg," ") != -1)
{
for(new lp_form=0;lp_form<=strlen(msg);lp_form++)
{
preppp = strfind(msg," ");
if(preppp == -1) break;
strdel(msg,preppp,preppp+1);
strins(msg,"+",preppp,strlen(msg));
}
}
// if(IsPlayerConnected(playerid)) format(url, 255, "%s%s%s%s%s%s%s", "http://translate.******.com/translate_t?hl=&ie=UTF-8&text=",msg,"&sl=",cntryname[playerid],"&tl=",cntryname[playerid],"#");
format(url, 255, "%s%s%s%s%s%s%s", "http://translate.******.com/translate_t?hl=&ie=UTF-8&text=",msg,"&sl=","en","&tl=",cntryname[playerid],"#");
HTTP(playerid, HTTP_GET, url, "", "MyHttpResponse");
SendClientMessage(playerid,color,rawdata);
return 1;
}
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 24.08.2010
I have been looking around and it seems like i am the first to actually try to use HTTP();
It would be nice for the wiki article to be expanded as this function could provide a HUGE advantage to server owners, also the idea of this translation is absolutely phenomenal to me, this really will be amasing!
Re: Translation of text using HTTP_GET and ****** translate -
Kyosaur - 24.08.2010
Quote:
Originally Posted by $$$PiMp
I have been looking around and it seems like i am the first to actually try to use HTTP();
It would be nice for the wiki article to be expanded as this function could provide a HUGE advantage to server owners, also the idea of this translation is absolutely phenomenal to me, this really will be amasing!
|
You're not the first, there is actually a released script using it already lol. Check it out (its an encyclopedia script, it should be of use to you).
There is also a wiki artical, but the wiki is down atm. Here it is via ******'s cache:
http://webcache.******usercontent.co...dex,+type,+url[],+data[],+callback[]%29%3B&cd=1&hl=en&ct=clnk&gl=us
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 24.08.2010
i have already checked the wiki however i dont think its enough information :S
And that encyclopedia is completely different to what i want.
I need someone who is really competent in sa-mp and someone who knows how to use HTTP, to help me :S
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
I have also tryed to get itranslate working with the new http function but it seems like the http functions only returns a redirection page o.0 I get the code 301 = moved permanently and that the http function returns is just a webpage with a link that it have moved :/
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
Hello, I bump I know but I got an good reason for it! I just made a php script that will make it possible to use the new http function with ****** translate.. Just use my webpage instead of ****** translate.. My php script takes the translation from ****** and converts it to plain text
This is an example: carnage.webffs.com/******/?msg=hej&langin=sv&langout=en
That link will translate the Swedish word "hej" to English "hi" So after msg= you insert the text you wont to translate.. after langin= you insert the lang you wont to translate from and after langout= you put the lang you wont to translate to.
Only one downside is that my php script doesn't support auto detection of langs I'm working on it but it's hard.. Also note this will be some ms slower then contacting ****** directly..
A pawno example:
new url[255];
format(url,255,"carnage.webffs.com/******/msg=%s&langin=%s&langout=%s","I'm testing","en","sv");
HTTP(fromplayer, HTTP_GET ,url, "", "TranslateChatMessage");
Re: Translation of text using HTTP_GET and ****** translate -
playbox12 - 25.08.2010
Excellent work, robanswe. Awesome!
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
Quote:
Originally Posted by playbox12
Excellent work, robanswe. Awesome!
|
No problems.. Just wont to add some info I will not close my website in a long time but if it some day gets offline just give me an pm and I will fix something or I will just give you guys the source code.. But for now stay tunned for auto detection of lang.. I have spent like 3 hours on getting the code to work at all then 1 hour of failure to get auto detect to work..
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 25.08.2010
Wow, thank you so much roban!!!
I have managed to get it to work
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
No problems and pls report any bugs.. I haven't found any but bugs have can just come sometimes
Also I will always be replaying on emails on my hotmail account
robin.jakobsson_sa-mp@hotmail.com so just send me a email if the website goes down or it it stop working..
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 25.08.2010
hmm i am now trying with this code:
pawn Code:
forward Inter_SendClientMessage(playerid,color,msg[]);
forward Inter_SendClientMessageToAll(color,msg[]);
forward iTranslate_OnPlayerConnect(playerid);
new ppl_ip[MAX_PLAYERS][32],cntryname[MAX_PLAYERS][128],url[255];
new rawdata[256];
public iTranslate_OnPlayerConnect(playerid)
{
GetPlayerIp(playerid,ppl_ip[playerid],32);
GetCountryCode(ppl_ip[playerid], cntryname[playerid], 128);
return 1;
}
forward MyHttpResponse(index, response_code, data[]);
public MyHttpResponse(index, response_code, data[])
{
strmid(rawdata,data,0,256,256);
// SendClientMessage(index,COLOR_WHITE,data);
new File:handd = fopen("src.txt");
fwrite(handd,data);
fclose(handd);
return 1;
}
public Inter_SendClientMessageToAll(color,msg[])
{
for(new i=0;i<GetMaxPlayers();i++)
{
if(IsPlayerConnected(i))
{
/* if(!strcmp(cntryname[i],"en",false))
{
SendClientMessage(i,color,msg);
}
else
{*/
format(url, 255, "%s%s", "carnage.webffs.com/******/?msg=%s&langin=%s&langout=%s",msg,"en",cntryname[i]);
HTTP(i, HTTP_GET, url, "", "MyHttpResponse");
SendClientMessage(i,color,rawdata);
// }
}
}
return 1;
}
public Inter_SendClientMessage(playerid,color,msg[])
{
/* if(!strcmp(cntryname[playerid],"en",false))
{
SendClientMessage(playerid,color,msg);
}
else
{*/
format(url, 255,"carnage.webffs.com/******/?msg=%s&langin=en&langout=hr",msg);
// format(url, 255, "%s%s", "carnage.webffs.com/******/?msg=",msg,"&langin=enlangout=",cntryname[playerid]);
HTTP(playerid, HTTP_GET, url, "", "MyHttpResponse");
SendClientMessage(playerid,color,rawdata);
// }
return 1;
}
and it only wants to show the first word of the message and its not even translated :S
BTW roban i tested your website it works good but it doesnt show characters from other countries, like it wont show german or russian characters
Re: Translation of text using HTTP_GET and ****** translate -
RyDeR` - 25.08.2010
pwncurl from Dracoblue is much better in my opinion.
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
like it wont show german or russian characters
That is a sa-mp problem isnt it? I had problems with that on the regular itranslate to.. Also sa-mp doesn't support russian characters?
RyDeR`
Pawnourl is better yes but not if you need to use it a lot.. Pwnourl stops the server from doing anything else when it is loading the website the new http function does not do that.. And that will be a big problem if you are translating all chat massages from like 30 players..
Re: Translation of text using HTTP_GET and ****** translate -
RyDeR` - 25.08.2010
Quote:
Originally Posted by robanswe
like it wont show german or russian characters
That is a sa-mp problem isnt it? I had problems with that on the regular itranslate to.. Also sa-mp doesn't support russian characters?
RyDeR`
Pawnourl is better yes but not if you need to use it a lot.. Pwnourl stops the server from doing anything else when it is loading the website the new http function does not do that.. And that will be a big problem if you are translating all chat massages from like 30 players..
|
Can be but at least you don't need some extra stuff to get it done with pwncurl.
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 25.08.2010
Quote:
Originally Posted by RyDeR`
Can be but at least you don't need some extra stuff to get it done with pwncurl.
|
The reason why we need extra stuff (This is what I think after I debugged my script..) is because the ****** translate page have some elements that http() doesn't support (I got that error massage(id:6) when using HTTP_HEAD when I used HTTP_GET it just crashed the server).. The http() is still in beta so I hope it will be fixed later on.. But relly my fix isn't bad and think like this my code do so your server needs to do less work.. My page is in plain text already the ****** translate site is not..
It seem to work for me but I sux at Russian so I doesn't know..
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 26.08.2010
no i mean your translator wont show them if i use it in firefox
Also i am only using it to translate all messages that the server sends the players, not player chat
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 26.08.2010
Quote:
Originally Posted by $$$PiMp
no i mean your translator wont show them if i use it in firefox
Also i am only using it to translate all messages that the server sends the players, not player chat
|
Thats a lot of massages to.. Also do you have russian characters installed on firefox? I doesn't know why it shoulden't work but maybe postdata doesn't like russian
Have you tryed to use normal ****** translate to see if it works there?
Test to visit this link:
http://carnage.webffs.com/******/?msg=Hey+I'm+testing&langin=en&langout=ru
Re: Translation of text using HTTP_GET and ****** translate -
$$$PiMp - 26.08.2010
on ****** it works fine, its just your script thats not processing it properly
Re: Translation of text using HTTP_GET and ****** translate -
robanswe - 26.08.2010
Ok I doesn't know if I can fix it but sa-mp can't handle Russian anyway so there is no problem really?
I will post you my script of a working translator when I'm home...
Re: Translation of text using HTTP_GET and ****** translate -
juice.j - 26.08.2010
As for German characters you can easily use workarounds, for Russian ones it would be a bit harder