Today, the question came up of how we can change the translation of the UI when you pick a different language. This is made more complicated by the facts that the UI is all instantiated up front, and that you can change translation from a spoke off the first hub. The latter problem means we can't just have a separate "choose your language" program up front. In the old UI, we delete the windows and reload them. I have a strict policy against deleting screens in the new UI, so we can't do that. I thus present the attached patch, which works well enough in my testing. It obviously needs further cleanup. All the 'XXXXXXXXX' stuff is because there's currently no translations of the new UI so I need something to prove that it works. - Chris diff --git a/pyanaconda/ui/gui/__init__.py b/pyanaconda/ui/gui/__init__.py index ca08edc..8dd1e99 100644 --- a/pyanaconda/ui/gui/__init__.py +++ b/pyanaconda/ui/gui/__init__.py @@ -214,6 +214,29 @@ class UIObject(object): """ pass + def retranslate(self): + from gi.repository import AnacondaWidgets, Gtk + + # Widget class -> (getter, setter) -or- + # Widget class -> (setter, ) + widgetMap = { AnacondaWidgets.StandaloneWindow: ("retranslate", ), + Gtk.Button: ("get_label", "set_label"), + Gtk.Label: ("get_label", "set_label") } + classes = widgetMap.keys() + + objs = filter(lambda obj: obj.__class__ in classes, self.builder.get_objects()) + for obj in objs: + klass = obj.__class__ + funcs = widgetMap[klass] + + if len(funcs) == 1: + getattr(obj, funcs[0])() + else: + before = getattr(obj, funcs[0])() + #xlated = _(before) + #getattr(obj, funcs[1])(xlated) + getattr(obj, funcs[1])("XXXXXXXXXX") + def setup(self): """Perform whatever actions are necessary to set defaults on the UI. This method may be called multiple times, so it's important to not diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py index c5d0e1d..167f012 100644 --- a/pyanaconda/ui/gui/spokes/welcome.py +++ b/pyanaconda/ui/gui/spokes/welcome.py @@ -76,6 +76,8 @@ class WelcomeLanguageSpoke(StandaloneSpoke): (store, selected) = selection.get_selected_rows() self.window.set_may_continue(len(selected) > 0) + self.retranslate() + # Override the default in StandaloneSpoke so we can display the beta # warning dialog first. def _on_continue_clicked(self, cb): diff --git a/pyanaconda/ui/gui/spokes/welcome.ui b/pyanaconda/ui/gui/spokes/welcome.ui index b1894d5..d6cacd7 100644 --- a/pyanaconda/ui/gui/spokes/welcome.ui +++ b/pyanaconda/ui/gui/spokes/welcome.ui @@ -242,7 +242,9 @@ OS you can rely on. It's for testing purposes only.</property> <property name="headers_visible">False</property> <property name="search_column">0</property> <child internal-child="selection"> - <object class="GtkTreeSelection" id="treeview-selection"/> + <object class="GtkTreeSelection" id="treeview-selection"> + <signal name="changed" handler="on_selection_changed" swapped="no"/> + </object> </child> <child> <object class="GtkTreeViewColumn" id="nativeName"> diff --git a/widgets/src/BaseWindow.c b/widgets/src/BaseWindow.c index 44c60ef..a1f7da0 100644 --- a/widgets/src/BaseWindow.c +++ b/widgets/src/BaseWindow.c @@ -407,6 +407,32 @@ void anaconda_base_window_clear_info(AnacondaBaseWindow *win) { win->priv->info_shown = FALSE; } +void anaconda_base_window_retranslate(AnacondaBaseWindow *win) { + char *markup; + GValue distro = G_VALUE_INIT; + + g_value_init(&distro, G_TYPE_STRING); + /* g_value_set_string(&distro, gtk_label_get_text(GTK_LABEL(win->priv->distro_label))); */ + g_value_set_string(&distro, "XXXXXXXXXX"); + + /* A window name is not necessarily set. */ + if (strcmp(gtk_label_get_text(GTK_LABEL(win->priv->name_label)), "") != 0) { + GValue name = G_VALUE_INIT; + + g_value_init(&name, G_TYPE_STRING); + /* g_value_set_string(&name, gtk_label_get_text(GTK_LABEL(win->priv->name_label))); */ + g_value_set_string(&name, "XXXXXXXXXX"); + + anaconda_base_window_set_property((GObject *) win, PROP_WINDOW_NAME, &name, NULL); + } + + anaconda_base_window_set_property((GObject *) win, PROP_DISTRIBUTION, &distro, NULL); + + markup = g_markup_printf_escaped("<span foreground='red' weight='bold' size='large'>%s</span>", "XXXXXXXXXX"); + gtk_label_set_markup(GTK_LABEL(win->priv->beta_label), markup); + g_free(markup); +} + static GtkBuildableIface *parent_buildable_iface; static void diff --git a/widgets/src/BaseWindow.h b/widgets/src/BaseWindow.h index f1132f6..222fb8d 100644 --- a/widgets/src/BaseWindow.h +++ b/widgets/src/BaseWindow.h @@ -62,6 +62,8 @@ struct _AnacondaBaseWindowClass { GType anaconda_base_window_get_type (void); GtkWidget *anaconda_base_window_new (); +void anaconda_base_window_retranslate (AnacondaBaseWindow *win); + gboolean anaconda_base_window_get_beta (AnacondaBaseWindow *win); void anaconda_base_window_set_beta (AnacondaBaseWindow *win, gboolean is_beta); diff --git a/widgets/src/StandaloneWindow.c b/widgets/src/StandaloneWindow.c index 5ceddd4..d770e93 100644 --- a/widgets/src/StandaloneWindow.c +++ b/widgets/src/StandaloneWindow.c @@ -190,3 +190,9 @@ void anaconda_standalone_window_set_may_continue(AnacondaStandaloneWindow *win, gboolean may_continue) { gtk_widget_set_sensitive(win->priv->continue_button, may_continue); } + +void anaconda_standalone_window_retranslate(AnacondaStandaloneWindow *win) { + anaconda_base_window_retranslate(ANACONDA_BASE_WINDOW(win)); + gtk_button_set_label(GTK_BUTTON(win->priv->quit_button), "XXXXXXXXXX"); + gtk_button_set_label(GTK_BUTTON(win->priv->continue_button), "XXXXXXXXXX"); +} diff --git a/widgets/src/StandaloneWindow.h b/widgets/src/StandaloneWindow.h index b1ba029..0838b20 100644 --- a/widgets/src/StandaloneWindow.h +++ b/widgets/src/StandaloneWindow.h @@ -72,6 +72,7 @@ GType anaconda_standalone_window_get_type (void); GtkWidget *anaconda_standalone_window_new (); gboolean anaconda_standalone_window_get_may_continue (AnacondaStandaloneWindow *win); void anaconda_standalone_window_set_may_continue (AnacondaStandaloneWindow *win, gboolean may_continue); +void anaconda_standalone_window_retranslate (AnacondaStandaloneWindow *win); G_END_DECLS _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list