make lang check overridable add nonconfigured engine shim

This commit is contained in:
Tai @ Flex 2016-12-19 11:37:22 +00:00
parent 9a152c55f5
commit 87fb400d2e
2 changed files with 38 additions and 16 deletions

View File

@ -5,8 +5,24 @@ dofile(modpath.."/http.lua" )
dofile(modpath.."/chat.lua" )
local engine = minetest.setting_get("babelfish.engine") or "yandex"
babel.key = minetest.setting_get("babelfish.key")
-- ========================== Language engine and overridable validation
function babel.validate_lang(self,langstring)
for target, langname in pairs(babel.langcodes) do
if target == langstring then
return true
end
end
return langstring.." is not a recognized language"
end
if not babel.key then engine = "none" end
dofile(modpath.."/"..engine.."_engine.lua")
-- =====================================================================/
local chat_history = {}
minetest.register_on_chat_message(function(player, message)
@ -21,16 +37,6 @@ local function components(mystring)
return targetlang, targetphrase
end
local function validate_lang(langstring)
for target, langname in pairs(babel.langcodes) do
if target == langstring then
return true
end
end
return false
end
local function validate_player(playername)
if minetest.get_player_by_name(playername) then
return true
@ -45,8 +51,9 @@ end
local function f_babel(player, argstring)
local targetplayer, targetlang = components(argstring)
if not validate_lang(targetlang) then
babel.chat_send_player(player, targetlang.." is not a recognized language")
local validation = babel:validate_lang(targetlang)
if validation ~= true then
babel.chat_send_player(player, validation)
return
end
@ -63,8 +70,9 @@ end
function f_babelshout(player, argstring)
local targetlang, targetphrase = components(argstring)
if not validate_lang(targetlang) then
babel.chat_send_player(player, targetlang.." is not a recognized language")
local validation = babel:validate_lang(targetlang)
if validation ~= true then
babel.chat_send_player(player, validation)
return
end
@ -78,8 +86,9 @@ function f_babelmsg(player, argstring)
local targetlang, targetphrase = components(argstring)
local targetplayer, targetphrase = components(targetphrase)
if not validate_lang(targetlang) then
babel.chat_send_player(player, targetlang.." is not a recognized language")
local validation = babel:validate_lang(targetlang)
if validation ~= true then
babel.chat_send_player(player, validation)
return
end

13
none_engine.lua Normal file
View File

@ -0,0 +1,13 @@
babel.engine = "none"
babel.langcodes = {}
local serviceurl = "https://example.com"
function babel.validate_lang()
return "Not configured"
end
function babel.translate(self,phrase,lang)
return "Not configured"
end