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