mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
improve i18n support
This commit is contained in:
@@ -139,9 +139,11 @@ public class App
|
|||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
I18n i18n = new I18n();
|
||||||
|
|
||||||
if ((args.length == 0) || (subcommand == null) || help)
|
if ((args.length == 0) || (subcommand == null) || help)
|
||||||
{
|
{
|
||||||
parser.printUsage(output, I18n.getBundle());
|
parser.printUsage(output, i18n.getBundle());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -152,7 +154,7 @@ public class App
|
|||||||
session = createSession();
|
session = createSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
subcommand.init(input, output, session);
|
subcommand.init(input, output, i18n, session);
|
||||||
subcommand.run(arguments);
|
subcommand.run(arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Command
|
public @interface Command
|
||||||
{
|
{
|
||||||
String value() default "";
|
String value() default "";
|
||||||
String usage() default "";
|
String usage() default "";
|
||||||
boolean sessionRequired() default true;
|
boolean sessionRequired() default true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,19 @@
|
|||||||
* http://bitbucket.org/sdorra/scm-manager
|
* http://bitbucket.org/sdorra/scm-manager
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
package sonia.scm.cli;
|
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;
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,8 +50,62 @@ import java.util.ResourceBundle;
|
|||||||
public class I18n
|
public class I18n
|
||||||
{
|
{
|
||||||
|
|
||||||
public static ResourceBundle getBundle(){
|
/** Field description */
|
||||||
return null;
|
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 input
|
||||||
* @param output
|
* @param output
|
||||||
|
* @param i18n
|
||||||
* @param session
|
* @param session
|
||||||
*/
|
*/
|
||||||
public void init(BufferedReader input, PrintWriter output,
|
public void init(BufferedReader input, PrintWriter output, I18n i18n,
|
||||||
ScmClientSession session)
|
ScmClientSession session)
|
||||||
{
|
{
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.output = output;
|
this.output = output;
|
||||||
|
this.i18n = i18n;
|
||||||
this.session = session;
|
this.session = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +104,7 @@ public abstract class SubCommand
|
|||||||
|
|
||||||
if (help)
|
if (help)
|
||||||
{
|
{
|
||||||
parser.printUsage(output, I18n.getBundle());
|
parser.printUsage(output, i18n.getBundle());
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -168,6 +170,9 @@ public abstract class SubCommand
|
|||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
|
/** Field description */
|
||||||
|
protected I18n i18n;
|
||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
protected BufferedReader input;
|
protected BufferedReader input;
|
||||||
|
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ public class SubCommandHandler extends OptionHandler<SubCommand>
|
|||||||
* Method description
|
* Method description
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @param prmtrs
|
*
|
||||||
|
* @param parameters
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*
|
*
|
||||||
@@ -106,15 +107,19 @@ public class SubCommandHandler extends OptionHandler<SubCommand>
|
|||||||
{
|
{
|
||||||
String name = parameters.getParameter(0);
|
String name = parameters.getParameter(0);
|
||||||
CommandDescriptor desc = subCommands.get(name);
|
CommandDescriptor desc = subCommands.get(name);
|
||||||
if ( desc != null )
|
|
||||||
|
if (desc != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// owner.stopOptionParsing();
|
// owner.stopOptionParsing();
|
||||||
setter.addValue( desc.createSubCommand() );
|
setter.addValue(desc.createSubCommand());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new CmdLineException(owner, "command ".concat(name).concat(" not found"));
|
throw new CmdLineException(owner,
|
||||||
|
"command ".concat(name).concat(" not found"));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user