【本地化】随机名字本地化

dev_chengFeng
ZhangBiao 2021-03-05 14:32:29 +08:00
parent fec790a1e0
commit 8dadc2d54b
2 changed files with 39 additions and 0 deletions

View File

@ -1635,6 +1635,37 @@ function LengthString(inputstr)
end
return width
end
--获取中文一段话的所有单个文字
function GetSingleWordInString(inputstr)
if not inputstr or inputstr == "" then
return
end
local lenInByte = #inputstr
local width = 0
local i = 1
local outputstr={}
while (i<=lenInByte)
do
local curByte = string.byte(inputstr, i)
local byteCount = 1;
if curByte>0 and curByte<=127 then
byteCount = 1 --1字节字符
elseif curByte>=192 and curByte<223 then
byteCount = 2 --双字节字符
elseif curByte>=224 and curByte<239 then
byteCount = 3 --汉字
elseif curByte>=240 and curByte<=247 then
byteCount = 4 --4字节字符
end
local char = string.sub(inputstr, i, i+byteCount-1)
outputstr[width+1] = char
i = i + byteCount -- 重置下一字节的索引
width = width + 1
end
return outputstr
end
--都截取长度
function SubString(inputstr,num)
local num = num and num or 0

View File

@ -229,6 +229,14 @@ end
-- 随机名称显示
function CreateNamePopup.OnRefreshName(randomName)
if GetCurLanguage() ~= 0 then
local str = GetSingleWordInString(randomName)
if LengthOfTable(str) == 3 then
randomName = GetLanguageStrById(str[1])..GetLanguageStrById(str[2]..str[3])
elseif LengthOfTable(str) == 4 then
randomName = GetLanguageStrById(str[1]..str[2])..GetLanguageStrById(str[3]..str[4])
end
end
this.textName.text = randomName or ""
this.textNameNew.text = randomName or ""
end