Multiple changes around Zictionary (mostly for Vietnamese) (#1069)

* Multiple changes
- Edit Vietnamese Zictionary
- Add STRING.viRemoveDiacritics()
- Edit the search behavior with string written in Vietnamese without diacritics

* Small changes

* Update lang_vi.lua

* Small change
This commit is contained in:
C6H12O6 + NaCl + H2O
2023-12-31 19:58:59 +07:00
committed by GitHub
parent 43215dfc4b
commit 42942d1ac4
6 changed files with 118 additions and 82 deletions

View File

@@ -36,7 +36,8 @@ do-- function STRING.shiftChar(c)
end
end
local upperData,lowerData
-- [LOW PERFORMANCE!]
local upperData,lowerData,VIdiaData
function STRING.upperUTF8(str)
for _,pair in next,upperData do
str=str:gsub(pair[1],pair[2])
@@ -49,6 +50,16 @@ function STRING.lowerUTF8(str)
end
return str
end
--[[
[FOR VIETNAMESE ONLY]
Remove all diacritics in strings written in Vietnamese
]]
function STRING.viRemoveDiacritics(str)
for _,pair in next,VIdiaData do
str=str:gsub(pair[1],pair[2])
end
return str
end
function STRING.trim(s)
if not s:find("%S") then return "" end
@@ -390,34 +401,44 @@ function STRING.unpackTable(t)
return JSON.decode(STRING.unpackText(t))
end
repeat
if love and love.filesystem and type(love.filesystem.read)=='function' then
upperData=love.filesystem.read('Zframework/upcaser.txt')
lowerData=love.filesystem.read('Zframework/lowcaser.txt')
do
local function readF(fname)
if love and love.filesystem and type(love.filesystem.read)=='function' then
f=love.filesystem.read(fname)
else
local f=io.open(fname,'r')
local d=f:read('a')
f:close()
end
return f
end
upperData=readF('Zframework/upcaser.txt')
lowerData=readF('Zframework/lowcaser.txt')
VIdiaData=readF('Zframework/vi_diaractics.txt')
local function splitData(data)
for i=1,#data do
local pair=STRING.split(data[i],'=')
data[i]=pair
end
return data
end
if upperData then upperData=splitData(STRING.split(gsub(upperData,'\n',','),','))
else
local f=io.open('Zframework/upcaser.txt','r')
if not f then break end
upperData=f:read('a')
f:close()
f=io.open('Zframework/lowcaser.txt','r')
if not f then break end
lowerData=f:read('a')
f:close()
upperData={}
LOG('ERROR: Failed to read the data from Zframework/upcaser.txt')
end
if lowerData then lowerData=splitData(STRING.split(gsub(lowerData,'\n',','),','))
else
lowerData={}
LOG('ERROR: Failed to read the data from Zframework/lowcaser.txt')
end
upperData=STRING.split(gsub(upperData,'\n',','),',')
lowerData=STRING.split(gsub(lowerData,'\n',','),',')
for i=1,#upperData do
local pair=STRING.split(upperData[i],'=')
-- upperData[pair[1]]=pair[2]
upperData[i]=pair
if VIdiaData then VIdiaData=splitData(STRING.split(gsub(VIdiaData,'\n',','),','))
else
VIdiaData={}
LOG('ERROR: Failed to read the data from Zframework/vi_diaractics.txt')
end
for i=1,#lowerData do
local pair=STRING.split(lowerData[i],'=')
-- lowerData[pair[1]]=pair[2]
lowerData[i]=pair
end
until true
end
return STRING

View File

@@ -0,0 +1,12 @@
Á=A,À=A,Ả=A,Ã=A,Ạ=A,Ă=A,Ắ=A,Ằ=A,Ẳ=A,Ẵ=A,Ặ=A,Â=A,Ấ=A,Ầ=A,Ẩ=A,Ẫ=A,Ậ=A
á=a,à=a,ả=a,ã=a,ạ=a,ă=a,ắ=a,ằ=a,ẳ=a,ẵ=a,ặ=a,â=a,ấ=a,ầ=a,ẩ=a,ẫ=a,ậ=a
Đ=D,đ=d
É=E,È=E,Ẻ=E,Ẽ=E,Ẹ=E,Ê=E,Ế=E,Ề=E,Ể=E,Ễ=E,Ệ=E
é=e,è=e,ẻ=e,ẽ=e,ẹ=e,ê=e,ế=e,ề=e,ể=e,ễ=e,ệ=e
Í=I,Ì=I,Ỉ=I,Ĩ=I,Ị=I
í=i,ì=i,ỉ=i,ĩ=i,ị=i
Ó=O,Ò=O,Ỏ=O,Õ=O,Ọ=O,Ô=O,Ố=O,Ồ=O,Ổ=O,Ỗ=O,Ộ=O,Ơ=O,Ớ=O,Ờ=O,Ở=O,Ỡ=O,Ợ=O
ó=o,ò=o,ỏ=o,õ=o,ọ=o,ô=o,ố=o,ồ=o,ổ=o,ỗ=o,ộ=o,ơ=o,ớ=o,ờ=o,ở=o,ỡ=o,ợ=o
Ú=U,Ù=U,Ủ=U,Ũ=U,Ụ=U,Ư=U,Ứ=U,Ừ=U,Ử=U,Ữ=U,Ự=U
ú=u,ù=u,ủ=u,ũ=u,ụ=u,ư=u,ứ=u,ừ=u,ử=u,ữ=u,ự=u
Ý=Y,Ỳ=Y,Ỷ=Y,Ỹ=Y,Ỵ=Y,ý=y,ỳ=y,ỷ=y,ỹ=y,ỵ=y