fix: proper localization when using GtkFileChooserNative (#30888)
* fix: proper localization when using GtkFileChooserNative * fix: iwyu
This commit is contained in:
parent
a75617bff1
commit
38b810b2e3
4 changed files with 87 additions and 49 deletions
|
@ -8,36 +8,71 @@
|
|||
#include <gtk/gtk.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "base/no_destructor.h"
|
||||
#include "base/strings/string_number_conversions.h"
|
||||
#include "third_party/skia/include/core/SkBitmap.h"
|
||||
#include "third_party/skia/include/core/SkColor.h"
|
||||
#include "third_party/skia/include/core/SkUnPreMultiply.h"
|
||||
#include "ui/gtk/gtk_compat.h" // nogncheck
|
||||
|
||||
namespace gtk_util {
|
||||
|
||||
// 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* const kCancelLabel = "_Cancel";
|
||||
const char* const kNoLabel = "_No";
|
||||
const char* const kOkLabel = "_OK";
|
||||
const char* const kOpenLabel = "_Open";
|
||||
const char* const kSaveLabel = "_Save";
|
||||
const char* const kYesLabel = "_Yes";
|
||||
#else
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
const char* const kCancelLabel = GTK_STOCK_CANCEL;
|
||||
const char* const kNoLabel = GTK_STOCK_NO;
|
||||
const char* const kOkLabel = GTK_STOCK_OK;
|
||||
const char* const kOpenLabel = GTK_STOCK_OPEN;
|
||||
const char* const kSaveLabel = GTK_STOCK_SAVE;
|
||||
const char* const kYesLabel = GTK_STOCK_YES;
|
||||
G_GNUC_END_IGNORE_DEPRECATIONS
|
||||
#endif
|
||||
// The following utilities are pulled from
|
||||
// https://source.chromium.org/chromium/chromium/src/+/main:ui/gtk/select_file_dialog_impl_gtk.cc;l=43-74
|
||||
|
||||
const char* GettextPackage() {
|
||||
static base::NoDestructor<std::string> gettext_package(
|
||||
"gtk" + base::NumberToString(gtk::GtkVersion().components()[0]) + "0");
|
||||
return gettext_package->c_str();
|
||||
}
|
||||
|
||||
const char* GtkGettext(const char* str) {
|
||||
return g_dgettext(GettextPackage(), str);
|
||||
}
|
||||
|
||||
const char* GetCancelLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-cancel"; // In GTK3, this is GTK_STOCK_CANCEL.
|
||||
static const char* cancel = GtkGettext("_Cancel");
|
||||
return cancel;
|
||||
}
|
||||
|
||||
const char* GetOpenLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-open"; // In GTK3, this is GTK_STOCK_OPEN.
|
||||
static const char* open = GtkGettext("_Open");
|
||||
return open;
|
||||
}
|
||||
|
||||
const char* GetSaveLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-save"; // In GTK3, this is GTK_STOCK_SAVE.
|
||||
static const char* save = GtkGettext("_Save");
|
||||
return save;
|
||||
}
|
||||
|
||||
const char* GetOkLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-ok"; // In GTK3, this is GTK_STOCK_OK.
|
||||
static const char* ok = GtkGettext("_Ok");
|
||||
return ok;
|
||||
}
|
||||
|
||||
const char* GetNoLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-no"; // In GTK3, this is GTK_STOCK_NO.
|
||||
static const char* no = GtkGettext("_No");
|
||||
return no;
|
||||
}
|
||||
|
||||
const char* GetYesLabel() {
|
||||
if (!gtk::GtkCheckVersion(4))
|
||||
return "gtk-yes"; // In GTK3, this is GTK_STOCK_YES.
|
||||
static const char* yes = GtkGettext("_Yes");
|
||||
return yes;
|
||||
}
|
||||
|
||||
GdkPixbuf* GdkPixbufFromSkBitmap(const SkBitmap& bitmap) {
|
||||
if (bitmap.isNull())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue