view src/translate.js.luan @ 74:64e35a92d163

add translation
author Franklin Schmidt <fschmidt@gmail.com>
date Thu, 28 Aug 2025 13:31:46 -0600
parents
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local Parsers = require "luan:Parsers.luan"
local json_string = Parsers.json_string or error()
local Io = require "luan:Io.luan"
local Http = require "luan:http/Http.luan"
local Shared = require "site:/lib/Shared.luan"
local languages = Shared.languages or error()
local Translator = require "site:/lib/ai/claude/Translator.luan"
local translate = Translator.translate or error()


return function()
	local msg = Http.request.parameters.msg or error()
	local text = Http.request.parameters.text or error()
	local language = Http.request.parameters.language or error()
	language = languages[language] or error()
	text = translate(text,language)
	Io.stdout = Http.response.text_writer()
%>
	translated('<%=msg%>',<%=json_string(text)%>);
<%
end