Skip to content

Commit

Permalink
Add API for setting/getting current locale
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jp9000 committed Jun 25, 2014
1 parent 9f652e6 commit 899f053
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
2 changes: 2 additions & 0 deletions libobs/obs-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
23 changes: 20 additions & 3 deletions libobs/obs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand All @@ -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;

Expand All @@ -525,7 +526,7 @@ bool obs_startup(void)
return false;
}

success = obs_init();
success = obs_init(locale);
if (!success)
obs_shutdown();

Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions libobs/obs.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,30 @@ 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);

/** @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
*
Expand Down
2 changes: 1 addition & 1 deletion obs/window-basic-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion test/osx/test.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/win/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 899f053

Please sign in to comment.