Search code examples
cdialoginternationalizationgtk

Do GTK file chooser dialogs come with localized strings for buttons and titles?


On Windows and macOS, file chooser dialogs are built into the operating system, and there is a way for an application to tell the dialog to localize the text on buttons and titles to the system language (usually by not explicitly setting the button and title text).

On Linux, while there is no system file chooser dialog, the vast majority of applications use GTK. However, GTK's file chooser dialogs require users to provide strings for the button and title text:

dialog = gtk_file_chooser_dialog_new ("Open File",
                                      parent_window,
                                      action,
                                      "_Cancel",
                                      GTK_RESPONSE_CANCEL,
                                      "_Open",
                                      GTK_RESPONSE_ACCEPT,
                                      NULL);

Leaving those strings empty or null leads to the buttons and title having no text at all, instead of having some default text.

Does GTK have its own set of localized default button and title text that application developers can tap into?

Note that many Linux applications use the gettext internationalization library, but that depends on the application to provide a translation database for every language they wish to support, which is not what I'm looking for. I'm looking for a way for my application to show proper dialog text in every language that GTK knows about, even if my application doesn't have translated strings for them.

Note also that that GTK message dialogs created with gtk_message_dialog_new can have correctly translated button text, assuming that the user has installed the correct language packs, as no text is explicitly specified (you just pass GTK_BUTTONS_OK_CANCEL to it to get correctly translated "OK" and "Cancel" buttons), but there seems to be no equivalent for file chooser dialogs.


Solution

  • Short answer: no.

    There is an essential difference between the behavior of gtk_message_dialog and gtk_file_chooser_dialog. With gnome focusing on flatpak development, while gtk_message_dialog will always use the GTK dialog, a call from an application to gtk_file_chooser_dialog will not always use the GTK chooser dialog. If the application is running in a QT environment, this call will open the standard QT environment chooser dialog. The same thing goes for any other environment.

    When this happens, the translation of the content of the buttons may differ from the way GTK does it and therefore the application is responsible for carrying out this translation, since we do not know whether or not the other environment will do this, or how it will do it. to do.