diff options
author | Bruno Haible <bruno@clisp.org> | 2006-03-27 12:00:15 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-23 12:13:04 +0200 |
commit | 0944a517c5c0cb04df5e0ae99a532ade820bd202 (patch) | |
tree | bed044cf50e2310127496198e961cf2bc72c9896 | |
parent | 3ae7bcd6035a094ffd2ba1a92688ef915d9d0e33 (diff) | |
download | external_gettext-0944a517c5c0cb04df5e0ae99a532ade820bd202.zip external_gettext-0944a517c5c0cb04df5e0ae99a532ade820bd202.tar.gz external_gettext-0944a517c5c0cb04df5e0ae99a532ade820bd202.tar.bz2 |
Recommend a simpler idiom for Java 1.5.
-rw-r--r-- | gettext-tools/doc/ChangeLog | 4 | ||||
-rw-r--r-- | gettext-tools/doc/gettext.texi | 35 |
2 files changed, 35 insertions, 4 deletions
diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 6e79abc..a032aa4 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -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. diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index 23a0646..684c661 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -8773,10 +8773,36 @@ 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# |