elementary - added elm_object_item_translatable_part_text_set() elm_object_item_translatable_part_text_get()

SVN revision: 83852
This commit is contained in:
ChunEon Park 2013-02-12 10:38:33 +00:00
parent 35c5f65051
commit 867084e7ba
6 changed files with 160 additions and 0 deletions

View File

@ -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().

View File

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

View File

@ -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)
{

View File

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

View File

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

View File

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