diff --git a/libobs/obs-internal.h b/libobs/obs-internal.h index ddf71929d28823..c6fd25e7ed69fd 100644 --- a/libobs/obs-internal.h +++ b/libobs/obs-internal.h @@ -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; diff --git a/libobs/obs.c b/libobs/obs.c index ffe22795f1aa36..c0d4f4ff99e275 100644 --- a/libobs/obs.c +++ b/libobs/obs.c @@ -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; diff --git a/libobs/obs.h b/libobs/obs.h index 70b10503fcaf0d..3bccadd57a9dfb 100644 --- a/libobs/obs.h +++ b/libobs/obs.h @@ -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 * diff --git a/obs/window-basic-main.cpp b/obs/window-basic-main.cpp index 10136bfbab9ab5..be29b571cc9d42 100644 --- a/obs/window-basic-main.cpp +++ b/obs/window-basic-main.cpp @@ -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"; diff --git a/test/osx/test.mm b/test/osx/test.mm index bc346d53887f09..df03c3de6b46ba 100644 --- a/test/osx/test.mm +++ b/test/osx/test.mm @@ -38,7 +38,7 @@ explicit OBSUniqueHandle(T *obj=nullptr) : base(obj, D) {} static void CreateOBS(NSView *view) { - if (!obs_startup()) + if (!obs_startup("en")) throw "Couldn't create OBS"; struct obs_video_info ovi; diff --git a/test/win/test.cpp b/test/win/test.cpp index ef435ca8cfef7c..1cd4293197619c 100644 --- a/test/win/test.cpp +++ b/test/win/test.cpp @@ -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;