Skip to content

Commit

Permalink
fix: i18n of gtk msgbox buttons
Browse files Browse the repository at this point in the history
similar to #19756 (12df0e8) but for messageboxes
  • Loading branch information
ckerr committed Aug 22, 2019
1 parent 5e525b3 commit d74952b
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions shell/browser/ui/message_box_gtk.cc
Expand Up @@ -4,8 +4,6 @@

#include "shell/browser/ui/message_box.h"

#include <glib/gi18n.h>

#include "base/callback.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand Down Expand Up @@ -33,6 +31,27 @@ MessageBoxSettings::~MessageBoxSettings() = default;

namespace {

// Copied from L40-L55 in
// https://cs.chromium.org/chromium/src/chrome/browser/ui/libgtkui/select_file_dialog_impl_gtk.cc
#if GTK_CHECK_VERSION(3, 90, 0)
// GTK stock items have been deprecated. The docs say to switch to using the
// strings "_Open", etc. However this breaks i18n. We could supply our own
// internationalized strings, but the "_" in these strings is significant: it's
// the keyboard shortcut to select these actions. TODO: Provide
// internationalized strings when GTK provides support for it.
const char kCancelLabel[] = "_Cancel";
const char kNoLabel[] = "_No";
const char kOkLabel[] = "_OK";
const char kYesLabel[] = "_Yes";
#else
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
const char* kCancelLabel = GTK_STOCK_CANCEL;
const char* kNoLabel = GTK_STOCK_NO;
const char* kOkLabel = GTK_STOCK_OK;
const char* kYesLabel = GTK_STOCK_YES;
G_GNUC_END_IGNORE_DEPRECATIONS
#endif

class GtkMessageBox : public NativeWindowObserver {
public:
explicit GtkMessageBox(const MessageBoxSettings& settings)
Expand Down Expand Up @@ -123,13 +142,13 @@ class GtkMessageBox : public NativeWindowObserver {
const char* TranslateToStock(int id, const std::string& text) {
const std::string lower = base::ToLowerASCII(text);
if (lower == "cancel")
return _("_Cancel");
return kCancelLabel;
if (lower == "no")
return _("_No");
return kNoLabel;
if (lower == "ok")
return _("_OK");
return kOkLabel;
if (lower == "yes")
return _("_Yes");
return kYesLabel;
return text.c_str();
}

Expand Down

0 comments on commit d74952b

Please sign in to comment.