local Translate_Controller = {} local private = {} local chat_pb = require("Proto/chat_pb") function Translate_Controller.ConvertToPureText(chatMsgData) --跑马灯不需要翻译 if chatMsgData.isGameMarquee or chatMsgData.isGmMarquee then return end --自己发的消息不用翻译 if chatMsgData.fromId == BattleDataGetter.GetAcID() then return end --把超链接根据chatMsgData.templateInfo.params中的insertBeginIndex、insertEndIndex扣掉 local templateInfo = chatMsgData.templateInfo local content = chatMsgData.content if IsServerDataNotNil(templateInfo) then if templateInfo.templateId == -1 then if templateInfo.params[1] and templateInfo.params[1].paramType == MDL.ChannelChat.TemplateParamType.Arabic then content = templateInfo.params[1].param.idsOrStr return content end local templateList = {} for i, v in ipairs(templateInfo.params) do table.insert(templateList, v) end --如果只有一个模板ID并且插入index都为0,则说明整句话都是文本,不用翻译(参考势力引荐) if #templateList == 1 and templateList[1].insertBeginIndex == 0 and templateList[1].insertEndIndex == 0 then return end table.sort(templateList, private.SortTemplateByInsertIndex) for i, v in ipairs(templateList) do if v.insertBeginIndex > 0 and v.insertEndIndex > 0 then content = utf8.sub(content, 1, v.insertBeginIndex) .. utf8.sub(content, v.insertEndIndex, UTL.String.GetStrCharCount(content)) end end else return end end --正则匹配表情的字符串去掉 content = string.gsub(content, "%[%w%]", "") if not string.isNilOrEmpty(content) then return content end end function private.SortTemplateByInsertIndex(templateA, templateB) return templateA.insertBeginIndex > templateB.insertBeginIndex end return Translate_Controller