modern_lisp-machine/.config/mpv/scripts/katakana_conversion.lua~

36 lines
1.7 KiB
Lua
Raw Permalink Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

-- katakana_conversion.lua
-- Table mapping half-width katakana to full-width
local half_to_full = {
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', ['ソ'] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = '', [''] = '', [''] = '',
[''] = '', [''] = ''
}
-- Function to convert half-width katakana to full-width
local function convert_halfwidth_to_fullwidth(text)
return text:gsub(".", function(c)
return half_to_full[c] or c
end)
end
-- Hook into the subtitle text before display
mp.add_hook("on_sub_text", 50, function(subtitle)
if subtitle and subtitle.text then
mp.msg.info("Original subtitle text: " .. subtitle.text)
subtitle.text = convert_halfwidth_to_fullwidth(subtitle.text)
mp.msg.info("Converted subtitle text: " .. subtitle.text)
end
return subtitle
end)