From f4bba95a7a09519e8828a146dfd7cb57b7e7df73 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Thu, 1 Jan 1970 00:00:00 +0000 Subject: [PATCH] Internationalize virt-ctrl. --- virt-ctrl/.depend | 40 ++++++++++++++++++--------------- virt-ctrl/Makefile.in | 12 ++++++++-- virt-ctrl/vc_connection_dlg.ml | 23 ++++++++++--------- virt-ctrl/vc_connections.ml | 11 +++++----- virt-ctrl/vc_dbus.ml | 18 ++++++++++----- virt-ctrl/vc_domain_ops.ml | 1 + virt-ctrl/vc_helpers.ml | 16 ++++++++------ virt-ctrl/vc_mainwindow.ml | 50 +++++++++++++++++++++++------------------- virt-ctrl/virt_ctrl.ml | 1 + 9 files changed, 101 insertions(+), 71 deletions(-) diff --git a/virt-ctrl/.depend b/virt-ctrl/.depend index 5b01507..84ba14c 100644 --- a/virt-ctrl/.depend +++ b/virt-ctrl/.depend @@ -2,23 +2,27 @@ vc_connections.cmi: ../libvirt/libvirt.cmi vc_domain_ops.cmi: vc_connections.cmi vc_helpers.cmi: ../libvirt/libvirt.cmi vc_mainwindow.cmi: vc_domain_ops.cmi -vc_connection_dlg.cmo: vc_connections.cmi vc_connection_dlg.cmi -vc_connection_dlg.cmx: vc_connections.cmx vc_connection_dlg.cmi -vc_connections.cmo: vc_helpers.cmi ../libvirt/libvirt.cmi vc_connections.cmi -vc_connections.cmx: vc_helpers.cmx ../libvirt/libvirt.cmx vc_connections.cmi -vc_dbus.cmo: vc_connection_dlg.cmi vc_dbus.cmi -vc_dbus.cmx: vc_connection_dlg.cmx vc_dbus.cmi -vc_domain_ops.cmo: vc_connections.cmi ../libvirt/libvirt.cmi \ - vc_domain_ops.cmi -vc_domain_ops.cmx: vc_connections.cmx ../libvirt/libvirt.cmx \ - vc_domain_ops.cmi -vc_helpers.cmo: ../libvirt/libvirt.cmi vc_helpers.cmi -vc_helpers.cmx: ../libvirt/libvirt.cmx vc_helpers.cmi +vc_connection_dlg.cmo: virt_ctrl_gettext.cmo vc_connections.cmi \ + vc_connection_dlg.cmi +vc_connection_dlg.cmx: virt_ctrl_gettext.cmx vc_connections.cmx \ + vc_connection_dlg.cmi +vc_connections.cmo: virt_ctrl_gettext.cmo vc_helpers.cmi \ + ../libvirt/libvirt.cmi vc_connections.cmi +vc_connections.cmx: virt_ctrl_gettext.cmx vc_helpers.cmx \ + ../libvirt/libvirt.cmx vc_connections.cmi +vc_dbus.cmo: virt_ctrl_gettext.cmo vc_connection_dlg.cmi vc_dbus.cmi +vc_dbus.cmx: virt_ctrl_gettext.cmx vc_connection_dlg.cmx vc_dbus.cmi +vc_domain_ops.cmo: virt_ctrl_gettext.cmo vc_connections.cmi \ + ../libvirt/libvirt.cmi vc_domain_ops.cmi +vc_domain_ops.cmx: virt_ctrl_gettext.cmx vc_connections.cmx \ + ../libvirt/libvirt.cmx vc_domain_ops.cmi +vc_helpers.cmo: virt_ctrl_gettext.cmo ../libvirt/libvirt.cmi vc_helpers.cmi +vc_helpers.cmx: virt_ctrl_gettext.cmx ../libvirt/libvirt.cmx vc_helpers.cmi vc_icons.cmo: vc_connection_dlg.cmi vc_icons.cmx: vc_connection_dlg.cmx -vc_mainwindow.cmo: vc_connections.cmi vc_connection_dlg.cmi \ - ../libvirt/libvirt.cmi vc_mainwindow.cmi -vc_mainwindow.cmx: vc_connections.cmx vc_connection_dlg.cmx \ - ../libvirt/libvirt.cmx vc_mainwindow.cmi -virt_ctrl.cmo: vc_mainwindow.cmi vc_domain_ops.cmi -virt_ctrl.cmx: vc_mainwindow.cmx vc_domain_ops.cmx +vc_mainwindow.cmo: virt_ctrl_gettext.cmo vc_connections.cmi \ + vc_connection_dlg.cmi ../libvirt/libvirt.cmi vc_mainwindow.cmi +vc_mainwindow.cmx: virt_ctrl_gettext.cmx vc_connections.cmx \ + vc_connection_dlg.cmx ../libvirt/libvirt.cmx vc_mainwindow.cmi +virt_ctrl.cmo: virt_ctrl_gettext.cmo vc_mainwindow.cmi vc_domain_ops.cmi +virt_ctrl.cmx: virt_ctrl_gettext.cmx vc_mainwindow.cmx vc_domain_ops.cmx diff --git a/virt-ctrl/Makefile.in b/virt-ctrl/Makefile.in index 1b4e529..eb28630 100644 --- a/virt-ctrl/Makefile.in +++ b/virt-ctrl/Makefile.in @@ -27,10 +27,15 @@ icons = @icons@ HAVE_GDK_PIXBUF_MLSOURCE = @HAVE_GDK_PIXBUF_MLSOURCE@ pkg_dbus = @pkg_dbus@ +pkg_gettext = @pkg_gettext@ OCAMLFIND = @OCAMLFIND@ -OBJS += \ +ifneq ($(pkg_gettext),no) +OBJS := virt_ctrl_gettext.cmo +endif + +OBJS += \ vc_helpers.cmo \ vc_connections.cmo \ vc_domain_ops.cmo \ @@ -41,9 +46,12 @@ ifneq ($(OCAMLFIND),) # Good, we have ocamlfind. OCAMLCPACKAGES := -I ../libvirt -package unix,lablgtk2 ifeq ($(pkg_dbus),yes) -OCAMLCPACKAGES := $(OCAMLCPACKAGES),dbus +OCAMLCPACKAGES += -package dbus OBJS += vc_dbus.cmo endif +ifeq ($(pkg_gettext),yes) +OCAMLCPACKAGES += -package gettext-stub +endif OCAMLCFLAGS := -g OCAMLCLIBS := -linkpkg OCAMLOPTPACKAGES := $(OCAMLCPACKAGES) diff --git a/virt-ctrl/vc_connection_dlg.ml b/virt-ctrl/vc_connection_dlg.ml index 9575efc..f072a1d 100644 --- a/virt-ctrl/vc_connection_dlg.ml +++ b/virt-ctrl/vc_connection_dlg.ml @@ -17,6 +17,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *) +open Virt_ctrl_gettext.Gettext + type name = string type uri = string type service = name * uri @@ -35,7 +37,7 @@ let icon_48x48_devices_computer_png = ref None (* Open connection dialog. *) let open_connection parent () = - let title = "Open connection to hypervisor" in + let title = s_ "Open connection to hypervisor" in let position = `CENTER_ON_PARENT in let dlg = GWindow.dialog ~title ~position ~parent @@ -57,7 +59,7 @@ let open_connection parent () = (* Local connections. *) let () = let frame = - GBin.frame ~label:"This machine" ~packing:vbox#pack () in + GBin.frame ~label:(s_ "This machine") ~packing:vbox#pack () in let hbox = GPack.hbox ~packing:frame#add () in hbox#set_spacing 20; ignore ( @@ -71,14 +73,14 @@ let open_connection parent () = vbox#set_spacing 5; let xen_button = - GButton.button ~label:"Xen hypervisor" + GButton.button ~label:(s_ "Xen hypervisor") ~packing:vbox#pack () in ignore (xen_button#connect#clicked ~callback:(fun () -> uri := Some local_xen_uri; dlg#destroy ())); let qemu_button = - GButton.button ~label:"QEMU or KVM" + GButton.button ~label:(s_ "QEMU or KVM") ~packing:vbox#pack () in ignore (qemu_button#connect#clicked ~callback:(fun () -> @@ -88,7 +90,7 @@ let open_connection parent () = (* Network connections. *) let () = let frame = - GBin.frame ~label:"Local network" + GBin.frame ~label:(s_ "Local network") ~packing:(vbox#pack ~expand:true) () in let hbox = GPack.hbox ~packing:frame#add () in hbox#set_spacing 20; @@ -129,9 +131,10 @@ let open_connection parent () = let hbox = GPack.hbox ~packing:vbox#pack () in let refresh_button = - GButton.button ~label:"Refresh" ~stock:`REFRESH ~packing:hbox#pack () in + GButton.button ~label:(s_ "Refresh") + ~stock:`REFRESH ~packing:hbox#pack () in let open_button = - GButton.button ~label:"Open" ~packing:hbox#pack () in + GButton.button ~label:(s_ "Open") ~packing:hbox#pack () in ignore (refresh_button#connect#clicked ~callback:refresh); @@ -154,7 +157,7 @@ let open_connection parent () = (* Custom connections. *) let () = let frame = - GBin.frame ~label:"URI connection" ~packing:vbox#pack () in + GBin.frame ~label:(s_ "URI connection") ~packing:vbox#pack () in let hbox = GPack.hbox ~packing:frame#add () in hbox#set_spacing 20; ignore (GMisc.image ~stock:`CONNECT ~packing:hbox#pack ()); @@ -164,7 +167,7 @@ let open_connection parent () = GEdit.entry ~text:"xen://localhost/" ~packing:(hbox#pack ~expand:true ~fill:true) () in let button = - GButton.button ~label:"Open" ~packing:hbox#pack () in + GButton.button ~label:(s_ "Open") ~packing:hbox#pack () in ignore (button#connect#clicked ~callback:(fun () -> @@ -176,7 +179,7 @@ let open_connection parent () = (* Just a cancel button in the action area. *) let cancel_button = - GButton.button ~label:"Cancel" + GButton.button ~label:(s_ "Cancel") ~packing:dlg#action_area#pack () in ignore (cancel_button#connect#clicked ~callback:(fun () -> diff --git a/virt-ctrl/vc_connections.ml b/virt-ctrl/vc_connections.ml index 05024c5..8f5fba0 100644 --- a/virt-ctrl/vc_connections.ml +++ b/virt-ctrl/vc_connections.ml @@ -18,6 +18,7 @@ *) open Printf +open Virt_ctrl_gettext.Gettext module C = Libvirt.Connect module D = Libvirt.Domain @@ -401,11 +402,11 @@ let make_treeview ?packing () = view_col#set_sort_order sort_order; view_col#set_sort_column_id sort_column_id in - append_visible_column "ID" col_name_id (Some (false, `ASCENDING, 0)); - append_visible_column "Name" col_domname (Some (true, `ASCENDING, 1)); - append_visible_column "Status" col_status None; - append_visible_column "CPU" col_cpu None; - append_visible_column "Memory" col_mem None; + append_visible_column (s_ "ID") col_name_id (Some (false, `ASCENDING, 0)); + append_visible_column (s_ "Name") col_domname (Some (true, `ASCENDING, 1)); + append_visible_column (s_ "Status") col_status None; + append_visible_column (s_ "CPU") col_cpu None; + append_visible_column (s_ "Memory") col_mem None; let columns = col_name_id, col_domname, col_status, col_cpu, col_mem, col_id in diff --git a/virt-ctrl/vc_dbus.ml b/virt-ctrl/vc_dbus.ml index 278b1fc..82b66dd 100644 --- a/virt-ctrl/vc_dbus.ml +++ b/virt-ctrl/vc_dbus.ml @@ -39,6 +39,7 @@ *) open Printf +open Virt_ctrl_gettext.Gettext open DBus let debug = true @@ -120,7 +121,7 @@ let add_service bus err msg = Hashtbl.replace services name uri | _ -> - prerr_endline "warning: unexpected message contents of Found signal" + prerr_endline (s_ "warning: unexpected message contents of Found signal") (* Process an ItemRemove message, indicating that a service has * gone away. @@ -135,7 +136,8 @@ let remove_service bus err msg = Hashtbl.remove services name | _ -> - prerr_endline "warning: unexpected message contents of ItemRemove signal" + prerr_endline + (s_ "warning: unexpected message contents of ItemRemove signal") (* A service has appeared on the network. Resolve its IP address, etc. *) let start_resolve_service bus err sb_path msg = @@ -182,7 +184,8 @@ let start_resolve_service bus err sb_path msg = () | _ -> - prerr_endline "warning: unexpected message contents of ItemNew signal" + prerr_endline + (s_ "warning: unexpected message contents of ItemNew signal") (* This is called when we get a message/signal. Could be from the * (global) ServiceBrowser or any of the ServiceResolver objects. @@ -212,8 +215,10 @@ let got_message bus err sb_path msg = remove_service bus err msg | "org.freedesktop.DBus", _ -> () | interface, member -> - eprintf "warning: ignored unknown message %s from %s\n%!" - member interface + let () = + eprintf (f_ "warning: ignored unknown message %s from %s\n%!") + member interface in + () ); true @@ -230,7 +235,8 @@ let connect () = | None -> let err = Error.init () in let bus = Bus.get Bus.System err in - if Error.is_set err then failwith "error set after getting System bus"; + if Error.is_set err then + failwith (s_ "error set after getting System bus"); (* Create a new ServiceBrowser object which emits a signal whenever * a new network service of the type specified is found on the network. diff --git a/virt-ctrl/vc_domain_ops.ml b/virt-ctrl/vc_domain_ops.ml index 787e71e..deace05 100644 --- a/virt-ctrl/vc_domain_ops.ml +++ b/virt-ctrl/vc_domain_ops.ml @@ -20,6 +20,7 @@ *) open Printf +open Virt_ctrl_gettext.Gettext module C = Libvirt.Connect module D = Libvirt.Domain diff --git a/virt-ctrl/vc_helpers.ml b/virt-ctrl/vc_helpers.ml index 10fe6b1..74e70cb 100644 --- a/virt-ctrl/vc_helpers.ml +++ b/virt-ctrl/vc_helpers.ml @@ -17,6 +17,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *) +open Virt_ctrl_gettext.Gettext + module C = Libvirt.Connect module D = Libvirt.Domain module N = Libvirt.Network @@ -47,13 +49,13 @@ let differences xs ys = d (List.sort compare xs, List.sort compare ys) let string_of_domain_state = function - | D.InfoNoState -> "unknown" - | D.InfoRunning -> "running" - | D.InfoBlocked -> "blocked" - | D.InfoPaused -> "paused" - | D.InfoShutdown -> "shutdown" - | D.InfoShutoff -> "shutoff" - | D.InfoCrashed -> "crashed" + | D.InfoNoState -> s_ "unknown" + | D.InfoRunning -> s_ "running" + | D.InfoBlocked -> s_ "blocked" + | D.InfoPaused -> s_ "paused" + | D.InfoShutdown -> s_ "shutdown" + | D.InfoShutoff -> s_ "shutoff" + | D.InfoCrashed -> s_ "crashed" (* Filter top level rows (only) in a tree_store. If function f returns * true then the row remains, but if it returns false then the row is diff --git a/virt-ctrl/vc_mainwindow.ml b/virt-ctrl/vc_mainwindow.ml index 7aa8145..c34a803 100644 --- a/virt-ctrl/vc_mainwindow.ml +++ b/virt-ctrl/vc_mainwindow.ml @@ -18,8 +18,9 @@ *) open Printf +open Virt_ctrl_gettext.Gettext -let title = "Virtual Control" +let title = s_ "Virtual Control" let utf8_copyright = "\194\169" @@ -35,18 +36,21 @@ let help_about () = GToolbox.message_box ~title ~icon - ("Virtualization control tool (virt-ctrl) by\n" ^ - "Richard W.M. Jones (rjones@redhat.com).\n\n" ^ - "Copyright " ^ utf8_copyright ^ " 2007-2008 Red Hat Inc.\n\n" ^ - "Libvirt version: " ^ virt_version ^ "\n" ^ - "Gtk toolkit version: " ^ gtk_version) + (sprintf (f_ "Virtualization control tool (virt-ctrl) by +Richard W.M. Jones (rjones@redhat.com). + +Copyright %s 2007-2008 Red Hat Inc. + +Libvirt version: %s + +Gtk toolkit version: %s") utf8_copyright virt_version gtk_version) (* Catch any exception and throw up a dialog. *) let () = (* A nicer exception printing function. *) let string_of_exn = function | Libvirt.Virterror err -> - "Virtualisation error: " ^ (Libvirt.Virterror.to_string err) + s_ "Virtualisation error" ^ ": " ^ (Libvirt.Virterror.to_string err) | Failure msg -> msg | exn -> Printexc.to_string exn in @@ -54,7 +58,7 @@ let () = fun exn -> let label = string_of_exn exn in prerr_endline label; - let title = "Error" in + let title = s_ "Error" in let icon = GMisc.image () in icon#set_stock `DIALOG_ERROR; icon#set_icon_size `DIALOG; @@ -72,25 +76,25 @@ let make let menubar = GMenu.menu_bar ~packing:vbox#pack () in let factory = new GMenu.factory menubar in let accel_group = factory#accel_group in - let file_menu = factory#add_submenu "File" in - let help_menu = factory#add_submenu "Help" in + let file_menu = factory#add_submenu (s_ "File") in + let help_menu = factory#add_submenu (s_ "Help") in window#add_accel_group accel_group; (* File menu. *) let factory = new GMenu.factory file_menu ~accel_group in - let open_item = factory#add_item "Open connection ..." + let open_item = factory#add_item (s_ "Open connection ...") ~key:GdkKeysyms._O in ignore (factory#add_separator ()); - let quit_item = factory#add_item "Quit" ~key:GdkKeysyms._Q in + let quit_item = factory#add_item (s_ "Quit") ~key:GdkKeysyms._Q in ignore (open_item#connect#activate ~callback:(Vc_connection_dlg.open_connection window)); (* Help menu. *) let factory = new GMenu.factory help_menu ~accel_group in - let help_item = factory#add_item "Help" in - let help_about_item = factory#add_item "About ..." in + let help_item = factory#add_item (s_ "Help") in + let help_about_item = factory#add_item (s_ "About ...") in ignore (help_about_item#connect#activate ~callback:help_about); @@ -111,26 +115,26 @@ let make let connect_button_menu = GMenu.menu () in let connect_button = GButton.menu_tool_button - ~label:"Connect ..." ~stock:`CONNECT + ~label:(s_ "Connect ...") ~stock:`CONNECT ~menu:connect_button_menu ~packing:toolbar#insert () in ignore (GButton.separator_tool_item ~packing:toolbar#insert ()); let open_button = - GButton.tool_button ~label:"Details" ~stock:`OPEN + GButton.tool_button ~label:(s_ "Details") ~stock:`OPEN ~packing:toolbar#insert () in ignore (GButton.separator_tool_item ~packing:toolbar#insert ()); let start_button = - GButton.tool_button ~label:"Start" ~stock:`ADD + GButton.tool_button ~label:(s_ "Start") ~stock:`ADD ~packing:toolbar#insert () in let pause_button = - GButton.tool_button ~label:"Pause" ~stock:`MEDIA_PAUSE + GButton.tool_button ~label:(s_ "Pause") ~stock:`MEDIA_PAUSE ~packing:toolbar#insert () in let resume_button = - GButton.tool_button ~label:"Resume" ~stock:`MEDIA_PLAY + GButton.tool_button ~label:(s_ "Resume") ~stock:`MEDIA_PLAY ~packing:toolbar#insert () in ignore (GButton.separator_tool_item ~packing:toolbar#insert ()); let shutdown_button = - GButton.tool_button ~label:"Shutdown" ~stock:`STOP + GButton.tool_button ~label:(s_ "Shutdown") ~stock:`STOP ~packing:toolbar#insert () in (* Set callbacks for the toolbar buttons. *) @@ -150,10 +154,10 @@ let make (* Set a menu on the connect menu-button. *) let () = let factory = new GMenu.factory connect_button_menu (*~accel_group*) in - let local_xen = factory#add_item "Local Xen" in - let local_qemu = factory#add_item "Local QEMU/KVM" in + let local_xen = factory#add_item (s_ "Local Xen") in + let local_qemu = factory#add_item (s_ "Local QEMU/KVM") in ignore (factory#add_separator ()); - let open_dialog = factory#add_item "Connect to ..." in + let open_dialog = factory#add_item (s_ "Connect to ...") in ignore (local_xen#connect#activate ~callback:Vc_connection_dlg.open_local_xen); ignore (local_qemu#connect#activate diff --git a/virt-ctrl/virt_ctrl.ml b/virt-ctrl/virt_ctrl.ml index c7c4620..9e5053e 100644 --- a/virt-ctrl/virt_ctrl.ml +++ b/virt-ctrl/virt_ctrl.ml @@ -18,6 +18,7 @@ *) open Printf +open Virt_ctrl_gettext.Gettext let () = (* Build the main window and wire up the buttons to the callback functions *) -- 1.8.3.1