@CliClass(usage="Converts resource-bundle property-files to different formats.") @CliMode(id="default", title="default", usage="Convert resource-bundle property-files from <bundle-class> for all available or the explicitly given locales. Example:\n\n{mainClass} --bundle-class foo.bar.NlsBundleMyExample \n\nFor each locale where a localization exists in property-file foo/bar/NlsBundleMyExample_<locale>.properties an according converted file is created in <path>. Already existing files will be overridden.") public class ResourceBundleConverter extends AbstractResourceBundleCli
NlsBundle
or
AbstractResourceBundle
. If you do not explicitly specify the bundle to synchronize as commandline option
(using --bundle
) this ResourceBundleConverter
will automatically scan your classpath for
NlsBundle
s and synchronize all of them.--help
to get help.Modifier and Type | Field and Description |
---|---|
private String |
argument |
private static String |
DEFAULT_ARGUMENT
The default for option
argument . |
private ChoiceEvaluation |
evalChoice |
private Format |
format |
private Pattern |
keyPattern |
private String[] |
locales |
private NlsMessageFormatterFactory |
messageFormatterFactory |
static String |
OPTION_ARGUMENT
The command-line option to set the
getFormat() . |
static String |
OPTION_EVAL_CHOICE
The command-line option to set the
getEvalChoice() . |
static String |
OPTION_FORMAT
The command-line option to set the
getFormat() . |
static String |
OPTION_KEY_PATTERN
The command-line option to set the
key pattern . |
static String |
OPTION_PATH_EXPRESSION
The command-line option to set the
getFormat() . |
private String |
pathExpression |
private NlsResourceLocator |
resourceLocator |
DEFAULT_BASE_PATH, OPTION_BUNDLE_CLASS, OPTION_DATE_PATTERN, OPTION_ENCODING, OPTION_LOCALE, OPTION_PATH
EXIT_CODE_CONSTRAINT_VIOLATION, EXIT_CODE_ILLEGAL_SYNTAX, EXIT_CODE_OK, EXIT_CODE_UNEXPECTED
Constructor and Description |
---|
ResourceBundleConverter()
The constructor.
|
getBundleClasses, getBundleHelper, getDatePattern, getEncoding, getNewline, getPath, getReflectionUtil, getResourceBundleLocator, getTargetFileMkdirs, setBundleClasses, setBundleHelper, setDatePattern, setEncoding, setLocales, setNewline, setPath, setReflectionUtil, setResourceBundleLocator, synchronize
getVersion, run
getIocContainer, getOutputSettings, getParserBuilder, getStandardError, getStandardOutput, getStreamUtil, handleError, printHelp, run, runAndExit, setStandardError, setStandardOutput, validate
getLogger
public static final String OPTION_KEY_PATTERN
key pattern
.public static final String OPTION_FORMAT
getFormat()
.public static final String OPTION_PATH_EXPRESSION
getFormat()
.public static final String OPTION_ARGUMENT
getFormat()
.public static final String OPTION_EVAL_CHOICE
getEvalChoice()
.private static final String DEFAULT_ARGUMENT
argument
.@CliOption(name="--locale", aliases="-l", operand="LOCALE", required=false, usage="The list of locales to process. Each locale has to be in the form \"ll[_CC[_vv]]\" where \"ll\" is the lowercase ISO 639 code, CC is the uppercase ISO 3166 2-letter code and vv is an arbitrary variant. Examples are \"de\", \"en_US\" or \"th_TH_TH\".") private String[] locales
@CliOption(name="--key-pattern", aliases="-k", operand="REGEX", required=false, usage="Use {operand} as regular expression to filter the resource bundle keys (e.g. \"label.*\").") private Pattern keyPattern
@CliOption(name="--format", aliases="-f", operand="FORMAT", required=false, usage="Write the converted output in the specified format {operand} (Default is \"{default}\").") private Format format
@CliOption(name="--path-expression", aliases="-x", operand="EXP", required=false, usage="Use the expression {operand} for the path of the converted output file including filename relative to the output path (Default is \"{default}\").") private String pathExpression
@CliOption(name="--argument", aliases="-a", operand="EXP", required=false, usage="Convert the arguments of the messages to the format {operand} (e.g. \"\\{{key}}\" or \"\\{index,format}\"). Can be used to convert the syntax for other NLS frameworks such as angular-translate (Default is \"{default}\").") private String argument
@CliOption(name="--eval-choice", aliases="-c", operand="EVAL", required=false, usage="Simplify and resolve CHOICE format expressions using {operand}.") private ChoiceEvaluation evalChoice
private NlsResourceLocator resourceLocator
private NlsMessageFormatterFactory messageFormatterFactory
public NlsResourceLocator getResourceLocator()
public NlsMessageFormatterFactory getMessageFormatterFactory()
public Pattern getKeyPattern()
Pattern
the resource bundle keys have to match for being added to the converted file.public void setKeyPattern(Pattern pattern)
pattern
- the new value of getKeyPattern()
.public void setFormat(Format format)
format
- the new value of getFormat()
.public String getPathExpression()
AbstractResourceBundleCli.getPath()
. Includes an
optional path and the filename.public void setPathExpression(String pathExpression)
pathExpression
- the new value of getPathExpression()
.public String getArgument()
NlsArgument
s.public void setArgument(String argument)
argument
- the new value of getArgument()
.public ChoiceEvaluation getEvalChoice()
ChoiceEvaluation
or null
to leave unmodified.public void setEvalChoice(ChoiceEvaluation evalChoice)
evalChoice
- the new value of getEvalChoice()
.public String[] getLocales()
AbstractResourceBundleCli
synchronized
.
Examples for locales (entries of the returned array) are ""
, "en"
, or "en_GB"
.getLocales
in class AbstractResourceBundleCli
public void setLocales(String[] locales)
AbstractResourceBundleCli
locales
.setLocales
in class AbstractResourceBundleCli
locales
- are the locales to setprotected List<String> getLocales(NlsBundleDescriptor bundle)
getLocales
in class AbstractResourceBundleCli
bundle
- the NlsBundleDescriptor
.locales
to process for the bundle.protected File getTargetFile(NlsBundleDescriptor bundle, String locale)
getTargetFile
in class AbstractResourceBundleCli
protected String getPathExpressionResolved(NlsBundleDescriptor bundle, String locale)
bundle
- the NlsBundleDescriptor
.locale
- the Locale
.path expression
with all variables resolved.protected Map<String,String> getVariableMap(NlsBundleDescriptor bundle, String locale)
bundle
- the NlsBundleDescriptor
.locale
- the Locale
.Map
with the variables to resolve
.protected int runDefaultMode() throws Exception
AbstractVersionedMain
AbstractVersionedMain.run(CliModeObject)
if the program is executed in default
mode
.runDefaultMode
in class AbstractResourceBundleCli
AbstractMain.EXIT_CODE_OK
on success.Exception
- in case of an unexpected error.protected void synchronize(NlsBundleDescriptor bundle, String localeString, File targetFile, String date) throws IOException
AbstractResourceBundleCli
AbstractResourceBundleCli.synchronize(NlsBundleDescriptor)
but for a single Locale
.synchronize
in class AbstractResourceBundleCli
bundle
- the bundle instance as java object.localeString
- the locale to synchronize as string.targetFile
- the File
to write to. May not yet exists but parent folder exists.date
- is the current date as string.IOException
- if an I/O problem occurred.private String convertMessage(String message, String key, NlsBundleDescriptor bundle, String locale)
private void convertArgument(NlsArgument nlsArgument, StringBuilder buffer, NlsMessageDescriptor messageDescriptor, List<String> argumentList)
private void convertArgumentChoice(NlsFormatterChoice formatter, StringBuilder buffer, NlsMessageDescriptor messageDescriptor, List<String> argumentList)
private NlsFormatterChoice.Choice extracted(NlsFormatterChoice formatter)
private String convertArgumentIndex(NlsMessageDescriptor messageDescriptor, List<String> argumentList, String result, String key)
private String convertArgumentFormatter(NlsFormatterPlugin<?> formatter, String arg)
private String convertArgumentJustification(Justification justification, String result)
public static void main(String[] arguments)
arguments
- are the command-line arguments.Copyright © 2001–2016 mmm-Team. All rights reserved.