double-consonants: handle all japanese consonants
This commit is contained in:
parent
0c4f5f4e51
commit
1e57c7e287
|
@ -0,0 +1,39 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Double consonants"
|
||||
script_description = tr"Ensure k tags are in the right place with double consonants"
|
||||
script_author = "amoethyst"
|
||||
script_version = "1.0"
|
||||
|
||||
local consonants = {"b", "c", "d", "f", "g", "h", "j", "k", "r", "m", "n", "p", "s", "t", "w", "z"}
|
||||
|
||||
local function _double(subs, i, letter)
|
||||
local expr = "^(.-)({\\[kK][fo]?[0-9.]+[^}]-})( -" .. letter .. ")(" .. letter .. ".*)$"
|
||||
local line = subs[i]
|
||||
|
||||
local before, tag, start_tt, after = line.text:match(expr)
|
||||
while after ~= nil do
|
||||
line.text = before .. start_tt .. tag .. after
|
||||
before, tag, start_tt, after = line.text:match(expr)
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
|
||||
local function double(subs, sel)
|
||||
for _, i in ipairs(sel) do
|
||||
for _, c in ipairs(consonants) do
|
||||
print(c)
|
||||
local ok, res = pcall(_double, subs, i, c)
|
||||
if ok then
|
||||
subs[i] = res
|
||||
else
|
||||
aegisub.log("error on line " .. i .. ": " .. line.text .. "\n")
|
||||
aegisub.log(res .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, double)
|
36
tt.lua
36
tt.lua
|
@ -1,36 +0,0 @@
|
|||
local tr = aegisub.gettext
|
||||
|
||||
script_name = tr"Double t"
|
||||
script_description = tr"Ensure k tags are in the right place with double t's"
|
||||
script_author = "amoethyst"
|
||||
script_version = "1.0"
|
||||
|
||||
local expr = "^(.-)({\\[kK][fo]?[0-9.]+[^}]-})( -t)(t.*)$"
|
||||
|
||||
|
||||
local function _tte(subs, i)
|
||||
local line = subs[i]
|
||||
|
||||
local before, tag, start_tt, after = line.text:match(expr)
|
||||
while after ~= nil do
|
||||
line.text = before .. start_tt .. tag .. after
|
||||
before, tag, start_tt, after = line.text:match(expr)
|
||||
end
|
||||
|
||||
return line
|
||||
end
|
||||
|
||||
|
||||
local function tte(subs, sel)
|
||||
for _, i in ipairs(sel) do
|
||||
local ok, res = pcall(_tte, subs, i)
|
||||
if ok then
|
||||
subs[i] = res
|
||||
else
|
||||
aegisub.log("error on line " .. i .. ": " .. line.text .. "\n")
|
||||
aegisub.log(res .. "\n")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
aegisub.register_macro(script_name, script_description, tte)
|
Loading…
Reference in New Issue