From: Bruno Haible Date: Tue, 13 Jan 2004 12:19:20 +0000 (+0000) Subject: More doc for C# and Java. X-Git-Tag: v0.14~68 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7fef14da5b1281174b47b8eae66d360faf6381f3;p=thirdparty%2Fgettext.git More doc for C# and Java. --- diff --git a/gettext-tools/doc/ChangeLog b/gettext-tools/doc/ChangeLog index 8c6ad2e65..0956d2ba7 100644 --- a/gettext-tools/doc/ChangeLog +++ b/gettext-tools/doc/ChangeLog @@ -1,3 +1,8 @@ +2004-01-11 Bruno Haible + + * gettext.texi (Java): Explain how to define the shorthand '_'. + (C#): Likewise. + 2003-12-28 Bruno Haible * gettext.texi (C#): Mention the --csharp-resources option. diff --git a/gettext-tools/doc/gettext.texi b/gettext-tools/doc/gettext.texi index a8b8281e6..d8b7b52bb 100644 --- a/gettext-tools/doc/gettext.texi +++ b/gettext-tools/doc/gettext.texi @@ -8335,6 +8335,59 @@ the GNU gettext package and distributed under the LGPL. 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: + +@itemize @bullet +@item +In a unique class of your project, say @samp{Util}, define a static variable +holding the @code{ResourceBundle} instance: + +@smallexample +public static ResourceBundle myResources = + ResourceBundle.getBundle("domain-name"); +@end smallexample + +All classes containing internationalized strings then contain + +@smallexample +private static ResourceBundle res = Util.myResources; +private static String _(String s) @{ return res.getString(s); @} +@end smallexample + +@noindent +and the shorthand is used like this: + +@smallexample +System.out.println(_("Operation completed.")); +@end smallexample + +@item +You add a class with a very short name, say @samp{S}, containing just the +definition of the resource bundle and of the shorthand: + +@smallexample +public class S @{ + public static ResourceBundle myResources = + ResourceBundle.getBundle("domain-name"); + public static String _(String s) @{ + return myResources.getString(s); + @} +@} +@end smallexample + +@noindent +and the shorthand is used like this: + +@smallexample +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. + @node C#, gawk, Java, List of Programming Languages @subsection C# @cindex C# @@ -8530,6 +8583,59 @@ but don't want to change an existing source code that uses Two examples, using the second API, are available in the @file{examples} directory: @code{hello-csharp}, @code{hello-csharp-forms}. +Now, to make use of the API and define a shorthand for @samp{GetString}, +there are two idioms that you can choose from: + +@itemize @bullet +@item +In a unique class of your project, say @samp{Util}, define a static variable +holding the @code{ResourceManager} instance: + +@smallexample +public static GettextResourceManager MyResourceManager = + new GettextResourceManager("domain-name"); +@end smallexample + +All classes containing internationalized strings then contain + +@smallexample +private static GettextResourceManager Res = Util.MyResourceManager; +private static String _(String s) @{ return Res.GetString(s); @} +@end smallexample + +@noindent +and the shorthand is used like this: + +@smallexample +Console.WriteLine(_("Operation completed.")); +@end smallexample + +@item +You add a class with a very short name, say @samp{S}, containing just the +definition of the resource manager and of the shorthand: + +@smallexample +public class S @{ + public static GettextResourceManager MyResourceManager = + new GettextResourceManager("domain-name"); + public static String _(String s) @{ + return MyResourceManager.GetString(s); + @} +@} +@end smallexample + +@noindent +and the shorthand is used like this: + +@smallexample +Console.WriteLine(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. + @node gawk, Pascal, C#, List of Programming Languages @subsection GNU awk @cindex awk