feat: add-intl-directory
APi for scripts to extend localization
This commit is contained in:
@@ -588,6 +588,14 @@ mp.commandv('script-message-to', 'uosc', 'overwrite-binding', 'stream-quality',
|
|||||||
|
|
||||||
To cancel the overwrite and return to default behavior, just omit the `<command>` parameter.
|
To cancel the overwrite and return to default behavior, just omit the `<command>` parameter.
|
||||||
|
|
||||||
|
### `add-intl-directory <path>`
|
||||||
|
|
||||||
|
Adds a new internationalization directory where uosc will look for localization files to be merged into current locale.
|
||||||
|
|
||||||
|
See `scripts/uosc_shared/intl` for directory structure example.
|
||||||
|
|
||||||
|
Example path: `~~/scripts/my_script/intl`
|
||||||
|
|
||||||
## Why _uosc_?
|
## Why _uosc_?
|
||||||
|
|
||||||
It stood for micro osc as it used to render just a couple rectangles before it grew to what it is today. And now it means a minimalist UI design direction where everything is out of your way until needed.
|
It stood for micro osc as it used to render just a couple rectangles before it grew to what it is today. And now it means a minimalist UI design direction where everything is out of your way until needed.
|
||||||
|
@@ -133,7 +133,8 @@ fg, bg = serialize_rgba(options.foreground).color, serialize_rgba(options.backgr
|
|||||||
fgt, bgt = serialize_rgba(options.foreground_text).color, serialize_rgba(options.background_text).color
|
fgt, bgt = serialize_rgba(options.foreground_text).color, serialize_rgba(options.background_text).color
|
||||||
|
|
||||||
--[[ INTERNATIONALIZATION ]]
|
--[[ INTERNATIONALIZATION ]]
|
||||||
t = require('uosc_shared/lib/intl')
|
local intl = require('uosc_shared/lib/intl')
|
||||||
|
t = intl.t
|
||||||
|
|
||||||
--[[ CONFIG ]]
|
--[[ CONFIG ]]
|
||||||
|
|
||||||
@@ -1255,6 +1256,7 @@ mp.register_script_message('set-min-visibility', function(visibility, elements)
|
|||||||
end)
|
end)
|
||||||
mp.register_script_message('flash-elements', function(elements) Elements:flash(split(elements, ' *, *')) end)
|
mp.register_script_message('flash-elements', function(elements) Elements:flash(split(elements, ' *, *')) end)
|
||||||
mp.register_script_message('overwrite-binding', function(name, command) key_binding_overwrites[name] = command end)
|
mp.register_script_message('overwrite-binding', function(name, command) key_binding_overwrites[name] = command end)
|
||||||
|
mp.register_script_message('add-intl-directory', function(path) intl.add_directory(path) end)
|
||||||
|
|
||||||
--[[ ELEMENTS ]]
|
--[[ ELEMENTS ]]
|
||||||
|
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
|
local intl_directories = {'~~/scripts/uosc_shared/intl/'}
|
||||||
local locale = {}
|
local locale = {}
|
||||||
local cache = {}
|
local cache = {}
|
||||||
|
local reload_timer = nil
|
||||||
|
|
||||||
-- https://learn.microsoft.com/en-us/windows/apps/publish/publish-your-app/supported-languages?pivots=store-installer-msix#list-of-supported-languages
|
-- https://learn.microsoft.com/en-us/windows/apps/publish/publish-your-app/supported-languages?pivots=store-installer-msix#list-of-supported-languages
|
||||||
function get_languages()
|
function get_languages()
|
||||||
@@ -48,13 +50,30 @@ function make_locale()
|
|||||||
elseif (lang == 'en') then
|
elseif (lang == 'en') then
|
||||||
translations = {}
|
translations = {}
|
||||||
else
|
else
|
||||||
table_assign(translations, get_locale_from_json('~~/scripts/uosc_shared/intl/' .. lang:lower() .. '.json'))
|
for _, path in ipairs(intl_directories) do
|
||||||
|
table_assign(translations, get_locale_from_json(path .. lang:lower() .. '.json'))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return translations
|
return translations
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function reload()
|
||||||
|
reload_timer, cache = nil, {}
|
||||||
|
locale = make_locale()
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
function add_directory(path)
|
||||||
|
path = trim_end(trim_end(path, '\\'), '/') .. '/'
|
||||||
|
if itable_index_of(intl_directories, path) then return end
|
||||||
|
intl_directories[#intl_directories + 1] = path
|
||||||
|
if not reload_timer then
|
||||||
|
reload_timer = mp.add_timeout(0.1, reload)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param text string
|
---@param text string
|
||||||
function t(text, ...)
|
function t(text, ...)
|
||||||
if not text then return '' end
|
if not text then return '' end
|
||||||
@@ -63,6 +82,6 @@ function t(text, ...)
|
|||||||
return cache[text]
|
return cache[text]
|
||||||
end
|
end
|
||||||
|
|
||||||
locale = make_locale()
|
reload()
|
||||||
|
|
||||||
return t
|
return {t = t, add_directory = add_directory}
|
||||||
|
Reference in New Issue
Block a user