xref: /netbsd-src/external/gpl2/gettext/dist/gettext-tools/examples/hello-java/Hello.java (revision 946379e7b37692fc43f68eb0d1c10daa0a7f3b6c)
1 // Example for use of GNU gettext.
2 // Copyright (C) 2003 Free Software Foundation, Inc.
3 // This file is in the public domain.
4 //
5 // Source code of the Java program.
6 
7 import java.util.*;
8 import java.io.*;
9 import java.text.*;
10 import gnu.gettext.*;
11 
12 public class Hello {
main(String[] args)13   public static void main (String[] args) {
14     ResourceBundle catalog = ResourceBundle.getBundle("hello-java");
15     System.out.println(GettextResource.gettext(catalog,"Hello, world!"));
16     System.out.println(
17         MessageFormat.format(
18             GettextResource.gettext(catalog,
19                 "This program is running as process number {0}."),
20             new Object[] { getPid() }));
21   }
22 
23   /* Return the process ID of the current process.  */
getPid()24   private static String getPid () {
25     try {
26       String[] args = new String[] { "/bin/sh", "-c", "echo $PPID" };
27       Process p = Runtime.getRuntime().exec(args);
28       InputStream p_out = p.getInputStream();
29       String s = (new BufferedReader(new InputStreamReader(p_out))).readLine();
30       p.destroy();
31       if (s != null)
32         return s;
33     } catch (IOException e) {
34       e.printStackTrace();
35     }
36     return "???";
37   }
38 }
39