libobs: Add macro for default module locale

These macros are used as easy helper functions to load/unload module
locale that's based upon the text_lookup system.  You simple place the
OBS_MODULE_USE_DEFAULT_LOCALE macro once in the module, call
OBS_MODULE_FREE_DEFAULT LOCALE in obs_module_unload, and then
call obs_module_text anywhere in your module where you need to look up
text.

By default, it will look for a locale directory in your module's data
directory, and look for language files within it (INI locale format)
master
jp9000 2014-07-09 21:32:54 -07:00
parent ac760efb57
commit aed8f54f1a
1 changed files with 26 additions and 0 deletions

View File

@ -53,6 +53,32 @@ 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: Use this macro in a module to use default locale handling. Use
* the OBS_MODULE_FREE_DEFAULT_LOCALE macro in obs_module_unload to free the
* locale data when the module unloads.
*/
#define OBS_MODULE_USE_DEFAULT_LOCALE(module_name, default_locale) \
lookup_t obs_module_lookup = NULL; \
const char *obs_module_text(const char *val) \
{ \
const char *out = val; \
text_lookup_getstr(obs_module_lookup, val, &out); \
return out; \
} \
void obs_module_set_locale(const char *locale) \
{ \
if (obs_module_lookup) text_lookup_destroy(obs_module_lookup); \
obs_module_lookup = obs_module_load_locale(module_name, \
default_locale, locale); \
}
#define OBS_MODULE_FREE_DEFAULT_LOCALE() \
text_lookup_destroy(obs_module_lookup)
/** Helper function for looking up locale if default locale handler was used */
extern const char *obs_module_text(const char *lookup_string);
/**
* Optional: Declares the author(s) of the module
*