0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00

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.
This commit is contained in:
jp9000 2014-07-09 21:28:40 -07:00
parent 1e7a99eeb4
commit ac760efb57
2 changed files with 53 additions and 0 deletions

View File

@ -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}; \

View File

@ -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.
*