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
7import java.util.*;
8import java.io.*;
9import java.text.*;
10import gnu.gettext.*;
11
12public class Hello {
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.  */
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