Add translate localized text feature 76/68076/7 accepted/tizen/common/20160504.125248 accepted/tizen/ivi/20160503.093012 accepted/tizen/mobile/20160503.092912 accepted/tizen/tv/20160503.092938 accepted/tizen/wearable/20160503.092950 submit/tizen/20160503.003646
authorHyunho Kang <hhstark.kang@samsung.com>
Mon, 2 May 2016 06:09:31 +0000 (15:09 +0900)
committerHyunho Kang <hhstark.kang@samsung.com>
Tue, 3 May 2016 01:42:31 +0000 (10:42 +0900)
Change-Id: Icd05fb258df7598f52c2e61b619f38404fb4b78f
Signed-off-by: Hyunho Kang <hhstark.kang@samsung.com>
include/notification_internal.h
include/notification_ipc.h
src/notification_internal.c
src/notification_ipc.c

index c63f8b7..e16e443 100644 (file)
@@ -703,10 +703,18 @@ int notification_register_detailed_changed_cb(
 int notification_unregister_detailed_changed_cb(
                void (*detailed_changed_cb)(void *data, notification_type_e type, notification_op *op_list, int num_op),
                void *user_data);
+
 /**
- * @}
+ * @brief This function translate localized texts
+ * @param[in] noti The notification handle that is created by notification_create()
+ * @return #NOTIFICATION_ERROR_NONE if success, other value if failure
+ * @see notification_create()
  */
+int notification_translate_localized_text(notification_h noti);
 
+/**
+ * @}
+ */
 #ifdef __cplusplus
 }
 #endif
index fc31c04..1451a70 100755 (executable)
@@ -27,7 +27,7 @@
 extern "C" {
 #endif
 
-GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti);
+GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate);
 int notification_ipc_make_noti_from_gvariant(notification_h noti,
                GVariant *variant);
 
index a519d28..f29e618 100755 (executable)
@@ -350,6 +350,47 @@ EXPORT_API int notification_get_icon(notification_h noti,
        return ret_err;
 }
 
+EXPORT_API int notification_translate_localized_text(notification_h noti)
+{
+       int noti_err = NOTIFICATION_ERROR_NONE;
+       char *ret_text = NULL;
+       char buf_key[32];
+       char *bundle_val = NULL;
+       char *new_text;
+       bundle *b;
+       notification_text_type_e type = NOTIFICATION_TEXT_TYPE_TITLE;
+
+       for (; type < NOTIFICATION_TEXT_TYPE_MAX; type++) {
+               noti_err = notification_get_text(noti, type, &ret_text);
+               if (noti_err == NOTIFICATION_ERROR_NONE && ret_text) {
+                       b = noti->b_text;
+                       if (b == NULL)
+                               b = bundle_create();
+
+                       new_text = strdup(ret_text);
+
+                       snprintf(buf_key, sizeof(buf_key), "%d", type);
+                       bundle_get_str(b, buf_key, &bundle_val);
+                       if (bundle_val != NULL)
+                               bundle_del(b, buf_key);
+
+                       bundle_add_str(b, buf_key, new_text);
+                       free(new_text);
+                       new_text = NULL;
+
+                       noti->num_format_args = 0;
+                       bundle_val = NULL;
+               }
+       }
+
+       if (noti->b_key) {
+               bundle_free(noti->b_key);
+               noti->b_key = NULL;
+       }
+
+       return noti_err;
+}
+
 EXPORT_API int notification_set_title(notification_h noti,
                                                       const char *title,
                                                       const char *loc_title)
index 92f6484..9062ac6 100755 (executable)
@@ -669,7 +669,7 @@ int notification_ipc_request_insert(notification_h noti, int *priv_id)
        noti->internal_group_id = NOTIFICATION_GROUP_ID_NONE;
 
        _print_noti(noti);
-       body = notification_ipc_make_gvariant_from_noti(noti);
+       body = notification_ipc_make_gvariant_from_noti(noti, false);
        if (body == NULL) {
                NOTIFICATION_ERR("cannot make gvariant");
                return NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -708,7 +708,7 @@ int notification_ipc_request_update(notification_h noti)
                return result;
        }
 
-       body = notification_ipc_make_gvariant_from_noti(noti);
+       body = notification_ipc_make_gvariant_from_noti(noti, false);
        if (body == NULL) {
                NOTIFICATION_ERR("cannot make gvariant");
                return NOTIFICATION_ERROR_OUT_OF_MEMORY;
@@ -747,7 +747,7 @@ int notification_ipc_request_update_async(notification_h noti,
        cb_item->result_cb = result_cb;
        cb_item->data = user_data;
 
-       body = notification_ipc_make_gvariant_from_noti(noti);
+       body = notification_ipc_make_gvariant_from_noti(noti, false);
        if (body == NULL) {
                NOTIFICATION_ERR("cannot make gvariant");
                free(cb_item);
@@ -1234,7 +1234,7 @@ int notification_ipc_update_system_setting(notification_system_setting_h system_
        return result;
 }
 
-EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti)
+EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h noti, bool translate)
 {
        NOTIFICATION_DBG("make gvariant from noti");
        int i = 0;
@@ -1254,6 +1254,9 @@ EXPORT_API GVariant *notification_ipc_make_gvariant_from_noti(notification_h not
        GVariant *result_body = NULL;
        GVariantBuilder builder;
 
+       if (translate)
+               notification_translate_localized_text(noti);
+
        g_variant_builder_init(&builder, G_VARIANT_TYPE("a{iv}"));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_NOTI_TYPE, g_variant_new_int32(noti->type));
        g_variant_builder_add(&builder, "{iv}", NOTIFICATION_DATA_TYPE_LAYOUT, g_variant_new_int32(noti->layout));