~ubuntu-branches/ubuntu/breezy/gettext/breezy

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2004-03-14 17:40:02 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040314174002-p1ad5ldve1hqzhye
Tags: 0.14.1-2
* Added libexpat1-dev to Build-Depends, for glade support.
* Added libc0.1-dev to Build-Depends, for GNU/kFreeBSD.
* Removed special-casing of knetbsd-gnu in debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 {
 
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
}