mirror of
https://github.com/sr229/metastruct-experiments.git
synced 2024-09-20 06:30:36 +00:00
Add language switching
This commit is contained in:
parent
bd732ecdec
commit
aba6b0cb68
1 changed files with 33 additions and 16 deletions
|
@ -2,16 +2,32 @@
|
||||||
--@author Mavain and Minori
|
--@author Mavain and Minori
|
||||||
--@client
|
--@client
|
||||||
|
|
||||||
|
local VALID_LANGS = {"en-gb", "en-ca", "en-us", "en-au", "ja", "ph", "so"}
|
||||||
|
|
||||||
local lang = "en-gb"
|
local lang = "en-gb"
|
||||||
local soundref
|
local soundref
|
||||||
|
|
||||||
|
-- A local function to check if this exists on our valid langs
|
||||||
|
-- if it doesn't, we throw error
|
||||||
|
local function has_value (tab, val)
|
||||||
|
for index, value in ipairs(tab) do
|
||||||
|
if value == val then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
hook.add("playerchat", "henkey", function(ply, txt)
|
hook.add("playerchat", "henkey", function(ply, txt)
|
||||||
if ply ~= owner() then return end
|
if ply ~= owner() then return end
|
||||||
|
|
||||||
if string.sub(txt, 1, 1) ~= ";" then return end
|
if string.sub(txt, 1, 1) ~= ";" then return end
|
||||||
txt = string.sub(txt, 2)
|
txt = string.sub(txt, 2)
|
||||||
|
|
||||||
|
if has_value(VALID_LANGS, txt) then
|
||||||
|
lang = txt
|
||||||
|
else
|
||||||
if txt:len() == 0 then return end
|
if txt:len() == 0 then return end
|
||||||
|
|
||||||
bass.loadURL("https://translate.google.com/translate_tts?ie=UTF-8&q=" .. http.urlEncode(txt) .. "&tl=" .. lang .. "&client=tw-ob", "3d",
|
bass.loadURL("https://translate.google.com/translate_tts?ie=UTF-8&q=" .. http.urlEncode(txt) .. "&tl=" .. lang .. "&client=tw-ob", "3d",
|
||||||
|
@ -28,4 +44,5 @@ hook.add("playerchat", "henkey", function(ply, txt)
|
||||||
|
|
||||||
soundref:play()
|
soundref:play()
|
||||||
end)
|
end)
|
||||||
|
end
|
||||||
end)
|
end)
|
Loading…
Reference in a new issue