- 51
- 6
- Версия MoonLoader
- Другое
Hello, I have a problem updating the translated text instead of the original text. It can be saved to the cache,
but the translated text is not displayed, it is still the original text.
Здравствуйте, у меня проблема с обновлением переведенного текста вместо оригинального. Его можно сохранить в кэше,
но переведенный текст не отображается, это все еще оригинальный текст.
Search3Dtext
but the translated text is not displayed, it is still the original text.
Здравствуйте, у меня проблема с обновлением переведенного текста вместо оригинального. Его можно сохранить в кэше,
но переведенный текст не отображается, это все еще оригинальный текст.
Search3Dtext

Lua:
local translationQueue = {}
local isProcessingQueue = false
function enqueueTranslation(text, back, callback)
table.insert(translationQueue, {text = text, back = back, callback = callback})
processQueue()
end
function processQueue()
if isProcessingQueue or #translationQueue == 0 then return end
isProcessingQueue = true
local item = table.remove(translationQueue, 1)
translate(item.text, item.back, function(translatedText)
if item.callback then
item.callback(translatedText)
end
isProcessingQueue = false
processQueue()
end)
end
function translate(text, back, callback)
if translatedCache[text] then
if callback then
callback(translatedCache[text])
else
msg("Error: callback function is nil")
end
return
end
msg("Translation in progress, please wait...")
last_translation_time = os.time()
lua_thread.create(function()
local sendtext = toSendGet(text)
local ilang1, ilang2 = getlang(back)
asyncHttpRequest("GET", "https://script.google.com/macros/s/AKfycbxslVceRG2DSUHR3Jlpt69_0TXkzCU3weD2ZRK7JQXyhQYYA0bcekZ5hIqXOtwCOfoz/exec?q="..sendtext.."&source="..ilang1.."&target="..ilang2,
{},
function(response)
if response.status_code == 302 then
local redirectUrl = response.text:match('HREF="([^"]+)"')
if redirectUrl then
redirectUrl = redirectUrl:gsub('amp;', '')
asyncHttpRequest("GET", redirectUrl, {},
function(finalResponse)
if finalResponse and finalResponse.text then
msg("Final response text: " .. finalResponse.text)
local translatedText = u8:decode(finalResponse.text)
translatedCache[text] = translatedText
saveCache()
if callback then callback(translatedText) end
msg("Translation complete!")
else
msg("Final response text is empty or invalid.")
end
end,
function(err)
msg("Redirect request failed: "..tostring(err))
end)
else
msg("Redirect URL not found in response!")
end
else
msg("Request failed with status: "..tostring(response.status_code))
end
end,
function(err)
msg("Request failed: "..tostring(err))
end)
end)
end
function q.onCreate3DText(result, text, color, posX, posY, posZ, distance, ignoreWalls, player, vehicle)
if itdtext.v then
local posX, posY, posZ = getCharCoordinates(playerPed)
local res, text, color, posX, posY, posZ, distance, ignoreWalls, player, vehicle = Search3Dtext(posX, posY, posZ, 5.0, "")
if res then
if translatedCache[text] then
text = translatedCache[text]
else
local originalText = text
loadCache()
if translatedCache[originalText] then
text = translatedCache[originalText]
else
enqueueTranslation(originalText, false, function(otext)
if otext then
translatedCache[originalText] = otext
saveCache()
text = otext
if sampIs3dTextDefined(id) then
local info = { sampGet3dTextInfoById(id) }
if #info >= 9 then
sampSet3dTextString(id, text)
end
end
end
end)
end
end
end
end
return { result, text, color, posX, posY, posZ, distance, ignoreWalls, player, vehicle }
end
function Search3Dtext(x, y, z, radius, patern)
local text = ""
local color = 0
local posX = 0.0
local posY = 0.0
local posZ = 0.0
local distance = 0.0
local ignoreWalls = false
local player = -1
local vehicle = -1
local result = false
for id = 0, 2048 do
if sampIs3dTextDefined(id) then
local text2, color2, posX2, posY2, posZ2, distance2, ignoreWalls2, player2, vehicle2 = sampGet3dTextInfoById(id)
if getDistanceBetweenCoords3d(x, y, z, posX2, posY2, posZ2) < radius then
if string.len(patern) ~= 0 then
if string.match(text2, patern, 0) ~= nil then result = true end
else
result = true
end
if result then
text = text2
color = color2
posX = posX2
posY = posY2
posZ = posZ2
distance = distance2
ignoreWalls = ignoreWalls2
player = player2
vehicle = vehicle2
radius = getDistanceBetweenCoords3d(x, y, z, posX, posY, posZ)
end
end
end
end
return result, text, color, posX, posY, posZ, distance, ignoreWalls, player, vehicle
end