소스 검색

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.
jp9000 11 년 전
부모
커밋
899f053034
6개의 변경된 파일42개의 추가작업 그리고 8개의 파일을 삭제
  1. 2 0
      libobs/obs-internal.h
  2. 20 3
      libobs/obs.c
  3. 17 2
      libobs/obs.h
  4. 1 1
      obs/window-basic-main.cpp
  5. 1 1
      test/osx/test.mm
  6. 1 1
      test/win/test.cpp

+ 2 - 0
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;

+ 20 - 3
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;

+ 17 - 2
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
  *

+ 1 - 1
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";

+ 1 - 1
test/osx/test.mm

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

+ 1 - 1
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;