From bc6db155617f44a194d1ff1035c3d8aaaa21aafc Mon Sep 17 00:00:00 2001 From: luoqing Date: Wed, 28 Jun 2023 11:20:12 +0800 Subject: [PATCH] fix(disks):Fixed interface translation not displayed in GB18030 coding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复在GB18030编码下界面翻译不显示 Close #7250 --- src/disks/gdubenchmarkdialog.c | 3 ++- src/disks/gducreateconfirmpage.c | 13 +++++++--- src/disks/gducreatediskimagedialog.c | 3 ++- src/disks/gdudevicetreemodel.c | 24 +++++++++--------- src/disks/gdurestorediskimagedialog.c | 17 +++++++++---- src/disks/gduvolumegrid.c | 7 +++--- src/disks/gduwindow.c | 35 +++++++++++++++------------ src/libgdu/gduutils.c | 3 ++- 8 files changed, 65 insertions(+), 40 deletions(-) diff --git a/src/disks/gdubenchmarkdialog.c b/src/disks/gdubenchmarkdialog.c index e975614..3b87936 100644 --- a/src/disks/gdubenchmarkdialog.c +++ b/src/disks/gdubenchmarkdialog.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -827,7 +828,7 @@ update_dialog (DialogData *data) /* disk / device label */ drive = udisks_client_get_drive_for_block (gdu_window_get_client (data->window), data->block); info = udisks_client_get_object_info (gdu_window_get_client (data->window), data->object); - gtk_label_set_text (GTK_LABEL (data->device_label), udisks_object_info_get_one_liner (info)); + gtk_label_set_text (GTK_LABEL (data->device_label), g_locale_to_utf8(udisks_object_info_get_one_liner (info),-1, NULL, NULL, NULL)); g_free (s); G_LOCK (bm_lock); diff --git a/src/disks/gducreateconfirmpage.c b/src/disks/gducreateconfirmpage.c index be98943..6378b65 100644 --- a/src/disks/gducreateconfirmpage.c +++ b/src/disks/gducreateconfirmpage.c @@ -10,6 +10,8 @@ #include +#include + #include "gducreateconfirmpage.h" struct _GduCreateConfirmPage @@ -107,8 +109,12 @@ gdu_create_confirm_page_fill_confirmation (GduCreateConfirmPage *page) * from UDisks, first is description, second the name: * "Partition 1 of 32 GB Flash Disk — /dev/sdb1". */ - s1 = g_strdup_printf (_("%s — %s"), udisks_object_info_get_description (info), - udisks_object_info_get_name (info)); + const gchar * desc = g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL); + const gchar * name = g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL); + + s1 = g_strdup_printf (_("%s — %s"), desc, + name); + gtk_label_set_text (priv->device_name_label, s1); g_free (s1); @@ -122,7 +128,8 @@ gdu_create_confirm_page_fill_confirmation (GduCreateConfirmPage *page) { gtk_widget_show (GTK_WIDGET (priv->used_label)); gtk_widget_show (GTK_WIDGET (priv->used_amount_label)); - s1 = udisks_client_get_size_for_display (priv->client, size - unused_space, FALSE, FALSE); + gchar *size_for_display = udisks_client_get_size_for_display (priv->client, size - unused_space, FALSE, FALSE); + s1 = g_locale_to_utf8(size_for_display, -1, NULL, NULL, NULL); /* Translators: Disk usage in the format '3 GB (7%)', unit string comes from UDisks. */ s2 = g_strdup_printf (_("%s (%.1f%%)"), s1, 100.0 * (size - unused_space) / size); diff --git a/src/disks/gducreatediskimagedialog.c b/src/disks/gducreatediskimagedialog.c index 181b289..9deb5c1 100644 --- a/src/disks/gducreatediskimagedialog.c +++ b/src/disks/gducreatediskimagedialog.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -289,7 +290,7 @@ create_disk_image_populate (DialogData *data) /* Source label */ info = udisks_client_get_object_info (gdu_window_get_client (data->window), data->object); - gtk_label_set_text (GTK_LABEL (data->source_label), udisks_object_info_get_one_liner (info)); + gtk_label_set_text (GTK_LABEL (data->source_label), g_locale_to_utf8(udisks_object_info_get_one_liner (info),-1, NULL, NULL, NULL)); g_clear_object (&info); } diff --git a/src/disks/gdudevicetreemodel.c b/src/disks/gdudevicetreemodel.c index 2157276..d591dad 100644 --- a/src/disks/gdudevicetreemodel.c +++ b/src/disks/gdudevicetreemodel.c @@ -11,6 +11,7 @@ #include "config.h" #include +#include #include "gdudevicetreemodel.h" #include "gduapplication.h" @@ -881,9 +882,9 @@ update_drive (GduDeviceTreeModel *model, s = g_strdup_printf ("%s" "%s" "%s%s", - udisks_object_info_get_description (info), + g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL), model->flags & GDU_DEVICE_TREE_MODEL_FLAGS_ONE_LINE_NAME ? " — " : "\n", - udisks_object_info_get_name (info), + g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL), included_device_name != NULL ? included_device_name : ""); } else @@ -891,9 +892,9 @@ update_drive (GduDeviceTreeModel *model, s = g_strdup_printf ("%s" "%s" "%s%s", - udisks_object_info_get_description (info), + g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL), model->flags & GDU_DEVICE_TREE_MODEL_FLAGS_ONE_LINE_NAME ? " — " : "\n", - udisks_object_info_get_name (info), + g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL), included_device_name != NULL ? included_device_name : ""); } @@ -916,7 +917,7 @@ update_drive (GduDeviceTreeModel *model, &iter, GDU_DEVICE_TREE_MODEL_COLUMN_ICON, icon, GDU_DEVICE_TREE_MODEL_COLUMN_NAME, s, - GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, udisks_object_info_get_sort_key (info), + GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, g_locale_to_utf8(udisks_object_info_get_sort_key (info),-1, NULL, NULL, NULL), GDU_DEVICE_TREE_MODEL_COLUMN_WARNING, warning, GDU_DEVICE_TREE_MODEL_COLUMN_JOBS_RUNNING, jobs_running, GDU_DEVICE_TREE_MODEL_COLUMN_PULSE, pulse, @@ -1114,7 +1115,7 @@ update_block (GduDeviceTreeModel *model, loop = udisks_object_peek_loop (object); size = udisks_block_get_size (block); - size_str = udisks_client_get_size_for_display (model->client, size, FALSE, FALSE); + size_str = g_locale_to_utf8(udisks_client_get_size_for_display (model->client, size, FALSE, FALSE) , -1, NULL, NULL, NULL); info = udisks_client_get_object_info (model->client, object); @@ -1127,7 +1128,7 @@ update_block (GduDeviceTreeModel *model, s = g_strdup_printf ("%s" "%s" "%s", - udisks_object_info_get_description (info), + g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL), model->flags & GDU_DEVICE_TREE_MODEL_FLAGS_ONE_LINE_NAME ? " — " : "\n", backing_file_unfused); g_free (backing_file_unfused); @@ -1137,7 +1138,7 @@ update_block (GduDeviceTreeModel *model, s = g_strdup_printf ("%s" "%s" "%s", - udisks_object_info_get_description (info), + g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL), model->flags & GDU_DEVICE_TREE_MODEL_FLAGS_ONE_LINE_NAME ? " — " : "\n", preferred_device); } @@ -1155,7 +1156,7 @@ update_block (GduDeviceTreeModel *model, &iter, GDU_DEVICE_TREE_MODEL_COLUMN_ICON, udisks_object_info_get_icon (info), GDU_DEVICE_TREE_MODEL_COLUMN_NAME, s, - GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, udisks_object_info_get_sort_key (info), + GDU_DEVICE_TREE_MODEL_COLUMN_SORT_KEY, g_locale_to_utf8(udisks_object_info_get_sort_key (info),-1, NULL, NULL, NULL), GDU_DEVICE_TREE_MODEL_COLUMN_JOBS_RUNNING, jobs_running, GDU_DEVICE_TREE_MODEL_COLUMN_PULSE, pulse, GDU_DEVICE_TREE_MODEL_COLUMN_SIZE, size, @@ -1442,8 +1443,9 @@ sort_func (gconstpointer a, ib = sort_get_object_info (model, UDISKS_OBJECT (b)); } - ret = g_strcmp0 (ia != NULL ? udisks_object_info_get_sort_key (ia) : NULL, - ib != NULL ? udisks_object_info_get_sort_key (ib) : NULL); + ret = g_strcmp0 (ia != NULL ? g_locale_to_utf8(udisks_object_info_get_sort_key (ia),-1, NULL, NULL, NULL) : NULL, + ib != NULL ? g_locale_to_utf8(udisks_object_info_get_sort_key (ib),-1, NULL, NULL, NULL) : NULL); + g_clear_object (&ib); g_clear_object (&ia); diff --git a/src/disks/gdurestorediskimagedialog.c b/src/disks/gdurestorediskimagedialog.c index bccf97e..6d44062 100644 --- a/src/disks/gdurestorediskimagedialog.c +++ b/src/disks/gdurestorediskimagedialog.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -279,7 +280,9 @@ restore_disk_image_update (DialogData *data) } else { - s = udisks_client_get_size_for_display (gdu_window_get_client (data->window), uncompressed_size, FALSE, TRUE); + gchar *size_for_display = udisks_client_get_size_for_display (gdu_window_get_client (data->window), uncompressed_size, FALSE, TRUE); + s = g_locale_to_utf8(size_for_display, -1, NULL, NULL, NULL); + /* Translators: Shown for a compressed disk image in the "Size" field. * The %s is the uncompressed size as a long string, e.g. "4.2 MB (4,300,123 bytes)". */ @@ -290,7 +293,9 @@ restore_disk_image_update (DialogData *data) } else { - image_size_str = udisks_client_get_size_for_display (gdu_window_get_client (data->window), size, FALSE, TRUE); + gchar *size_for_display = udisks_client_get_size_for_display (gdu_window_get_client (data->window), size, FALSE, TRUE); + image_size_str = g_locale_to_utf8(size_for_display, -1, NULL, NULL, NULL); + } if (data->block_size > 0) @@ -306,8 +311,9 @@ restore_disk_image_update (DialogData *data) /* Only complain if slack is bigger than 1MB */ if (data->block_size - size > 1000L*1000L) { - s = udisks_client_get_size_for_display (gdu_window_get_client (data->window), + gchar * size_for_display = udisks_client_get_size_for_display (gdu_window_get_client (data->window), data->block_size - size, FALSE, FALSE); + s = g_locale_to_utf8(size_for_display ,-1, NULL, NULL, NULL); restore_warning = g_strdup_printf (_("The disk image is %s smaller than the target device"), s); g_free (s); } @@ -315,8 +321,9 @@ restore_disk_image_update (DialogData *data) } else if (size > data->block_size) { - s = udisks_client_get_size_for_display (gdu_window_get_client (data->window), + gchar * size_for_display = udisks_client_get_size_for_display (gdu_window_get_client (data->window), size - data->block_size, FALSE, FALSE); + s = g_locale_to_utf8(size_for_display ,-1, NULL, NULL, NULL); restore_error = g_strdup_printf (_("The disk image is %s bigger than the target device"), s); g_free (s); } @@ -539,7 +546,7 @@ restore_disk_image_populate (DialogData *data) { UDisksObjectInfo *info; info = udisks_client_get_object_info (gdu_window_get_client (data->window), data->object); - gtk_label_set_text (GTK_LABEL (data->destination_label), udisks_object_info_get_one_liner (info)); + gtk_label_set_text (GTK_LABEL (data->destination_label), g_locale_to_utf8(udisks_object_info_get_one_liner (info),-1, NULL, NULL, NULL)); g_clear_object (&info); gtk_widget_hide (data->selectable_destination_label); diff --git a/src/disks/gduvolumegrid.c b/src/disks/gduvolumegrid.c index 91012b4..3f53a2d 100644 --- a/src/disks/gduvolumegrid.c +++ b/src/disks/gduvolumegrid.c @@ -1631,11 +1631,12 @@ create_common_device_info_string (UDisksClient *client, type = udisks_block_get_id_type (block); version = udisks_block_get_id_version (block); - size_str = udisks_client_get_size_for_display (client, + gchar * size_for_display = udisks_client_get_size_for_display (client, element->size, NO_USE_POW2, NO_LONG_STRING); + size_str = g_locale_to_utf8(size_for_display,-1, NULL, NULL, NULL); if (is_extended_partition (partition)) { return size_str; @@ -1651,7 +1652,7 @@ create_common_device_info_string (UDisksClient *client, version, NO_LONG_STRING); - size_with_type_str = g_strdup_printf ("%s %s", size_str, type_for_display); + size_with_type_str = g_strdup_printf ("%s %s", size_str, g_locale_to_utf8(type_for_display, -1, NULL, NULL, NULL)); g_free (type_for_display); return size_with_type_str; @@ -1836,7 +1837,7 @@ grid_element_set_details (GduVolumeGrid *grid, size_str = udisks_client_get_size_for_display (grid->client, element->size, FALSE, FALSE); element->text = g_strdup_printf ("%s\n%s", C_("volume-grid", "Free Space"), - size_str); + g_locale_to_utf8(size_str,-1, NULL, NULL, NULL)); g_free (size_str); } break; diff --git a/src/disks/gduwindow.c b/src/disks/gduwindow.c index 97eb8f0..c6f2b2c 100644 --- a/src/disks/gduwindow.c +++ b/src/disks/gduwindow.c @@ -18,6 +18,7 @@ #include #include +#include #include "gduapplication.h" #include "gduwindow.h" @@ -1522,7 +1523,8 @@ set_size (GduWindow *window, SetMarkupFlags flags) { gchar *s; - s = udisks_client_get_size_for_display (window->client, size, FALSE, TRUE); + gchar *size_for_display = udisks_client_get_size_for_display (window->client, size, FALSE, TRUE); + s = g_locale_to_utf8(size_for_display, -1, NULL, NULL, NULL); set_markup (window, key_label_id, label_id, s, size); g_free (s); } @@ -1955,8 +1957,9 @@ update_generic_drive_bits (GduWindow *window, s = NULL; if (partition_table != NULL) { - const gchar *table_type = udisks_partition_table_get_type_ (partition_table); - s = g_strdup (udisks_client_get_partition_table_type_for_display (window->client, table_type)); + const gchar *table_type = g_locale_to_utf8(udisks_partition_table_get_type_ (partition_table), -1, NULL, NULL, NULL); + const gchar *table_type_for_display = udisks_client_get_partition_table_type_for_display (window->client, table_type); + s = g_strdup (g_locale_to_utf8(table_type_for_display, -1, NULL, NULL, NULL)); if (s == NULL) { /* Translators: Shown for unknown partitioning type. The first %s is the low-level type. */ @@ -2049,7 +2052,7 @@ update_device_page_for_drive (GduWindow *window, g_free (s); } - hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), udisks_object_info_get_description (info)); + hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL)); hdy_header_bar_set_subtitle (HDY_HEADER_BAR (window->right_header), str->str); g_string_free (str, TRUE); @@ -2184,7 +2187,7 @@ update_device_page_for_drive (GduWindow *window, set_markup (window, "devtab-drive-size-label", "devtab-drive-size-value-label", - s, SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY); + g_locale_to_utf8(s, -1, NULL, NULL, NULL), SET_MARKUP_FLAGS_HYPHEN_IF_EMPTY); g_free (s); } else @@ -2201,7 +2204,7 @@ update_device_page_for_drive (GduWindow *window, set_markup (window, "devtab-drive-media-label", "devtab-drive-media-value-label", - udisks_object_info_get_media_description (info), SET_MARKUP_FLAGS_NONE); + g_locale_to_utf8(udisks_object_info_get_media_description (info),-1, NULL, NULL, NULL), SET_MARKUP_FLAGS_NONE); } else { @@ -2269,7 +2272,7 @@ update_device_page_for_loop (GduWindow *window, info = udisks_client_get_object_info (window->client, object); device_desc = get_device_file_for_display (block); - hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), udisks_object_info_get_description (info)); + hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL)); hdy_header_bar_set_subtitle (HDY_HEADER_BAR (window->right_header), device_desc); gtk_widget_show (window->devtab_drive_menu_button); @@ -2325,7 +2328,7 @@ update_device_page_for_fake_block (GduWindow *window, info = udisks_client_get_object_info (window->client, object); device_desc = get_device_file_for_display (block); - hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), udisks_object_info_get_description (info)); + hdy_header_bar_set_title (HDY_HEADER_BAR (window->right_header), g_locale_to_utf8(udisks_object_info_get_description (info),-1, NULL, NULL, NULL)); hdy_header_bar_set_subtitle (HDY_HEADER_BAR (window->right_header), device_desc); gtk_widget_show (window->devtab_drive_menu_button); @@ -2481,7 +2484,7 @@ update_device_page_for_block (GduWindow *window, * The second %s is a short string with the space free (e.g. '43 GB'). * The %f is the percentage in use (e.g. 62.2). */ - s = g_strdup_printf (_("%s — %s free (%.1f%% full)"), s3, s2, + s = g_strdup_printf (_("%s — %s free (%.1f%% full)"), g_locale_to_utf8(s3, -1, NULL, NULL, NULL), g_locale_to_utf8(s2 ,-1, NULL, NULL, NULL), 100.0 * (size - unused_space) / size); g_free (s3); g_free (s2); @@ -2509,7 +2512,7 @@ update_device_page_for_block (GduWindow *window, if (partition != NULL) { - s = udisks_client_get_partition_info (window->client, partition); + s = g_locale_to_utf8(udisks_client_get_partition_info (window->client, partition), -1, NULL, NULL, NULL); if (s == NULL) s = g_strdup (C_("partition type", "Unknown")); set_markup (window, @@ -2631,7 +2634,9 @@ update_device_page_for_block (GduWindow *window, } else { - s = udisks_client_get_id_for_display (window->client, usage, type, version, TRUE); + gchar *id_for_display = udisks_client_get_id_for_display (window->client, usage, type, version, TRUE); + s = g_locale_to_utf8(id_for_display ,-1, NULL, NULL, NULL); + } } else @@ -3010,13 +3015,13 @@ fs_repair_cb (UDisksFilesystem *filesystem, if (success) { s = g_strdup_printf (_("Filesystem %s on %s has been repaired."), - name, udisks_object_info_get_name (info)); + name, g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL)); } else { /* show as result and not error message, because it's not a malfunction of GDU */ s = g_strdup_printf (_("Filesystem %s on %s could not be repaired."), - name, udisks_object_info_get_name (info)); + name, g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL)); } gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message_dialog), "%s", s); @@ -3233,13 +3238,13 @@ fs_check_cb (UDisksFilesystem *filesystem, if (consistent) { s = g_strdup_printf (_("Filesystem %s on %s is undamaged."), - name, udisks_object_info_get_name (info)); + name, g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL)); } else { /* show as result and not error message, because it's not a malfunction of GDU */ s = g_strdup_printf (_("Filesystem %s on %s needs repairing."), - name, udisks_object_info_get_name (info)); + name, g_locale_to_utf8(udisks_object_info_get_name (info),-1, NULL, NULL, NULL)); } gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (message_dialog), "%s", s); diff --git a/src/libgdu/gduutils.c b/src/libgdu/gduutils.c index a5acc92..7335cee 100644 --- a/src/libgdu/gduutils.c +++ b/src/libgdu/gduutils.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "gduutils.h" @@ -770,7 +771,7 @@ get_widget_for_object (UDisksClient *client, image = gtk_image_new_from_gicon (udisks_object_info_get_icon (info), GTK_ICON_SIZE_SMALL_TOOLBAR); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - label = gtk_label_new (udisks_object_info_get_one_liner (info)); + label = gtk_label_new (g_locale_to_utf8(udisks_object_info_get_one_liner (info),-1, NULL, NULL, NULL)); gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_MIDDLE); gtk_label_set_xalign (GTK_LABEL (label), 0.0); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); -- 2.27.0