Add a fallback about language change 86/163186/1
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 7 Dec 2017 22:52:13 +0000 (07:52 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 7 Dec 2017 22:52:13 +0000 (07:52 +0900)
If the language is changed when an application is starting,
the callback of the language change event will be invoked.

Change-Id: I2849397a55bf91f97ac246f03589d68a4ad569eb
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/base/appcore_base.c

index 37e1840..b0820a6 100644 (file)
@@ -55,6 +55,7 @@ typedef struct _appcore_base_context {
        bool suspended_state;
        bool allowed_bg;
        bool dirty;
+       guint sid;
 } appcore_base_context;
 
 typedef struct _appcore_base_event_node {
@@ -654,6 +655,11 @@ static void __on_language_change(keynode_t *key, void *data)
 {
        char *val;
 
+       if (__context.sid) {
+               g_source_remove(__context.sid);
+               __context.sid = 0;
+       }
+
        val = vconf_keynode_get_str(key);
 
        __update_lang();
@@ -680,6 +686,42 @@ static void __on_region_change(keynode_t *key, void *data)
        free(val);
 }
 
+static gboolean __invoke_lang_change(gpointer data)
+{
+       const char *lang;
+
+       __context.sid = 0;
+
+       lang = getenv("LANG");
+       if (!lang)
+               return G_SOURCE_REMOVE;
+
+       __invoke_callback((void *)lang, APPCORE_BASE_EVENT_LANG_CHANGE);
+
+       return G_SOURCE_REMOVE;
+}
+
+static void __verify_language(void)
+{
+       char *lang;
+       const char *env_lang;
+
+       env_lang = getenv("LANG");
+       if (!env_lang)
+               return;
+
+       lang = vconf_get_str(VCONFKEY_LANGSET);
+       if (!lang)
+               return;
+
+       if (strcmp(env_lang, lang) != 0) {
+               _INFO("LANG(%s), LANGSET(%s)", env_lang, lang);
+               __context.sid = g_idle_add(__invoke_lang_change, NULL);
+       }
+
+       free(lang);
+}
+
 static gboolean __flush_memory(gpointer data)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
@@ -918,6 +960,7 @@ EXPORT_API int appcore_base_init(appcore_base_ops ops, int argc, char **argv, vo
        if (__context.ops.init)
                __context.ops.init(argc, argv, data);
 
+       __verify_language();
        if (__context.ops.set_i18n)
                __context.ops.set_i18n(__context.data);
 
@@ -969,6 +1012,11 @@ EXPORT_API void appcore_base_fini(void)
                }
        }
 
+       if (__context.sid) {
+               g_source_remove(__context.sid);
+               __context.sid = 0;
+       }
+
        g_list_free_full(__events, free);
        __events = NULL;