From e6cca10e5cf86b9bd280e371fb1195835a96bff0 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Fri, 28 Mar 2008 17:12:47 +0000 Subject: Internationalize virt-df program. --- virt-df/.depend | 18 +++++++------ virt-df/Makefile.in | 18 +++++++++---- virt-df/virt_df.ml | 63 +++++++++++++++++++++++++------------------ virt-df/virt_df_ext2.ml | 7 ++--- virt-df/virt_df_linux_swap.ml | 4 ++- virt-df/virt_df_lvm2.ml | 3 ++- 6 files changed, 69 insertions(+), 44 deletions(-) mode change 100755 => 100644 virt-df/virt_df_ext2.ml mode change 100755 => 100644 virt-df/virt_df_linux_swap.ml mode change 100755 => 100644 virt-df/virt_df_lvm2.ml diff --git a/virt-df/.depend b/virt-df/.depend index 1a7750e..69ae982 100644 --- a/virt-df/.depend +++ b/virt-df/.depend @@ -1,10 +1,12 @@ -virt_df_ext2.cmo: virt_df.cmo -virt_df_ext2.cmx: virt_df.cmx -virt_df_linux_swap.cmo: virt_df.cmo -virt_df_linux_swap.cmx: virt_df.cmx -virt_df_lvm2.cmo: virt_df.cmo -virt_df_lvm2.cmx: virt_df.cmx +virt_df_ext2.cmo: virt_df_gettext.cmo virt_df.cmo +virt_df_ext2.cmx: virt_df_gettext.cmx virt_df.cmx +virt_df_linux_swap.cmo: virt_df_gettext.cmo virt_df.cmo +virt_df_linux_swap.cmx: virt_df_gettext.cmx virt_df.cmx +virt_df_lvm2.cmo: virt_df_gettext.cmo virt_df.cmo +virt_df_lvm2.cmx: virt_df_gettext.cmx virt_df.cmx virt_df_main.cmo: virt_df.cmo virt_df_main.cmx: virt_df.cmx -virt_df.cmo: ../libvirt/libvirt_version.cmi ../libvirt/libvirt.cmi -virt_df.cmx: ../libvirt/libvirt_version.cmx ../libvirt/libvirt.cmx +virt_df.cmo: virt_df_gettext.cmo ../libvirt/libvirt_version.cmi \ + ../libvirt/libvirt.cmi +virt_df.cmx: virt_df_gettext.cmx ../libvirt/libvirt_version.cmx \ + ../libvirt/libvirt.cmx diff --git a/virt-df/Makefile.in b/virt-df/Makefile.in index 1f3af53..057c8e5 100644 --- a/virt-df/Makefile.in +++ b/virt-df/Makefile.in @@ -26,14 +26,22 @@ exec_prefix = @exec_prefix@ bindir = @bindir@ pkg_xml_light = @pkg_xml_light@ +pkg_gettext = @pkg_gettext@ OCAMLCPACKAGES := -package unix,extlib,xml-light -OBJS := virt_df.cmo \ - virt_df_ext2.cmo \ - virt_df_linux_swap.cmo \ - virt_df_lvm2.cmo \ - virt_df_main.cmo +ifneq ($(pkg_gettext),no) +OCAMLCPACKAGES += -package gettext-stub +endif + +OBJS := \ + virt_df_gettext.cmo \ + virt_df.cmo \ + virt_df_ext2.cmo \ + virt_df_linux_swap.cmo \ + virt_df_lvm2.cmo \ + virt_df_main.cmo + XOBJS := $(OBJS:.cmo=.cmx) OCAMLCPACKAGES += -I ../libvirt diff --git a/virt-df/virt_df.ml b/virt-df/virt_df.ml index 350d535..4fbc706 100644 --- a/virt-df/virt_df.ml +++ b/virt-df/virt_df.ml @@ -19,9 +19,10 @@ open Printf open ExtList - open Unix +open Virt_df_gettext.Gettext + module C = Libvirt.Connect module D = Libvirt.Domain module N = Libvirt.Network @@ -145,7 +146,7 @@ and probe_mbr fd = lseek fd 446 SEEK_SET; let str = String.create 64 in if read fd str 0 64 <> 64 then - failwith "error reading partition table" + failwith (s_ "error reading partition table") else ( (* Extract partitions from the data. *) let primaries = List.map (get_partition str) [ 0; 16; 32; 48 ] in @@ -178,13 +179,13 @@ and probe_extended_partition max fd epart sect = LargeFile.lseek fd (ebr_offs +^ 446L) SEEK_SET; let str = String.create 32 in if read fd str 0 32 <> 32 then - failwith "error reading extended partition" + failwith (s_ "error reading extended partition") else ( (* Extract partitions from the data. *) let part1, part2 = match List.map (get_partition str) [ 0; 16 ] with | [p1;p2] -> p1,p2 - | _ -> failwith "probe_extended_partition: internal error" in + | _ -> failwith (s_ "probe_extended_partition: internal error") in (* First partition entry has offset to the start of this partition. *) let part1 = { part1 with part_lba_start = sect +^ part1.part_lba_start } in @@ -232,7 +233,7 @@ and get_partition str offs = and probe_partition target part_type fd start size = match part_type with | None -> - ProbeFailed "detection of unpartitioned devices not yet supported" + ProbeFailed (s_ "detection of unpartitioned devices not yet supported") | Some 0x05 -> ProbeIgnore (* Extended partition - ignore it. *) | Some part_type -> @@ -242,7 +243,7 @@ and probe_partition target part_type fd start size = with Not_found -> ProbeFailed - (sprintf "unsupported partition type %02x" part_type) + (sprintf (f_ "unsupported partition type %02x") part_type) and print_stats dom_name statss = List.iter ( @@ -337,19 +338,29 @@ let main () = in let argspec = Arg.align [ - "-a", Arg.Set all, " Show all domains (default: only active domains)"; - "--all", Arg.Set all, " Show all domains (default: only active domains)"; - "-c", Arg.String set_uri, "uri Connect to URI (default: Xen)"; - "--connect", Arg.String set_uri, "uri Connect to URI (default: Xen)"; - "-h", Arg.Set human, " Print sizes in human-readable format"; - "--human-readable", Arg.Set human, " Print sizes in human-readable format"; - "-i", Arg.Set inodes, " Show inodes instead of blocks"; - "--inodes", Arg.Set inodes, " Show inodes instead of blocks"; - "--version", Arg.Unit version, " Display version and exit"; + "-a", Arg.Set all, + " " ^ s_ "Show all domains (default: only active domains)"; + "--all", Arg.Set all, + " " ^ s_ "Show all domains (default: only active domains)"; + "-c", Arg.String set_uri, + "uri " ^ s_ "Connect to URI (default: Xen)"; + "--connect", Arg.String set_uri, + "uri " ^ s_ "Connect to URI (default: Xen)"; + "-h", Arg.Set human, + " " ^ s_ "Print sizes in human-readable format"; + "--human-readable", Arg.Set human, + " " ^ s_ "Print sizes in human-readable format"; + "-i", Arg.Set inodes, + " " ^ s_ "Show inodes instead of blocks"; + "--inodes", Arg.Set inodes, + " " ^ s_ "Show inodes instead of blocks"; + "--version", Arg.Unit version, + " " ^ s_ "Display version and exit"; ] in - let anon_fun str = raise (Arg.Bad (str ^ ": unknown parameter")) in - let usage_msg = "virt-df : like 'df', shows disk space used in guests + let anon_fun str = + raise (Arg.Bad (sprintf (f_ "%s: unknown parameter") str)) in + let usage_msg = s_ "virt-df : like 'df', shows disk space used in guests SUMMARY virt-df [-options] @@ -368,7 +379,7 @@ OPTIONS" in prerr_endline (Libvirt.Virterror.to_string err); (* If non-root and no explicit connection URI, print a warning. *) if geteuid () <> 0 && name = None then ( - print_endline "NB: If you want to monitor a local Xen hypervisor, you usually need to be root"; + print_endline (s_ "NB: If you want to monitor a local Xen hypervisor, you usually need to be root"); ); exit 1 in @@ -405,7 +416,7 @@ OPTIONS" in let nodes, domain_attrs = match xml with | Xml.Element ("domain", attrs, children) -> children, attrs - | _ -> failwith "get_xml_desc didn't return " in + | _ -> failwith (s_ "get_xml_desc didn't return ") in let domid = try Some (int_of_string (List.assoc "id" domain_attrs)) @@ -413,10 +424,10 @@ OPTIONS" in let rec loop = function | [] -> - failwith "get_xml_desc returned no node in XML" + failwith (s_ "get_xml_desc returned no node in XML") | Xml.Element ("name", _, [Xml.PCData name]) :: _ -> name | Xml.Element ("name", _, _) :: _ -> - failwith "get_xml_desc returned strange node" + failwith (s_ "get_xml_desc returned strange node") | _ :: rest -> loop rest in let name = loop nodes in @@ -484,11 +495,11 @@ OPTIONS" in let () = let total, used, avail = match !inodes, !human with - | false, false -> "1K-blocks", "Used", "Available" - | false, true -> "Size", "Used", "Available" - | true, _ -> "Inodes", "IUse", "IFree" in + | false, false -> s_ "1K-blocks", s_ "Used", s_ "Available" + | false, true -> s_ "Size", s_ "Used", s_ "Available" + | true, _ -> s_ "Inodes", s_ "IUse", s_ "IFree" in printf "%-20s %10s %10s %10s %s\n%!" - "Filesystem" total used avail "Type" in + (s_ "Filesystem") total used avail (s_ "Type") in (* Probe the devices. *) List.iter ( @@ -500,6 +511,6 @@ OPTIONS" in | { d_device = Some "cdrom" } -> () (* Ignore physical CD-ROM devices. *) | _ -> - printf "(device omitted)\n"; + print_endline (s_ "(device omitted)"); ) dom_disks ) doms diff --git a/virt-df/virt_df_ext2.ml b/virt-df/virt_df_ext2.ml old mode 100755 new mode 100644 index d2b51f3..1acd855 --- a/virt-df/virt_df_ext2.ml +++ b/virt-df/virt_df_ext2.ml @@ -21,6 +21,7 @@ open Unix open Printf +open Virt_df_gettext.Gettext (* Int64 operators for convenience. *) let (+^) = Int64.add @@ -35,10 +36,10 @@ let probe_ext2 target part_type fd start size = LargeFile.lseek fd ((start+^2L) *^ sector_size) SEEK_SET; let str = String.create 128 in if read fd str 0 128 <> 128 then - failwith "error reading ext2/ext3 magic" + failwith (s_ "error reading ext2/ext3 magic") else ( if str.[56] != '\x53' || str.[57] != '\xEF' then ( - Virt_df.ProbeFailed "partition marked EXT2/3 but no valid filesystem" + Virt_df.ProbeFailed (s_ "partition marked EXT2/3 but no valid filesystem") ) else ( (* Refer to *) let s_inodes_count = read_int32_le str 0 in @@ -78,7 +79,7 @@ let probe_ext2 target part_type fd start size = Virt_df.Filesystem { - Virt_df.fs_name = "Linux ext2/3"; + Virt_df.fs_name = s_ "Linux ext2/3"; fs_block_size = block_size; fs_blocks_total = s_blocks_count -^ overhead; fs_blocks_reserved = s_r_blocks_count; diff --git a/virt-df/virt_df_linux_swap.ml b/virt-df/virt_df_linux_swap.ml old mode 100755 new mode 100644 index 4638828..04e22b9 --- a/virt-df/virt_df_linux_swap.ml +++ b/virt-df/virt_df_linux_swap.ml @@ -20,6 +20,8 @@ Support for Linux swap partitions. *) +open Virt_df_gettext.Gettext + (* Int64 operators for convenience. *) let (+^) = Int64.add let (-^) = Int64.sub @@ -28,7 +30,7 @@ let (/^) = Int64.div let probe_swap target part_type fd start size = Virt_df.Swap { - Virt_df.swap_name = "Linux swap"; + Virt_df.swap_name = s_ "Linux swap"; swap_block_size = 4096L; (* XXX *) swap_blocks_total = size *^ 512L /^ 4096L; } diff --git a/virt-df/virt_df_lvm2.ml b/virt-df/virt_df_lvm2.ml old mode 100755 new mode 100644 index 8dc0c05..d01a5a8 --- a/virt-df/virt_df_lvm2.ml +++ b/virt-df/virt_df_lvm2.ml @@ -21,6 +21,7 @@ *) open Printf +open Virt_df_gettext.Gettext (* Int64 operators for convenience. *) let (+^) = Int64.add @@ -29,7 +30,7 @@ let ( *^ ) = Int64.mul let (/^) = Int64.div let probe_lvm2 target part_type fd start size = - Virt_df.ProbeFailed "LVM2 not supported yet" + Virt_df.ProbeFailed (s_ "LVM2 not supported yet") (* Register with main code. *) let () = -- cgit