From 867084e7ba2f95969f5f974d38d7eca4ae5ccfef Mon Sep 17 00:00:00 2001 From: ChunEon Park Date: Tue, 12 Feb 2013 10:38:33 +0000 Subject: [PATCH] elementary - added elm_object_item_translatable_part_text_set() elm_object_item_translatable_part_text_get() SVN revision: 83852 --- legacy/elementary/ChangeLog | 4 + legacy/elementary/NEWS | 1 + legacy/elementary/src/lib/elm_main.c | 13 +++ legacy/elementary/src/lib/elm_object_item.h | 49 +++++++++++ legacy/elementary/src/lib/elm_widget.c | 90 +++++++++++++++++++++ legacy/elementary/src/lib/elm_widget.h | 3 + 6 files changed, 160 insertions(+) diff --git a/legacy/elementary/ChangeLog b/legacy/elementary/ChangeLog index 02955fa2bd..0a69ebc270 100644 --- a/legacy/elementary/ChangeLog +++ b/legacy/elementary/ChangeLog @@ -992,3 +992,7 @@ 2013-02-13 ChunEon Park (Hermet) * Ctxpopup will be dismissed when elm language is changed. + +2013-02-13 ChunEon Park (Hermet) + + * added APIs - elm_object_item_translatable_part_text_set(), elm_object_item_translatable_part_text_get(). diff --git a/legacy/elementary/NEWS b/legacy/elementary/NEWS index 3a481536b6..d5f1098c0d 100644 --- a/legacy/elementary/NEWS +++ b/legacy/elementary/NEWS @@ -34,6 +34,7 @@ Additions: * Add elm_index smart callback - "language,changed". * Add smart callback signals of a scroller. "vbar,drag", "vbar,press", "vbar,unpress", "hbar,drag", "hbar,press", "hbar,unpress". * Add elm_glview, elm_gengrid smart callback - "language,changed". + * Add APIs - elm_object_item_translatable_part_text_set(), elm_object_item_translatable_part_text_get(). Improvements: diff --git a/legacy/elementary/src/lib/elm_main.c b/legacy/elementary/src/lib/elm_main.c index 05492a7ca2..1e5d02fdd9 100644 --- a/legacy/elementary/src/lib/elm_main.c +++ b/legacy/elementary/src/lib/elm_main.c @@ -1516,6 +1516,19 @@ elm_object_item_part_text_get(const Elm_Object_Item *it, const char *part) return _elm_widget_item_part_text_get((Elm_Widget_Item *)it, part); } +EAPI void +elm_object_item_domain_translatable_part_text_set(Elm_Object_Item *it, const char *part, const char *domain, const char *text) +{ + _elm_widget_item_domain_translatable_part_text_set((Elm_Widget_Item *)it, part, domain, text); +} + +EAPI const char * +elm_object_item_translatable_part_text_get(const Elm_Object_Item *it, const char *part) +{ + return _elm_widget_item_translatable_part_text_get((Elm_Widget_Item *)it, part); +} + + EAPI void elm_object_access_info_set(Evas_Object *obj, const char *txt) { diff --git a/legacy/elementary/src/lib/elm_object_item.h b/legacy/elementary/src/lib/elm_object_item.h index 43491d134b..a01648af3b 100644 --- a/legacy/elementary/src/lib/elm_object_item.h +++ b/legacy/elementary/src/lib/elm_object_item.h @@ -98,6 +98,55 @@ EAPI const char *elm_object_item_part_text_get(const Elm_Object #define elm_object_item_text_get(it) elm_object_item_part_text_get((it), NULL) +/** + * Set the text for an object item's part, marking it as translatable. + * + * The string to set as @p text must be the original one. Do not pass the + * return of @c gettext() here. Elementary will translate the string + * internally and set it on the object item using + * elm_object_item_part_text_set(), also storing the original string so that it + * can be automatically translated when the language is changed with + * elm_language_set(). The @p domain will be stored along to find the + * translation in the correct catalog. It can be NULL, in which case it will use + * whatever domain was set by the application with @c textdomain(). This is + * useful in case you are building a library on top of Elementary that will have + * its own translatable strings, that should not be mixed with those of programs + * using the library. + * + * @param it The object item containing the text part + * @param part The name of the part to set + * @param domain The translation domain to use + * @param text The original, non-translated text to set + * + * @ingroup General + * @since 1.8 + */ +EAPI void elm_object_item_domain_translatable_part_text_set(Elm_Object_Item *it, const char *part, const char *domain, const char *text); + +#define elm_object_item_domain_translatable_text_set(it, domain, text) elm_object_item_domain_translatable_part_text_set((it), NULL, (domain), (text)) + +#define elm_object_item_translatable_text_set(it, text) elm_object_item_domain_translatable_part_text_set((it), NULL, NULL, (text)) + +/** + * Gets the original string set as translatable for an object item. + * + * When setting translated strings, the function elm_object_item_part_text_get() + * will return the translation returned by @c gettext(). To get the original + * string use this function. + * + * @param it The object item. + * @param part The name of the part that was set + * + * @return The original, untranslated string + * + * @ingroup General + * @since 1.8 + */ +EAPI const char *elm_object_item_translatable_part_text_get(const Elm_Object_Item *it, const char *part); + +#define elm_object_item_translatable_text_get(it) elm_object_item_translatable_part_text_get((it), NULL) + + /** * Set the text to read out when in accessibility mode * diff --git a/legacy/elementary/src/lib/elm_widget.c b/legacy/elementary/src/lib/elm_widget.c index f3b2012927..bbae69c5ca 100644 --- a/legacy/elementary/src/lib/elm_widget.c +++ b/legacy/elementary/src/lib/elm_widget.c @@ -4484,6 +4484,8 @@ _elm_widget_item_new(Evas_Object *widget, EAPI void _elm_widget_item_free(Elm_Widget_Item *item) { + Elm_Translate_String_Data *ts; + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item); if (item->del_func) @@ -4495,6 +4497,14 @@ _elm_widget_item_free(Elm_Widget_Item *item) if (item->access_info) eina_stringshare_del(item->access_info); + EINA_LIST_FREE (item->translate_strings, ts) + { + eina_stringshare_del(ts->id); + eina_stringshare_del(ts->domain); + eina_stringshare_del(ts->string); + free(ts); + } + EINA_MAGIC_SET(item, EINA_MAGIC_NONE); free(item); } @@ -4684,6 +4694,86 @@ _elm_widget_item_disable_hook_set(Elm_Widget_Item *item, item->disable_func = func; } +EAPI void +_elm_widget_item_domain_translatable_part_text_set(Elm_Widget_Item *item, + const char *part, + const char *domain, + const char *label) +{ + const char *str; + Eina_List *l; + Elm_Translate_String_Data *ts = NULL; + + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item); + + str = eina_stringshare_add(part); + EINA_LIST_FOREACH(item->translate_strings, l, ts) + { + if (ts->id == str) break; + else ts = NULL; + } + + if (!ts && !label) + eina_stringshare_del(str); + else if (!ts) + { + ts = malloc(sizeof(Elm_Translate_String_Data)); + if (!ts) return; + + ts->id = str; + ts->domain = eina_stringshare_add(domain); + ts->string = eina_stringshare_add(label); + item->translate_strings = eina_list_append(item->translate_strings, ts); + } + else + { + if (label) + { + eina_stringshare_replace(&ts->domain, domain); + eina_stringshare_replace(&ts->string, label); + } + else + { + item->translate_strings = eina_list_remove_list( + item->translate_strings, l); + eina_stringshare_del(ts->id); + eina_stringshare_del(ts->domain); + eina_stringshare_del(ts->string); + free(ts); + } + eina_stringshare_del(str); + } + +#ifdef HAVE_GETTEXT + if (label && label[0]) + label = dgettext(domain, label); +#endif + _elm_widget_item_part_text_set(item, part, label); +} + +EAPI const char * +_elm_widget_item_translatable_part_text_get(const Elm_Widget_Item *item, + const char *part) +{ + const char *str; + Eina_List *l; + Elm_Translate_String_Data *ts; + const char *ret = NULL; + + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL); + + str = eina_stringshare_add(part); + EINA_LIST_FOREACH(item->translate_strings, l, ts) + if (ts->id == str) + { + ret = ts->string; + break; + } + eina_stringshare_del(str); + + return ret; +} + typedef struct _Elm_Widget_Item_Tooltip Elm_Widget_Item_Tooltip; struct _Elm_Widget_Item_Tooltip diff --git a/legacy/elementary/src/lib/elm_widget.h b/legacy/elementary/src/lib/elm_widget.h index ed335e62da..ff622227aa 100644 --- a/legacy/elementary/src/lib/elm_widget.h +++ b/legacy/elementary/src/lib/elm_widget.h @@ -555,6 +555,7 @@ struct _Elm_Widget_Item Evas_Object *access_obj; const char *access_info; Eina_List *access_order; + Eina_List *translate_strings; Eina_Bool disabled : 1; }; @@ -730,6 +731,8 @@ EAPI void _elm_widget_item_disabled_set(Elm_Widget_Item *item, Eina_ EAPI Eina_Bool _elm_widget_item_disabled_get(const Elm_Widget_Item *item); EAPI void _elm_widget_item_disable_hook_set(Elm_Widget_Item *item, Elm_Widget_Disable_Cb func); EAPI void _elm_widget_item_del_pre_hook_set(Elm_Widget_Item *item, Elm_Widget_Del_Pre_Cb func); +EAPI void _elm_widget_item_domain_translatable_part_text_set(Elm_Widget_Item *item, const char *part, const char *domain, const char *label); +EAPI const char * _elm_widget_item_translatable_part_text_get(const Elm_Widget_Item *item, const char *part); /** * Function to operate on a given widget's scrollabe children when necessary.