]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Recommend a simpler idiom for Java 1.5.
authorBruno Haible <bruno@clisp.org>
Mon, 27 Mar 2006 12:00:15 +0000 (12:00 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:04 +0000 (12:13 +0200)
gettext-tools/doc/ChangeLog
gettext-tools/doc/gettext.texi

index 6e79abcf482b9d17c03202fef9137f2668544021..a032aa4faa6ad6b7862c7dac3d6f8374248a1712 100644 (file)
@@ -1,3 +1,7 @@
+2006-03-26  Bruno Haible  <bruno@clisp.org>
+
+       * gettext.texi (Java): Recommend a simpler idiom for Java 1.5.
+
 2006-03-25  Bruno Haible  <bruno@clisp.org>
 
        * gettext.texi (C): Also mention the hello-c++-wxwidgets example.
index 23a06464e3ad9d94c2d59eef37607a501ae2607f..684c661bd0e319f862135348bf0f3f00b3792e94 100644 (file)
@@ -8773,9 +8773,35 @@ Three examples, using the second API, are available in the @file{examples}
 directory: @code{hello-java}, @code{hello-java-awt}, @code{hello-java-swing}.
 
 Now, to make use of the API and define a shorthand for @samp{getString},
-there are two idioms that you can choose from:
+there are three idioms that you can choose from:
 
 @itemize @bullet
+@item
+(This one assumes Java 1.5 or newer.)
+In a unique class of your project, say @samp{Util}, define a static variable
+holding the @code{ResourceBundle} instance and the shorthand:
+
+@smallexample
+private static ResourceBundle myResources =
+  ResourceBundle.getBundle("domain-name");
+public static String _(String s) @{
+  return myResources.getString(s);
+@}
+@end smallexample
+
+All classes containing internationalized strings then contain
+
+@smallexample
+import static Util._;
+@end smallexample
+
+@noindent
+and the shorthand is used like this:
+
+@smallexample
+System.out.println(_("Operation completed."));
+@end smallexample
+
 @item
 In a unique class of your project, say @samp{Util}, define a static variable
 holding the @code{ResourceBundle} instance:
@@ -8821,9 +8847,10 @@ System.out.println(S._("Operation completed."));
 @end smallexample
 @end itemize
 
-Which of the two idioms you choose, will depend on whether copying two lines
-of codes into every class is more acceptable in your project than a class
-with a single-letter name.
+Which of the three idioms you choose, will depend on whether your project
+requires portability to Java versions prior to Java 1.5 and, if so, whether
+copying two lines of codes into every class is more acceptable in your project
+than a class with a single-letter name.
 
 @node C#, gawk, Java, List of Programming Languages
 @subsection C#