Add language switching

This commit is contained in:
Ayane 2022-06-02 22:33:54 +08:00 committed by GitHub
parent bd732ecdec
commit aba6b0cb68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,16 +2,32 @@
--@author Mavain and Minori
--@client
local VALID_LANGS = {"en-gb", "en-ca", "en-us", "en-au", "ja", "ph", "so"}
local lang = "en-gb"
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)
if ply ~= owner() then return end
if string.sub(txt, 1, 1) ~= ";" then return end
txt = string.sub(txt, 2)
if has_value(VALID_LANGS, txt) then
lang = txt
else
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",
@ -28,4 +44,5 @@ hook.add("playerchat", "henkey", function(ply, txt)
soundref:play()
end)
end
end)