Skip to content

Commit

Permalink
Add module callbacks for loading locale data
Browse files Browse the repository at this point in the history
The module callback obs_module_set_locale will be called after loading
the module, and any time the locale is manually changed via core API.

When this function is called, the module is expected to load new text
lookup values for all the text it uses based upon the current locale.
  • Loading branch information
jp9000 committed Jun 25, 2014
1 parent 0b4a259 commit 1abf915
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct draw_callback {
struct obs_module {
char *name;
void *module;
void (*set_locale)(const char *locale);
};

extern void free_module(struct obs_module *mod);
Expand Down
7 changes: 6 additions & 1 deletion libobs/obs-module.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ int obs_load_module(const char *path)
return errorcode;
}

mod.name = bstrdup(path);
mod.name = bstrdup(path);
mod.set_locale = os_dlsym(mod.module, "obs_module_set_locale");

if (mod.set_locale)
mod.set_locale(obs->locale);

da_push_back(obs->modules, &mod);
return MODULE_SUCCESS;
}
Expand Down
11 changes: 5 additions & 6 deletions libobs/obs-module.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ MODULE_EXPORT bool obs_module_load(uint32_t libobs_version);
/** Optional: Called when the module is unloaded. */
MODULE_EXPORT void obs_module_unload(void);

/** Called to set the current locale data for the module. */
MODULE_EXPORT void obs_module_set_locale(const char *locale);

/**
* Optional: Declares the author(s) of the module
*
Expand All @@ -59,9 +62,5 @@ MODULE_EXPORT void obs_module_unload(void);
MODULE_EXPORT const char *obs_module_author(void); \
const char *obs_module_author(void) {return name;}

/**
* Optional: Declares the author of the module
*
* @param locale Locale to look up the description for.
*/
MODULE_EXPORT const char *obs_module_description(const char *locale);
/** Optional: Returns a description of the module */
MODULE_EXPORT const char *obs_module_description(void);
7 changes: 7 additions & 0 deletions libobs/obs.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,13 @@ void obs_set_locale(const char *locale)
if (obs->locale)
bfree(obs->locale);
obs->locale = bstrdup(locale);

for (size_t i = 0; i < obs->modules.num; i++) {
struct obs_module *module = obs->modules.array+i;

if (module->set_locale)
module->set_locale(locale);
}
}

const char *obs_get_locale(void)
Expand Down

0 comments on commit 1abf915

Please sign in to comment.