feat: internationalization (#518)

Adds `languages` option to specify localization language priority.
Built in languages can be found in `scripts/uosc_shared/intl`.
This commit is contained in:
natural-harmonia-gropius
2023-04-24 17:37:58 +08:00
committed by GitHub
parent f274101fbd
commit 3c70ffd927
7 changed files with 156 additions and 34 deletions

View File

@@ -109,6 +109,7 @@ defaults = {
adjust_osd_margins = true,
chapter_ranges = 'openings:30abf964,endings:30abf964,ads:c54e4e80',
chapter_range_patterns = 'openings:オープニング;endings:エンディング',
languages = 'slang,en',
}
options = table_shallow_copy(defaults)
opt.read_options(options, 'uosc')
@@ -131,37 +132,40 @@ if options.autoload then mp.commandv('set', 'keep-open-pause', 'no') end
fg, bg = serialize_rgba(options.foreground).color, serialize_rgba(options.background).color
fgt, bgt = serialize_rgba(options.foreground_text).color, serialize_rgba(options.background_text).color
--[[ INTERNATIONALIZATION ]]
t = require('uosc_shared/lib/intl')
--[[ CONFIG ]]
function create_default_menu()
return {
{title = 'Subtitles', value = 'script-binding uosc/subtitles'},
{title = 'Audio tracks', value = 'script-binding uosc/audio'},
{title = 'Stream quality', value = 'script-binding uosc/stream-quality'},
{title = 'Playlist', value = 'script-binding uosc/items'},
{title = 'Chapters', value = 'script-binding uosc/chapters'},
{title = 'Navigation', items = {
{title = 'Next', hint = 'playlist or file', value = 'script-binding uosc/next'},
{title = 'Prev', hint = 'playlist or file', value = 'script-binding uosc/prev'},
{title = 'Delete file & Next', value = 'script-binding uosc/delete-file-next'},
{title = 'Delete file & Prev', value = 'script-binding uosc/delete-file-prev'},
{title = 'Delete file & Quit', value = 'script-binding uosc/delete-file-quit'},
{title = 'Open file', value = 'script-binding uosc/open-file'},
{title = t('Subtitles'), value = 'script-binding uosc/subtitles'},
{title = t('Audio tracks'), value = 'script-binding uosc/audio'},
{title = t('Stream quality'), value = 'script-binding uosc/stream-quality'},
{title = t('Playlist'), value = 'script-binding uosc/items'},
{title = t('Chapters'), value = 'script-binding uosc/chapters'},
{title = t('Navigation'), items = {
{title = t('Next'), hint = t('playlist or file'), value = 'script-binding uosc/next'},
{title = t('Prev'), hint = t('playlist or file'), value = 'script-binding uosc/prev'},
{title = t('Delete file & Next'), value = 'script-binding uosc/delete-file-next'},
{title = t('Delete file & Prev'), value = 'script-binding uosc/delete-file-prev'},
{title = t('Delete file & Quit'), value = 'script-binding uosc/delete-file-quit'},
{title = t('Open file'), value = 'script-binding uosc/open-file'},
},},
{title = 'Utils', items = {
{title = 'Aspect ratio', items = {
{title = 'Default', value = 'set video-aspect-override "-1"'},
{title = t('Utils'), items = {
{title = t('Aspect ratio'), items = {
{title = t('Default'), value = 'set video-aspect-override "-1"'},
{title = '16:9', value = 'set video-aspect-override "16:9"'},
{title = '4:3', value = 'set video-aspect-override "4:3"'},
{title = '2.35:1', value = 'set video-aspect-override "2.35:1"'},
},},
{title = 'Audio devices', value = 'script-binding uosc/audio-device'},
{title = 'Editions', value = 'script-binding uosc/editions'},
{title = 'Screenshot', value = 'async screenshot'},
{title = 'Show in directory', value = 'script-binding uosc/show-in-directory'},
{title = 'Open config folder', value = 'script-binding uosc/open-config-directory'},
{title = t('Audio devices'), value = 'script-binding uosc/audio-device'},
{title = t('Editions'), value = 'script-binding uosc/editions'},
{title = t('Screenshot'), value = 'async screenshot'},
{title = t('Show in directory'), value = 'script-binding uosc/show-in-directory'},
{title = t('Open config folder'), value = 'script-binding uosc/open-config-directory'},
},},
{title = 'Quit', value = 'quit'},
{title = t('Quit'), value = 'quit'},
}
end
@@ -222,6 +226,7 @@ config = {
local title_parts = split(title or '', ' *> *')
for index, title_part in ipairs(#title_parts > 0 and title_parts or {''}) do
title_part = t(title_part)
if index < #title_parts then
submenu_id = submenu_id .. title_part
@@ -987,7 +992,7 @@ bind_command('editions', create_self_updating_menu_opener({
local items = {}
for _, edition in ipairs(editions or {}) do
items[#items + 1] = {
title = edition.title or 'Edition',
title = edition.title or t('Edition'),
hint = tostring(edition.id + 1),
value = edition.id,
active = edition.id == current_id,