elm: Introduce interface Efl.Ui.Translatable

This will be used to replace the part translation API in Elm.Widget. It
should work for both parts and non-parts (ie. the main text of a button,
for instance).

For now I'm taking the following approach:
 - All efl_text_set/get strings are untranslatable, i.e. get() returns
   the visible string, set replaces and can not be translated.
 - translatable_text_set/get needs to be used to enable automatic
   translation, which in turns calls efl_text_set to modify the visible
   string. Thus, translatable applications will have to use
   efl_ui_translatable_text_set a lot more than efl_text_set, unless
   they translate strings application-side.

Note that some other frameworks take a simpler approach equivalent to
calling efl_text_set() with an already translated text. This prevents
runtime language changes of the application, unless the application
handles them specifically.
This commit is contained in:
Jean-Philippe Andre 2017-09-22 15:13:16 +09:00
parent 2b7f9b6dfd
commit 839c4ed395
33 changed files with 112 additions and 55 deletions

View File

@ -140,6 +140,7 @@ elm_public_eolian_files = \
lib/elementary/efl_ui_focus_user.eo \
lib/elementary/efl_ui_textpath.eo \
lib/elementary/efl_ui_textpath_part.eo \
lib/elementary/efl_ui_translatable.eo \
$(NULL)
# Private classes (not exposed or shipped)

View File

@ -151,6 +151,7 @@ EAPI extern Elm_Version *elm_version;
# include "efl_ui_focus_manager_root_focus.eo.h"
# include "efl_ui_focus_user.eo.h"
# include <efl_ui_textpath.eo.h>
# include <efl_ui_translatable.eo.h>
#endif
#include <elm_tooltip.h>

View File

@ -408,12 +408,12 @@ _reload_format(Evas_Object *obj)
}
EOLIAN static void
_efl_ui_clock_elm_widget_translate(Eo *obj, Efl_Ui_Clock_Data *sd)
_efl_ui_clock_efl_ui_translatable_translation_update(Eo *obj, Efl_Ui_Clock_Data *sd)
{
if (!sd->user_format) _reload_format(obj);
else _field_list_display(obj);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static Eina_List *

View File

@ -229,7 +229,7 @@ class Efl.Ui.Clock (Efl.Ui.Layout)
Elm.Widget.focus_next;
Elm.Widget.on_disabled_update;
Elm.Widget.on_focus_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
}
events {
changed; [[Called when clock changed]]

View File

@ -0,0 +1,58 @@
interface Efl.Ui.Translatable
{
[[Interface for all translatable text APIs.
This is intended for translation of human readable on-screen text strings,
but may also be used in text-to-speech situations.
]]
methods {
@property translatable_text {
[[A unique string to be translated.
Often this will be a human-readable string (eg. in English) but it
might as well be a unique string identifier that must then be
translated to the current locale with $dgettext() or any similar
mechanism.
Setting this property will enable translation for this object or
part.
]]
set {
[[Sets the new untranslated string and domain for this object.]]
}
get {
values {
domain: string @optional; [[A translation domain. If $null
this means the default domain is used.]]
}
return: string; [[This returns the untranslated value of $label.
The translated string can usually be retrieved with
$Efl.Text.text.get.]]
}
values {
label: string; [[A unique (untranslated) string.]]
domain: string @optional; [[A translation domain. If $null this
uses the default domain (eg. set by $textdomain()).]]
}
}
translation_update @protected {
[[Requests this object to update its text strings for the current
locale.
For the moment, strings are translated with $dgettext, so support for
this function may depend on the platform. It is up to the application
to provide their own translation data.
This function is a hook meant to be implemented by any object that
supports translation. This might be called whenever a new object is
created or when the current locale changes, for instance. This should
only trigger further calls to @.translation_update to children
objects.
]]
}
}
events {
/* FIXME: Shouldn't language,change be here? */
}
}

View File

@ -3679,7 +3679,7 @@ _elm_win_translate(void)
Evas_Object *obj;
EINA_LIST_FOREACH(_elm_win_list, l, obj)
elm_widget_translate(obj);
efl_ui_translatable_translation_update(obj);
}
void

View File

@ -45,14 +45,14 @@ static const Elm_Action key_actions[] = {
};
EOLIAN static void
_elm_combobox_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Combobox_Data *sd)
_elm_combobox_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Combobox_Data *sd)
{
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
elm_obj_widget_translate(sd->genlist);
elm_obj_widget_translate(sd->entry);
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(sd->genlist);
efl_ui_translatable_translation_update(sd->entry);
if (sd->hover)
elm_obj_widget_translate(sd->hover);
efl_ui_translatable_translation_update(sd->hover);
}
EOLIAN static Efl_Ui_Theme_Apply

View File

@ -48,7 +48,7 @@ static const Elm_Action key_actions[] = {
};
EOLIAN static void
_elm_ctxpopup_elm_widget_translate(Eo *obj, Elm_Ctxpopup_Data *sd)
_elm_ctxpopup_efl_ui_translatable_translation_update(Eo *obj, Elm_Ctxpopup_Data *sd)
{
Eina_List *l;
Elm_Object_Item *it;
@ -58,7 +58,7 @@ _elm_ctxpopup_elm_widget_translate(Eo *obj, Elm_Ctxpopup_Data *sd)
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(it);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
EOLIAN static Eina_Bool

View File

@ -49,7 +49,7 @@ static const Elm_Action key_actions[] = {
};
EOLIAN static void
_elm_hoversel_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd)
_elm_hoversel_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd)
{
Eo *it;
Eina_List *l;
@ -57,7 +57,7 @@ _elm_hoversel_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Hoversel_Data *sd)
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(it);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
EOLIAN static Efl_Ui_Theme_Apply

View File

@ -64,7 +64,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(_multi_buttonentry_cb,
);
EOLIAN static void
_elm_multibuttonentry_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Multibuttonentry_Data *sd)
_elm_multibuttonentry_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Multibuttonentry_Data *sd)
{
Elm_Object_Item *it;
Eina_List *l;
@ -72,7 +72,7 @@ _elm_multibuttonentry_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Multibuttone
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(it);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static char *

View File

@ -105,14 +105,14 @@ _prev_page_focus_recover(Elm_Naviframe_Item_Data *it)
}
EOLIAN static void
_elm_naviframe_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Naviframe_Data *sd)
_elm_naviframe_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Naviframe_Data *sd)
{
Elm_Naviframe_Item_Data *it;
EINA_INLIST_FOREACH(sd->stack, it)
elm_wdg_item_translate(EO_OBJ(it));
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static void

View File

@ -67,7 +67,7 @@ EFL_CALLBACKS_ARRAY_DEFINE(_notify_cb,
static void _on_content_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
EOLIAN static void
_elm_popup_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Popup_Data *sd)
_elm_popup_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Popup_Data *sd)
{
Elm_Popup_Item_Data *it;
Eina_List *l;
@ -75,8 +75,8 @@ _elm_popup_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Popup_Data *sd)
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(EO_OBJ(it));
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
elm_obj_widget_translate(sd->main_layout);
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(sd->main_layout);
}
static void

View File

@ -40,7 +40,7 @@ class Elm.Combobox (Efl.Ui.Button, Efl.Ui.Selectable,
Efl.Gfx.visible { set; }
Efl.Gfx.size { set; }
Elm.Widget.theme_apply;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_event;
Efl.Ui.Autorepeat.autorepeat_supported { get; }
Elm.Genlist.filter { set; }

View File

@ -208,7 +208,7 @@ class Elm.Ctxpopup (Efl.Ui.Layout, Elm.Interface.Atspi_Widget_Action,
Elm.Widget.focus_next;
Elm.Widget.on_disabled_update;
Elm.Widget.widget_sub_object_add;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.theme_apply;
Elm.Widget.widget_event;
Efl.Ui.Menu.selected_item { get; }

View File

@ -56,7 +56,7 @@ _dayselector_resize(void *data,
}
EOLIAN static void
_elm_dayselector_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
_elm_dayselector_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Dayselector_Data *sd)
{
time_t t;
Eina_List *l;
@ -76,7 +76,7 @@ _elm_dayselector_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Dayselector_Data
elm_object_text_set(VIEW(it), buf);
}
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static void

View File

@ -153,7 +153,7 @@ class Elm.Dayselector (Efl.Ui.Layout)
Efl.Object.constructor;
Elm.Widget.theme_apply;
Elm.Widget.focus_direction_manager_is;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Efl.Part.part;
}
events {

View File

@ -49,7 +49,7 @@ static const Elm_Action key_actions[] = {
};
EOLIAN static void
_elm_diskselector_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Diskselector_Data *sd)
_elm_diskselector_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Diskselector_Data *sd)
{
Elm_Diskselector_Item_Data *it;
Eina_List *l;

View File

@ -206,7 +206,7 @@ class Elm.Diskselector (Elm.Widget, Elm.Interface_Scrollable,
Elm.Widget.focus_next;
Elm.Widget.theme_apply;
Elm.Widget.on_focus_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_sub_object_del;
Elm.Widget.widget_event;
Elm.Interface_Scrollable.policy { get; set; }

View File

@ -97,7 +97,7 @@ class Elm.Hoversel (Efl.Ui.Button, Efl.Ui.Selectable,
Efl.Gfx.visible { set; }
Elm.Widget.widget_parent { set; }
Elm.Widget.theme_apply;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_event;
Efl.Ui.Autorepeat.autorepeat_supported { get; }
Elm.Interface.Atspi_Widget_Action.elm_actions { get; }

View File

@ -632,7 +632,7 @@ static Eina_Bool _key_action_escape(Evas_Object *obj, const char *params EINA_UN
}
EOLIAN static void
_elm_list_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_List_Data *sd)
_elm_list_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_List_Data *sd)
{
Elm_Object_Item *it;
Eina_List *l;
@ -640,7 +640,7 @@ _elm_list_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_List_Data *sd)
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(it);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static void

View File

@ -441,7 +441,7 @@ class Elm.List (Efl.Ui.Layout, Elm.Interface_Scrollable,
Elm.Widget.focus_next;
Elm.Widget.on_disabled_update;
Elm.Widget.on_focus_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_sub_object_del;
Elm.Widget.widget_event;
Elm.Widget.focused_item { get; }

View File

@ -32,7 +32,7 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
#undef ELM_PRIV_MENU_SIGNALS
EOLIAN static void
_elm_menu_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
_elm_menu_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Menu_Data *sd)
{
Elm_Menu_Item_Data *it;
Eina_List *l;

View File

@ -59,7 +59,7 @@ class Elm.Menu (Elm.Widget, Efl.Ui.Clickable, Efl.Ui.Menu,
Efl.Gfx.visible { set; }
Elm.Widget.widget_parent { get; set; }
Elm.Widget.theme_apply;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.focus_manager_create;
Elm.Interface.Atspi_Accessible.children { get; }
Efl.Access.Selection.selected_children_count { get; }

View File

@ -185,7 +185,7 @@ class Elm.Multibuttonentry (Efl.Ui.Layout, Efl.Ui.Clickable)
Elm.Widget.focus_direction;
Elm.Widget.focus_next;
Elm.Widget.on_focus_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_event;
Elm.Interface.Atspi_Accessible.children { get; }
Efl.Part.part;

View File

@ -149,7 +149,7 @@ class Elm.Naviframe (Efl.Ui.Layout, Elm.Interface.Atspi_Widget_Action)
Elm.Widget.focus_direction_manager_is;
Elm.Widget.on_access_update;
Elm.Widget.focus_next;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.theme_apply;
Elm.Widget.widget_event;
Efl.Canvas.Layout_Signal.signal_emit;

View File

@ -175,7 +175,7 @@ class Elm.Popup (Efl.Ui.Layout, Elm.Interface.Atspi_Widget_Action)
Elm.Widget.on_access_update;
Elm.Widget.focus_next;
Elm.Widget.widget_parent { set; }
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_sub_object_del;
Elm.Widget.widget_event;
Efl.Canvas.Layout_Signal.signal_emit;

View File

@ -26,7 +26,7 @@ static const Evas_Smart_Cb_Description _smart_callbacks[] = {
};
EOLIAN static void
_elm_segment_control_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Segment_Control_Data *sd)
_elm_segment_control_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Segment_Control_Data *sd)
{
Elm_Object_Item *it;
Eina_List *l;
@ -34,7 +34,7 @@ _elm_segment_control_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Segment_Contr
EINA_LIST_FOREACH(sd->items, l, it)
elm_wdg_item_translate(it);
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
EOLIAN static void

View File

@ -142,7 +142,7 @@ class Elm.Segment_Control (Efl.Ui.Layout)
Elm.Widget.focus_direction_manager_is;
Elm.Widget.on_access_update;
Elm.Widget.on_disabled_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
}
events {
changed; [[Called when segment control changed]]

View File

@ -1724,14 +1724,14 @@ _elm_toolbar_item_elm_widget_item_part_content_unset(Eo *eo_item EINA_UNUSED, El
}
EOLIAN static void
_elm_toolbar_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Toolbar_Data *sd)
_elm_toolbar_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Toolbar_Data *sd)
{
Elm_Toolbar_Item_Data *it;
EINA_INLIST_FOREACH(sd->items, it)
elm_wdg_item_translate(EO_OBJ(it));
elm_obj_widget_translate(efl_super(obj, MY_CLASS));
efl_ui_translatable_translation_update(efl_super(obj, MY_CLASS));
}
static void

View File

@ -325,7 +325,7 @@ class Elm.Toolbar (Elm.Widget, Elm.Interface_Scrollable, Efl.Ui.Direction,
Elm.Widget.focus_next;
Elm.Widget.theme_apply;
Elm.Widget.on_focus_update;
Elm.Widget.translate;
Efl.Ui.Translatable.translation_update;
Elm.Widget.widget_event;
Elm.Widget.focus_highlight_geometry { get; }
Elm.Widget.focused_item { get; }

View File

@ -3882,7 +3882,7 @@ elm_widget_part_text_translate(Eo *obj, const char *part, const char *text)
}
EOLIAN static void
_elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
_elm_widget_efl_ui_translatable_translation_update(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
{
const Eina_List *l;
Evas_Object *child;
@ -3890,10 +3890,10 @@ _elm_widget_translate(Eo *obj EINA_UNUSED, Elm_Widget_Smart_Data *sd)
EINA_LIST_FOREACH(sd->subobjs, l, child)
{
if (elm_widget_is(child))
elm_widget_translate(child);
efl_ui_translatable_translation_update(child);
}
if (sd->hover_obj) elm_widget_translate(sd->hover_obj);
if (sd->hover_obj) efl_ui_translatable_translation_update(sd->hover_obj);
#ifdef HAVE_GETTEXT
Elm_Translate_String_Data *ts;
@ -6693,3 +6693,6 @@ ELM_PART_TEXT_DEFAULT_GET(elm_widget, NULL)
#include "elm_widget_item.eo.c"
#include "elm_widget.eo.c"
/* Others */
#include "efl_ui_translatable.eo.c"

View File

@ -19,7 +19,8 @@ struct Elm.Widget.Focus_State {
abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
Efl.Access.Component, Efl.Ui.Focus.User, Efl.Part,
Efl.Ui.Focus.Object, Efl.Ui.Base, Efl.Ui.Cursor)
Efl.Ui.Focus.Object, Efl.Ui.Base, Efl.Ui.Cursor,
Efl.Ui.Translatable)
{
[[Elementary widget abstract class]]
legacy_prefix: elm_widget;
@ -285,14 +286,6 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
}
/* Translation & Text API. */
translate @protected {
[[Virtual function handling language changes.
If a widget is composed of multiple sub-objects, this function might
need to be reimplemented to translate all those sub-objects that
have visible (or accessible) translatable text.
]]
}
@property domain_part_text_translatable {
[[Translate domain text part property]]
set {
@ -860,6 +853,7 @@ abstract Elm.Widget (Efl.Canvas.Group, Elm.Interface.Atspi_Accessible,
Efl.Ui.Cursor.cursor { get; set; }
Efl.Ui.Cursor.cursor_style { get; set; }
Efl.Ui.Cursor.cursor_theme_search_enabled { get; set; }
Efl.Ui.Translatable.translation_update; [[This implements the calls to $gettext() and $text_set().]]
Efl.Part.part; [[Returns @Efl.Ui.Widget.Part.]]
}
events {

View File

@ -635,7 +635,7 @@ EAPI Eina_Bool elm_widget_api_check(int ver);
EAPI Eina_Bool elm_widget_access(Evas_Object *obj, Eina_Bool is_access);
EAPI Efl_Ui_Theme_Apply elm_widget_theme(Evas_Object *obj);
EAPI void elm_widget_theme_specific(Evas_Object *obj, Elm_Theme *th, Eina_Bool force);
EAPI void elm_widget_translate(Evas_Object *obj);
EAPI void efl_ui_translatable_translation_update(Evas_Object *obj);
EAPI void elm_widget_on_show_region_hook_set(Evas_Object *obj, void *data, Efl_Ui_Scrollable_On_Show_Region func, Eina_Free_Cb data_free);
EAPI Eina_Bool elm_widget_sub_object_parent_add(Evas_Object *sobj);
EAPI Eina_Bool elm_widget_sub_object_add(Evas_Object *obj, Evas_Object *sobj);