diff options
author | Tom Tromey <tromey@redhat.com> | 2006-05-15 15:56:42 +0000 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2006-05-15 15:56:42 +0000 |
commit | 2c585099764317c658d8494dd9c32b3c682a7c5c (patch) | |
tree | 1f332c4fa27fa7ba3de54d1b8587d3335243f939 /tools | |
parent | dafab8249fbf6ee69d854f2d66faec1bcc94af2c (diff) | |
download | classpath-2c585099764317c658d8494dd9c32b3c682a7c5c.tar.gz |
* tools/gnu/classpath/tools/getopt/Option.java (getDescription):
Removed old comment.
* tools/gnu/classpath/tools/getopt/ClasspathToolParser.java:
Externalized strings.
(getVersionString): Use MessageFormat.
* tools/gnu/classpath/tools/getopt/Messages.java: New file.
* resource/gnu/classpath/tools/getopt/Messages.properties: New file.
* tools/gnu/classpath/tools/getopt/Parser.java: Externalized strings.
(getArgument): Use a MessageFormat.
(handleLongOption): Likewise.
(parse): Likewise.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/gnu/classpath/tools/getopt/ClasspathToolParser.java | 16 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/getopt/Messages.java | 67 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/getopt/Option.java | 1 | ||||
-rw-r--r-- | tools/gnu/classpath/tools/getopt/Parser.java | 54 |
4 files changed, 113 insertions, 25 deletions
diff --git a/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java b/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java index be382a7a4..e712056ef 100644 --- a/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java +++ b/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java @@ -38,6 +38,8 @@ exception statement from your version. */ package gnu.classpath.tools.getopt; +import java.text.MessageFormat; + import gnu.classpath.Configuration; /** @@ -50,13 +52,13 @@ public class ClasspathToolParser { private static String getVersionString(String programName) { - return (programName + " (GNU Classpath) " - + Configuration.CLASSPATH_VERSION - + "\n\n" - + "Copyright 2006 Free Software Foundation, Inc.\n" - + "This is free software; see the source for copying conditions. There is NO\n" - + "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."); - + String fmt = (Messages.getString("ClasspathToolParser.VersionFormat")); //$NON-NLS-1$ + return MessageFormat.format(fmt, + new Object[] + { + programName, + Configuration.CLASSPATH_VERSION + }); } public ClasspathToolParser(String programName) diff --git a/tools/gnu/classpath/tools/getopt/Messages.java b/tools/gnu/classpath/tools/getopt/Messages.java new file mode 100644 index 000000000..3c963d786 --- /dev/null +++ b/tools/gnu/classpath/tools/getopt/Messages.java @@ -0,0 +1,67 @@ +/* Messages.java -- i18n support for getopt + Copyright (C) 2006 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.tools.getopt; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +public class Messages +{ + private static final String BUNDLE_NAME + = "gnu.classpath.tools.getopt.Messages"; //$NON-NLS-1$ + + private static final ResourceBundle RESOURCE_BUNDLE + = ResourceBundle.getBundle(BUNDLE_NAME); + + private Messages() + { + } + + public static String getString(String key) + { + try + { + return RESOURCE_BUNDLE.getString(key); + } + catch (MissingResourceException e) + { + return '!' + key + '!'; + } + } +} diff --git a/tools/gnu/classpath/tools/getopt/Option.java b/tools/gnu/classpath/tools/getopt/Option.java index e54aaa103..6f775e4a1 100644 --- a/tools/gnu/classpath/tools/getopt/Option.java +++ b/tools/gnu/classpath/tools/getopt/Option.java @@ -184,7 +184,6 @@ public abstract class Option */ public String getDescription() { - // FIXME: localization. return description; } diff --git a/tools/gnu/classpath/tools/getopt/Parser.java b/tools/gnu/classpath/tools/getopt/Parser.java index 0ef815d45..082cf8945 100644 --- a/tools/gnu/classpath/tools/getopt/Parser.java +++ b/tools/gnu/classpath/tools/getopt/Parser.java @@ -40,6 +40,7 @@ package gnu.classpath.tools.getopt; import java.io.PrintStream; import java.text.BreakIterator; +import java.text.MessageFormat; import java.util.ArrayList; import java.util.Iterator; import java.util.Locale; @@ -127,7 +128,7 @@ public class Parser protected static void formatText(PrintStream out, String text, Locale aLocale) { BreakIterator bit = BreakIterator.getLineInstance(aLocale); - String[] lines = text.split("\n"); + String[] lines = text.split("\n"); //$NON-NLS-1$ for (int i = 0; i < lines.length; i++) { text = lines[i]; @@ -165,8 +166,8 @@ public class Parser this.longOnly = longOnly; // Put standard options in their own section near the end. - OptionGroup finalGroup = new OptionGroup("Standard options"); - finalGroup.add(new Option("help", "print this help, then exit") + OptionGroup finalGroup = new OptionGroup(Messages.getString("Parser.StdOptions")); //$NON-NLS-1$ + finalGroup.add(new Option("help", Messages.getString("Parser.PrintHelp")) //$NON-NLS-1$ //$NON-NLS-2$ { public void parsed(String argument) throws OptionException { @@ -174,7 +175,7 @@ public class Parser System.exit(0); } }); - finalGroup.add(new Option("version", "print version number, then exit") + finalGroup.add(new Option("version", Messages.getString("Parser.PrintVersion")) //$NON-NLS-1$ //$NON-NLS-2$ { public void parsed(String argument) throws OptionException { @@ -182,7 +183,7 @@ public class Parser System.exit(0); } }); - finalGroup.add(new Option('J', "pass argument to the Java runtime", "OPTION") + finalGroup.add(new Option('J', Messages.getString("Parser.JArgument"), Messages.getString("Parser.JName")) //$NON-NLS-1$ //$NON-NLS-2$ { public void parsed(String argument) throws OptionException { @@ -299,7 +300,12 @@ public class Parser { ++currentIndex; if (currentIndex >= args.length) - throw new OptionException("option '" + request + "' requires an argument"); + { + String message + = MessageFormat.format(Messages.getString("Parser.ArgReqd"), //$NON-NLS-1$ + new Object[] { request }); + throw new OptionException(request); + } return args[currentIndex]; } @@ -321,7 +327,11 @@ public class Parser } } if (found == null) - throw new OptionException("unrecognized option '" + real + "'"); + { + String msg = MessageFormat.format(Messages.getString("Parser.Unrecognized"), //$NON-NLS-1$ + new Object[] { real }); + throw new OptionException(msg); + } String argument = null; if (found.getTakesArgument()) { @@ -332,8 +342,10 @@ public class Parser } else if (eq != - 1) { - throw new OptionException("option '" + real.substring(0, eq + index) - + "' doesn't allow an argument"); + String msg + = MessageFormat.format(Messages.getString("Parser.NoArg"), //$NON-NLS-1$ + new Object[] { real.substring(0, eq + index) }); + throw new OptionException(msg); } found.parsed(argument); } @@ -351,10 +363,14 @@ public class Parser } } if (found == null) - throw new OptionException("unrecognized option '-" + option + "'"); + { + String msg = MessageFormat.format(Messages.getString("Parser.UnrecDash"), //$NON-NLS-1$ + new Object[] { "" + option }); //$NON-NLS-1$ + throw new OptionException(msg); + } String argument = null; if (found.getTakesArgument()) - argument = getArgument("-" + option); + argument = getArgument("-" + option); //$NON-NLS-1$ found.parsed(argument); } @@ -383,12 +399,12 @@ public class Parser { if (args[currentIndex].length() == 0 || args[currentIndex].charAt(0) != '-' - || "-".equals(args[currentIndex])) + || "-".equals(args[currentIndex])) //$NON-NLS-1$ { files.notifyFile(args[currentIndex]); continue; } - if ("--".equals(args[currentIndex])) + if ("--".equals(args[currentIndex])) //$NON-NLS-1$ break; if (args[currentIndex].charAt(1) == '-') handleLongOption(args[currentIndex], 2); @@ -405,10 +421,14 @@ public class Parser } catch (OptionException err) { - System.err.println(programName + ": " + err.getMessage()); - System.err.println(programName + ": Try '" + programName - + " " + (longOnly ? "-help" : "--help") - + "' for more information."); + System.err.println(programName + ": " + err.getMessage()); //$NON-NLS-1$ + String fmt; + if (longOnly) + fmt = Messages.getString("Parser.TryHelpShort"); //$NON-NLS-1$ + else + fmt = Messages.getString("Parser.TryHelpLong"); //$NON-NLS-1$ + String msg = MessageFormat.format(fmt, new Object[] { programName }); + System.err.println(programName + ": " + msg); //$NON-NLS-1$ System.exit(1); } } |