提交 ac760efb 编写于 作者: J jp9000

libobs: Add function for default module locale

This function is used to simplify the process when using the default
locale handling for modules.  It will automatically search in the plugin
data directory associated with the specific module specified, load the
default locale text (for example english if its default language is
english), and then it will load the set locale on top of the default
locale, which will cause text to use the default locale if the desired
locale text is not found.
上级 1e7a99ee
......@@ -101,6 +101,54 @@ void free_module(struct obs_module *mod)
bfree(mod->name);
}
lookup_t obs_module_load_locale(const char *module, const char *default_locale,
const char *locale)
{
struct dstr str = {0};
lookup_t lookup = NULL;
if (!module || !default_locale || !locale) {
blog(LOG_WARNING, "obs_module_load_locale: Invalid parameters");
return NULL;
}
dstr_copy(&str, module);
dstr_cat(&str, "/locale/");
dstr_cat(&str, default_locale);
dstr_cat(&str, ".ini");
char *file = obs_find_plugin_file(str.array);
if (file)
lookup = text_lookup_create(file);
bfree(file);
if (!lookup) {
blog(LOG_WARNING, "Failed to load '%s' text for module: '%s'",
default_locale, module);
goto cleanup;
}
if (astrcmpi(locale, default_locale) == 0)
goto cleanup;
dstr_copy(&str, module);
dstr_cat(&str, "/locale/");
dstr_cat(&str, locale);
dstr_cat(&str, ".ini");
file = obs_find_plugin_file(str.array);
if (!text_lookup_add(lookup, file))
blog(LOG_WARNING, "Failed to load '%s' text for module: '%s'",
locale, module);
bfree(file);
cleanup:
dstr_free(&str);
return lookup;
}
#define REGISTER_OBS_DEF(size_var, structure, dest, info) \
do { \
struct structure data = {0}; \
......
......@@ -19,6 +19,7 @@
#include "util/c99defs.h"
#include "util/bmem.h"
#include "util/text-lookup.h"
#include "graphics/graphics.h"
#include "graphics/vec2.h"
#include "graphics/vec3.h"
......@@ -250,6 +251,10 @@ EXPORT bool obs_get_audio_info(struct audio_output_info *ai);
*/
EXPORT int obs_load_module(const char *path);
/** Helper function for using default module locale */
EXPORT lookup_t obs_module_load_locale(const char *module,
const char *default_locale, const char *locale);
/**
* Enumerates all available inputs source types.
*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册