• Gmod Translator
    35 replies, posted
Here's a simple translator I made while I was bored. I though I would post it if anyone wants it. Just throw it in a lua file in lua/autorun/client. [lua]local english = "en" local spanish = "es" local german = "de" local french = "fr" local function ChatTranslate(ply, text, teamchat, isdead) Translate("fr", "en", text) end hook.Add("OnPlayerChat", "Translate", ChatTranslate) local function TranslateToChat(ply, cmd, args) local text = string.Implode(" ", args) TranslateTo("en", "fr", text) end concommand.Add("translate", TranslateToChat) function TranslateTo(from, to, text) local text = text:gsub("%s", "%%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateToCallback) end function TranslateToCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-4) local translated = string.Left(translated, string.len(translated)-1) RunConsoleCommand("say", translated) end function Translate(from, to, text) local text = text:gsub("%s", "%%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateCallback) end function TranslateCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-3) chat.AddText(translated) end[/lua] If you want me to add more to it and make it more useable, please feel free to pester me into doing so.
Nice release! Good for servers who attract non-english speaking people, adding more languages could make it purfect!
[QUOTE=CmdrMatthew;27620345]Here's a simple translator I made while I was bored. I though I would post it if anyone wants it. Just throw it in a lua file in lua/autorun/client. [lua]local english = "en" local spanish = "es" local german = "de" local french = "fr" local function ChatTranslate(ply, text, teamchat, isdead) Translate("fr", "en", text) end hook.Add("OnPlayerChat", "Translate", ChatTranslate) local function TranslateToChat(ply, cmd, args) local text = string.Implode(" ", args) TranslateTo("en", "fr", text) end concommand.Add("translate", TranslateToChat) function TranslateTo(from, to, text) local text = string.Replace(text, " ", "%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateToCallback) end function TranslateToCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-4) local translated = string.Left(translated, string.len(translated)-1) RunConsoleCommand("say", translated) end function Translate(from, to, text) local text = string.Replace(text, " ", "%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateCallback) end function TranslateCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-3) chat.AddText(translated) end[/lua] If you want me to add more to it and make it more useable, please feel free to pester me into doing so.[/QUOTE] For the love of god remove string.Replace and use gsub.
[QUOTE=Wizard of Ass;27620838]For the love of god remove string.Replace and use gsub.[/QUOTE] Could you give me an example of how to do that? When I tried it errored with invalid pattern or something like that. EDIT: Fixed. [editline]24th January 2011[/editline] Here is a serverside implementation that will automatically translate anyone who's language is set differently than yours. [lua]AddCSLuaFile("languages.lua") local languages = {} if CLIENT then local langs = {} langs["english"] = "en" langs["spanish"] = "es" langs["german"] = "de" langs["french"] = "fr" local function ChatTranslate(ply, text, teamchat, isdead) if ply:Language() == LocalPlayer():Language() then return end Translate(ply:Language(), LocalPlayer():Language(), text) end hook.Add("OnPlayerChat", "Translate", ChatTranslate) local function TranslateToChat(ply, cmd, args) local text = string.Implode(" ", args) TranslateTo("en", "fr", text) end concommand.Add("translate", TranslateToChat) function TranslateTo(from, to, text) local text = text:gsub("%s", "%%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateToCallback) end function TranslateToCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-4) local translated = string.Left(translated, string.len(translated)-1) RunConsoleCommand("say", translated) end function Translate(from, to, text) local text = text:gsub("%s", "%%20") http.Get("http://translate.google.com/translate_a/t?client=t&text="..text.."&hl="..to.."&sl="..from.."&tl="..to.."&pc=0", "", TranslateCallback) end function TranslateCallback(contents, size) local tab = string.Explode(",", contents) local translated = string.Right(tab[1], string.len(tab[1])-3) chat.AddText(translated) end languages.table = {} local meta = FindMetaTable("Player") function meta:Language() local language = languages.table[self:UniqueID()] if not language then return "en" end return langs[language] end local function recieve(msg) languages.table[msg:ReadString()] = msg:ReadString() end usermessage.Hook("LanguageData", recieve) local function prompt(msg) Derma_StringRequest("Languages", "What language do you speak?", "english", function(text) RunConsoleCommand("mylanguage", text) end) end usermessage.Hook("LanguagePrompt", prompt) else local function send(ply, lang) umsg.Start("LanguageData") umsg.String(ply:UniqueID()) umsg.String(lang) umsg.End() end function languages.set(ply, cmd, args) send(ply, args[1]) end concommand.Add("mylanguage", languages.set) function languages.prompt(ply) umsg.Start("LanguagePrompt", ply) umsg.End() end local function spawnedply(ply) if not ply.lang then ply.lang = true languages.prompt(ply) end end hook.Add("PlayerSpawn", "LanguagesPrompt", spawnedply) end[/lua] Sorry about it looking like crap, but I'm pretty sure it works.
Aha nice!
Yeah this is actually cool, now niggers, beaners, and chinks can all come and play together! [editline]23rd January 2011[/editline] inb4ban4racist [highlight](User was banned for this post ("Racism" - Swebonny))[/highlight] [highlight](User was permabanned for this post ("Extended. Breaking rules on an alt also long ban history. Will not learn." - Swebonny))[/highlight]
Thank you for not including italian. /sarcasm :colbert:
Hey italian coders don't deserve a traduction (considering they're all skids)
If anyone wants me to add the code for other languages, just ask.
[QUOTE=CmdrMatthew;27628739]If anyone wants me to add the code for other languages, just ask.[/QUOTE] Why not expand on this and make a derma, with a combo box letting you choose from which language to which?
[QUOTE=Deuces;27630995]Why not expand on this and make a derma, with a combo box letting you choose from which language to which?[/QUOTE] The serverside one has a Dialog that prompts what language you speak so the other users will have it automatically translated to their language if it is different. But I can do it to the clientside one if you wish.
[QUOTE=CmdrMatthew;27632282]The serverside one has a Dialog that prompts what language you speak so the other users will have it automatically translated to their language if it is different. But I can do it to the clientside one if you wish.[/QUOTE] Well it would be cool if there was like a combo box and a text box on the left side of the menu, in the combo box were all the languages you chose one wrote in the text box, then chose the language to translate to in another combo box on the right side then when you push GO or whatever it puts the translated text into the other textbox
Original idea to use googles translate function inside gmod. I like it!
I call this... Smart idea.
Now make one that automatically responds with answers from cleverbot. R.I.P. c-unit
R.I.P him. Well, you should make one on danish language too.
[QUOTE=Persious;27678743]R.I.P him. Well, you should make one on danish language too.[/QUOTE] lol why would he do that? thats just encouraging danish kids to come on your server and rage
Well, the fact is that many people understand danish better than English, and as you see, danish is used by many people in Garry's Mod.
English is used more..
I'm liking it, seems like it would be great to use to help aid those annoying people who talk French when you clearly state it's an English server.
I need to show this to my server owner friend badly. We get a lot of people like Dizla described.
Does this work with special characters? Because when you put special characters like korean into normal chat, they become boxes, try it.
No it does not, gmod just doesnt have the characters.
Someone shold make a module for it :)
[QUOTE=Andriko1;27720241]Someone shold make a module for it :)[/QUOTE] already been made, look up gm_memleak. Then require the module and make it leak 100 mb and you will have the special chars.
[QUOTE=I'mNotc-unit;27725251]already been made, look up gm_memleak. Then require the module and make it leak 100 mb and you will have the special chars.[/QUOTE] notseth.jpg
Hello, Could you please explain for the less technically minded people i.e. me how to "Throw this into a file" thank you, RossoOrso
[QUOTE=RossoOrso;48749469]Hello, Could you please explain for the less technically minded people i.e. me how to "Throw this into a file" thank you, RossoOrso[/QUOTE] You should probably check the last post date on a post before posting on it. You kinda bumped a 4 year old topic.
[QUOTE=xbeastguyx;48750438]You should probably check the last post date on a post before posting on it. You kinda bumped a 4 year old topic.[/QUOTE] Actually, it's great that he bumped it, I never knew this thing even existed!
Yeah Im also glad he bumped it, really good server side add-on! :goodjob: Could you add support for the russian language to be translated, if not could someone just tell me what to add to the code to allow this as I dont fully understand it! Thanks!
Sorry, you need to Log In to post a reply to this thread.