]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
More doc for C# and Java.
authorBruno Haible <bruno@clisp.org>
Tue, 13 Jan 2004 12:19:20 +0000 (12:19 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:11:37 +0000 (12:11 +0200)
gettext-tools/doc/ChangeLog
gettext-tools/doc/gettext.texi

index 8c6ad2e65abaef8791a098ebf8d5e19b0948b2a3..0956d2ba7205a2623787d1682d9d4e2a26612ae5 100644 (file)
@@ -1,3 +1,8 @@
+2004-01-11  Bruno Haible  <bruno@clisp.org>
+
+       * gettext.texi (Java): Explain how to define the shorthand '_'.
+       (C#): Likewise.
+
 2003-12-28  Bruno Haible  <bruno@clisp.org>
 
        * gettext.texi (C#): Mention the --csharp-resources option.
index a8b8281e607c9f0668763d9912864958319872c3..d8b7b52bb3848d31e6fbd97409fb79fcaa320a1c 100644 (file)
@@ -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