From 6e4b76546950d53d1db61ce562952b812fe731e9 Mon Sep 17 00:00:00 2001 From: Mike Gorse Date: Wed, 3 May 2023 17:13:02 -0500 Subject: Use internal names when possible for localized role names This matches the behavior of atspi_accessible_get_role_name. We already hav translations from atk, so we can use those. Also, move the table for role name translations into atspi, since it seems that atk is increasingly becoming a legacy tool. Add a note to the xml indicating that it is optional to implement GetRoleName and GetLocalizedRoleName. Fixes #110 --- atk/atkobject.c | 123 ------------------------------------ atspi/atspi-accessible.c | 5 ++ atspi/atspi-misc.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++ atspi/atspi-misc.h | 2 + xml/Accessible.xml | 8 ++- 5 files changed, 173 insertions(+), 125 deletions(-) diff --git a/atk/atkobject.c b/atk/atkobject.c index 8d75d53d..89f85b4e 100644 --- a/atk/atkobject.c +++ b/atk/atkobject.c @@ -95,129 +95,6 @@ enum LAST_SIGNAL }; -/* These are listed here for extraction by intltool */ -#if 0 - N_("invalid") - N_("accelerator label") - N_("alert") - N_("animation") - N_("arrow") - N_("calendar") - N_("canvas") - N_("check box") - N_("check menu item") - N_("color chooser") - N_("column header") - N_("combo box") - N_("dateeditor") - N_("desktop icon") - N_("desktop frame") - N_("dial") - N_("dialog") - N_("directory pane") - N_("drawing area") - N_("file chooser") - N_("filler") - /* I know it looks wrong but that is what Java returns */ - N_("fontchooser") - N_("frame") - N_("glass pane") - N_("html container") - N_("icon") - N_("image") - N_("internal frame") - N_("label") - N_("layered pane") - N_("list") - N_("list item") - N_("menu") - N_("menu bar") - N_("menu button") - N_("menu item") - N_("option pane") - N_("page tab") - N_("page tab list") - N_("panel") - N_("password text") - N_("popup menu") - N_("progress bar") - N_("push button") - N_("radio button") - N_("radio menu item") - N_("root pane") - N_("row header") - N_("scroll bar") - N_("scroll pane") - N_("separator") - N_("slider") - N_("split pane") - N_("spin button") - N_("statusbar") - N_("table") - N_("table cell") - N_("table column header") - N_("table row header") - N_("tear off menu item") - N_("terminal") - N_("text") - N_("toggle button") - N_("tool bar") - N_("tool tip") - N_("tree") - N_("tree table") - N_("unknown") - N_("viewport") - N_("window") - N_("header") - N_("footer") - N_("paragraph") - N_("ruler") - N_("application") - N_("autocomplete") - N_("edit bar") - N_("embedded component") - N_("entry") - N_("chart") - N_("caption") - N_("document frame") - N_("heading") - N_("page") - N_("section") - N_("redundant object") - N_("form") - N_("link") - N_("input method window") - N_("table row") - N_("tree item") - N_("document spreadsheet") - N_("document presentation") - N_("document text") - N_("document web") - N_("document email") - N_("comment") - N_("list box") - N_("grouping") - N_("image map") - N_("notification") - N_("info bar") - N_("level bar") - N_("title bar") - N_("block quote") - N_("audio") - N_("video") - N_("definition") - N_("article") - N_("landmark") - N_("log") - N_("marquee") - N_("math") - N_("rating") - N_("timer") - N_("description list") - N_("description term") - N_("description value") -#endif /* 0 */ - typedef struct { gchar *accessible_id; diff --git a/atspi/atspi-accessible.c b/atspi/atspi-accessible.c index 65c1f354..54f67c8f 100644 --- a/atspi/atspi-accessible.c +++ b/atspi/atspi-accessible.c @@ -669,9 +669,14 @@ gchar * atspi_accessible_get_localized_role_name (AtspiAccessible *obj, GError **error) { char *retval = NULL; + AtspiRole role; g_return_val_if_fail (obj != NULL, NULL); + role = atspi_accessible_get_role (obj, error); + if (role >= 0 && role < ATSPI_ROLE_COUNT && role != ATSPI_ROLE_EXTENDED) + return g_strdup (atspi_role_get_localized_name (role)); + _atspi_dbus_call (obj, atspi_interface_accessible, "GetLocalizedRoleName", error, "=>s", &retval); if (!retval) diff --git a/atspi/atspi-misc.c b/atspi/atspi-misc.c index 9e68049d..11f37da2 100644 --- a/atspi/atspi-misc.c +++ b/atspi/atspi-misc.c @@ -43,6 +43,143 @@ * Miscellaneous methods for using AT-SPI services. */ +/* These are listed here for extraction by intltool */ +#if 0 + N_("invalid") + N_("accelerator label") + N_("alert") + N_("animation") + N_("arrow") + N_("calendar") + N_("canvas") + N_("check box") + N_("check menu item") + N_("color chooser") + N_("column header") + N_("combo box") + N_("dateeditor") + N_("desktop icon") + N_("desktop frame") + N_("dial") + N_("dialog") + N_("directory pane") + N_("drawing area") + N_("file chooser") + N_("filler") + /* I know it looks wrong but that is what Java returns */ + N_("fontchooser") + N_("frame") + N_("glass pane") + N_("html container") + N_("icon") + N_("image") + N_("internal frame") + N_("label") + N_("layered pane") + N_("list") + N_("list item") + N_("menu") + N_("menu bar") + N_("menu button") + N_("menu item") + N_("option pane") + N_("page tab") + N_("page tab list") + N_("panel") + N_("password text") + N_("popup menu") + N_("progress bar") + N_("push button") + N_("radio button") + N_("radio menu item") + N_("root pane") + N_("row header") + N_("scroll bar") + N_("scroll pane") + N_("separator") + N_("slider") + N_("split pane") + N_("spin button") + N_("statusbar") + N_("table") + N_("table cell") + N_("table column header") + N_("table row header") + N_("tear off menu item") + N_("terminal") + N_("text") + N_("toggle button") + N_("tool bar") + N_("tool tip") + N_("tree") + N_("tree table") + N_("unknown") + N_("viewport") + N_("window") + N_("header") + N_("footer") + N_("paragraph") + N_("ruler") + N_("application") + N_("autocomplete") + N_("edit bar") + N_("embedded component") + N_("entry") + N_("chart") + N_("caption") + N_("document frame") + N_("heading") + N_("page") + N_("section") + N_("redundant object") + N_("form") + N_("link") + N_("input method window") + N_("table row") + N_("tree item") + N_("document spreadsheet") + N_("document presentation") + N_("document text") + N_("document web") + N_("document email") + N_("comment") + N_("list box") + N_("grouping") + N_("image map") + N_("notification") + N_("info bar") + N_("level bar") + N_("title bar") + N_("block quote") + N_("audio") + N_("video") + N_("definition") + N_("article") + N_("landmark") + N_("log") + N_("marquee") + N_("math") + N_("rating") + N_("timer") + N_("description list") + N_("description term") + N_("description value") +#endif /* 0 */ + +static void +_gettext_initialization (void) +{ + static gboolean gettext_initialized = FALSE; + + if (!gettext_initialized) + { + gettext_initialized = TRUE; + setlocale (LC_ALL, ""); + bindtextdomain (GETTEXT_PACKAGE, ATSPI_LOCALEDIR); + bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); + } +} + static void handle_get_items (DBusPendingCall *pending, void *user_data); static DBusConnection *bus = NULL; @@ -1864,6 +2001,29 @@ atspi_role_get_name (AtspiRole role) return NULL; } +/** + * atspi_role_get_localized_name: + * @role: an #AtspiRole object to query. + * + * Gets the localized description string describing the #AtspiRole @role. + * + * Returns: the localized string describing the AtspiRole + **/ +const gchar * +atspi_role_get_localized_name (AtspiRole role) +{ + gchar *raw_name = NULL; + const gchar *ret; + + _gettext_initialization (); + + raw_name = atspi_role_get_name (role); + ret = dgettext (GETTEXT_PACKAGE, raw_name); + if (ret != raw_name) + g_free (raw_name); + return ret; +} + GHashTable * _atspi_dbus_update_cache_from_dict (AtspiAccessible *accessible, DBusMessageIter *iter) { diff --git a/atspi/atspi-misc.h b/atspi/atspi-misc.h index d820d94e..d262aff4 100644 --- a/atspi/atspi-misc.h +++ b/atspi/atspi-misc.h @@ -47,6 +47,8 @@ void atspi_set_main_context (GMainContext *cnx); gchar *atspi_role_get_name (AtspiRole role); + +const gchar *atspi_role_get_localized_name (AtspiRole role); G_END_DECLS #endif /* _ATSPI_MISC_H_ */ diff --git a/xml/Accessible.xml b/xml/Accessible.xml index 2ada7005..25e16994 100644 --- a/xml/Accessible.xml +++ b/xml/Accessible.xml @@ -729,7 +729,9 @@ Gets a UTF-8 string corresponding to the name of the role played by an object. This method will return useful values for roles that fall outside the - enumeration used in the GetRole method. + enumeration used in the GetRole method. Implementing this method is + optional, and it may be removed in a future version of the API. + Libatspi will only call id in the event of an unknown role. --> @@ -741,7 +743,9 @@ Gets a UTF-8 string corresponding to the name of the role played by an object, translated to the current locale. This method will return useful values for roles that fall outside the - enumeration used in the GetRole method. + enumeration used in the GetRole method. Implementing this method is + optional, and it may be removed in a future version of the API. + Libatspi will only call id in the event of an unknown role. --> -- cgit v1.2.1