From 9c544bf56569b76fb9147c522541c04fb074d96a Mon Sep 17 00:00:00 2001 From: tomasklaen Date: Mon, 15 May 2023 09:51:16 +0200 Subject: [PATCH] fix: removed `add-intl-directory` API It doesn't make sense for uosc to be the internationalization provider for other scripts. --- README.md | 8 ------ scripts/uosc.lua | 1 - scripts/uosc_shared/lib/intl.lua | 48 +++++++++++--------------------- 3 files changed, 16 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index efbf184..588a49b 100644 --- a/README.md +++ b/README.md @@ -588,14 +588,6 @@ mp.commandv('script-message-to', 'uosc', 'overwrite-binding', 'stream-quality', To cancel the overwrite and return to default behavior, just omit the `` parameter. -### `add-intl-directory ` - -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_? 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. diff --git a/scripts/uosc.lua b/scripts/uosc.lua index f5ef81b..de35cda 100644 --- a/scripts/uosc.lua +++ b/scripts/uosc.lua @@ -1256,7 +1256,6 @@ mp.register_script_message('set-min-visibility', function(visibility, 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('add-intl-directory', function(path) intl.add_directory(path) end) --[[ ELEMENTS ]] diff --git a/scripts/uosc_shared/lib/intl.lua b/scripts/uosc_shared/lib/intl.lua index 0f51cec..e3acecd 100644 --- a/scripts/uosc_shared/lib/intl.lua +++ b/scripts/uosc_shared/lib/intl.lua @@ -1,11 +1,11 @@ -local intl_directories = {'~~/scripts/uosc_shared/intl/'} +local intl_dir = '~~/scripts/uosc_shared/intl/' local locale = {} 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 function get_languages() local languages = {} + for _, lang in ipairs(split(options.languages, ',')) do if (lang == 'slang') then local slang = mp.get_property_native('slang') @@ -42,38 +42,10 @@ end function make_locale() local translations = {} - local languages = get_languages() - for i = #languages, 1, -1 do - lang = languages[i] - if (lang:match('.json$')) then - table_assign(translations, get_locale_from_json(lang)) - elseif (lang == 'en') then - translations = {} - else - for _, path in ipairs(intl_directories) do - table_assign(translations, get_locale_from_json(path .. lang:lower() .. '.json')) - end - end - end return translations 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 function t(text, a) if not text then return '' end @@ -84,6 +56,18 @@ function t(text, a) return cache[key] end -reload() +-- Load locales +local languages = get_languages() -return {t = t, add_directory = add_directory} +for i = #languages, 1, -1 do + lang = languages[i] + if (lang:match('.json$')) then + table_assign(locale, get_locale_from_json(lang)) + elseif (lang == 'en') then + locale = {} + else + table_assign(locale, get_locale_from_json(intl_dir .. lang:lower() .. '.json')) + end +end + +return {t = t}