~win-cross-dev/win-cross/gettext

« back to all changes in this revision

Viewing changes to gettext-tools/examples/hello-java/Hello.java

  • Committer: Nathan Osman
  • Date: 2012-08-11 05:06:52 UTC
  • Revision ID: admin@quickmediasolutions.com-20120811050652-ochkxjtonbw6kkve
Initial commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Example for use of GNU gettext.
 
2
// This file is in the public domain.
 
3
//
 
4
// Source code of the Java program.
 
5
 
 
6
import java.util.*;
 
7
import java.io.*;
 
8
import java.text.*;
 
9
import gnu.gettext.*;
 
10
 
 
11
public 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
}