mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +01:00
improve i18n support
This commit is contained in:
@@ -139,9 +139,11 @@ public class App
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
I18n i18n = new I18n();
|
||||
|
||||
if ((args.length == 0) || (subcommand == null) || help)
|
||||
{
|
||||
parser.printUsage(output, I18n.getBundle());
|
||||
parser.printUsage(output, i18n.getBundle());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -152,7 +154,7 @@ public class App
|
||||
session = createSession();
|
||||
}
|
||||
|
||||
subcommand.init(input, output, session);
|
||||
subcommand.init(input, output, i18n, session);
|
||||
subcommand.run(arguments);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,19 @@
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.cli;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
@@ -39,8 +50,62 @@ import java.util.ResourceBundle;
|
||||
public class I18n
|
||||
{
|
||||
|
||||
public static ResourceBundle getBundle(){
|
||||
return null;
|
||||
};
|
||||
/** Field description */
|
||||
public static final String RESOURCE_BUNDLE = "sonia.resources.i18n";
|
||||
|
||||
/** the logger for I18n */
|
||||
private static final Logger logger = LoggerFactory.getLogger(I18n.class);
|
||||
|
||||
//~--- constructors ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public I18n()
|
||||
{
|
||||
bundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public ResourceBundle getBundle()
|
||||
{
|
||||
return bundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param key
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getMessage(String key)
|
||||
{
|
||||
String value = key;
|
||||
|
||||
try
|
||||
{
|
||||
key = bundle.getString(key);
|
||||
}
|
||||
catch (MissingResourceException ex)
|
||||
{
|
||||
logger.warn("could not find resource for key {}", key);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private ResourceBundle bundle;
|
||||
}
|
||||
|
||||
@@ -76,13 +76,15 @@ public abstract class SubCommand
|
||||
*
|
||||
* @param input
|
||||
* @param output
|
||||
* @param i18n
|
||||
* @param session
|
||||
*/
|
||||
public void init(BufferedReader input, PrintWriter output,
|
||||
public void init(BufferedReader input, PrintWriter output, I18n i18n,
|
||||
ScmClientSession session)
|
||||
{
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.i18n = i18n;
|
||||
this.session = session;
|
||||
}
|
||||
|
||||
@@ -102,7 +104,7 @@ public abstract class SubCommand
|
||||
|
||||
if (help)
|
||||
{
|
||||
parser.printUsage(output, I18n.getBundle());
|
||||
parser.printUsage(output, i18n.getBundle());
|
||||
System.exit(1);
|
||||
}
|
||||
else
|
||||
@@ -168,6 +170,9 @@ public abstract class SubCommand
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
protected I18n i18n;
|
||||
|
||||
/** Field description */
|
||||
protected BufferedReader input;
|
||||
|
||||
|
||||
@@ -95,7 +95,8 @@ public class SubCommandHandler extends OptionHandler<SubCommand>
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param prmtrs
|
||||
*
|
||||
* @param parameters
|
||||
*
|
||||
* @return
|
||||
*
|
||||
@@ -106,15 +107,19 @@ public class SubCommandHandler extends OptionHandler<SubCommand>
|
||||
{
|
||||
String name = parameters.getParameter(0);
|
||||
CommandDescriptor desc = subCommands.get(name);
|
||||
|
||||
if (desc != null)
|
||||
{
|
||||
|
||||
// owner.stopOptionParsing();
|
||||
setter.addValue(desc.createSubCommand());
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new CmdLineException(owner, "command ".concat(name).concat(" not found"));
|
||||
throw new CmdLineException(owner,
|
||||
"command ".concat(name).concat(" not found"));
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user