提交 899f0530 编写于 作者: J jp9000

Add API for setting/getting current locale

This API is used to set the current locale for libobs, which it will set
for all modules when a module is loaded or specifically when the locale
is manually changed.
上级 9f652e64
......@@ -173,6 +173,8 @@ struct obs_core {
signal_handler_t signals;
proc_handler_t procs;
char *locale;
/* segmented into multiple sub-structures to keep things a bit more
* clean and organized */
struct obs_core_video video;
......
......@@ -503,7 +503,7 @@ static inline bool obs_init_handlers(void)
extern const struct obs_source_info scene_info;
static bool obs_init(void)
static bool obs_init(const char *locale)
{
obs = bzalloc(sizeof(struct obs_core));
......@@ -512,11 +512,12 @@ static bool obs_init(void)
if (!obs_init_handlers())
return false;
obs->locale = bstrdup(locale);
obs_register_source(&scene_info);
return true;
}
bool obs_startup(void)
bool obs_startup(const char *locale)
{
bool success;
......@@ -525,7 +526,7 @@ bool obs_startup(void)
return false;
}
success = obs_init();
success = obs_init(locale);
if (!success)
obs_shutdown();
......@@ -559,6 +560,7 @@ void obs_shutdown(void)
free_module(obs->modules.array+i);
da_free(obs->modules);
bfree(obs->locale);
bfree(obs);
obs = NULL;
}
......@@ -568,6 +570,21 @@ bool obs_initialized(void)
return obs != NULL;
}
void obs_set_locale(const char *locale)
{
if (!obs)
return;
if (obs->locale)
bfree(obs->locale);
obs->locale = bstrdup(locale);
}
const char *obs_get_locale(void)
{
return obs ? obs->locale : NULL;
}
bool obs_reset_video(struct obs_video_info *ovi)
{
if (!obs) return false;
......
......@@ -197,8 +197,12 @@ struct source_frame {
/* ------------------------------------------------------------------------- */
/* OBS context */
/** Initializes OBS */
EXPORT bool obs_startup(void);
/**
* Initializes OBS
*
* @param locale The locale to use for modules
*/
EXPORT bool obs_startup(const char *locale);
/** Releases all data associated with OBS and terminates the OBS context */
EXPORT void obs_shutdown(void);
......@@ -206,6 +210,17 @@ EXPORT void obs_shutdown(void);
/** @return true if the main OBS context has been initialized */
EXPORT bool obs_initialized(void);
/**
* Sets a new locale to use for modules. This will call obs_module_set_locale
* for each module with the new locale.
*
* @param locale The locale to use for modules
*/
EXPORT void obs_set_locale(const char *locale);
/** @return the current locale */
EXPORT const char *obs_get_locale(void);
/**
* Sets base video ouput base resolution/fps/format
*
......
......@@ -468,7 +468,7 @@ void OBSBasic::OBSInit()
show();
App()->processEvents();
if (!obs_startup())
if (!obs_startup(App()->GetLocale()))
throw "Failed to initialize libobs";
if (!InitBasicConfig())
throw "Failed to load basic.ini";
......
......@@ -38,7 +38,7 @@ using SceneContext = OBSUniqueHandle<obs_scene,
static void CreateOBS(NSView *view)
{
if (!obs_startup())
if (!obs_startup("en"))
throw "Couldn't create OBS";
struct obs_video_info ovi;
......
......@@ -71,7 +71,7 @@ static void CreateOBS(HWND hwnd)
RECT rc;
GetClientRect(hwnd, &rc);
if (!obs_startup())
if (!obs_startup("en"))
throw "Couldn't create OBS";
struct obs_video_info ovi;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册