@CliClass(usage="Create and/or update resource-bundle property-files.") @CliMode(id="default", title="default", usage="Create and/or update resource-bundle property-files from <bundle-class> for the given locales (including the root locale). Example:\n\n{mainClass} --bundle-class foo.bar.NlsBundleMyExample --locale de de_DE en en_US en_GB fr zh ja_JP zh_TW\n\nFor each locale a property-file foo/bar/NlsBundleMyExample_<locale>.properties will be created or updated in the base-path. In each property-file all properties defined in <bundle-class> will be added with a TODO-marker and the original text as value. If the property-file already exists, all existing properties will remain unchanged and comments will be kept.") public class ResourceBundleSynchronizer extends AbstractResourceBundleCli
NlsBundle
or
AbstractResourceBundle
. If you do not explicitly specify the bundle to synchronize as commandline option
(using --bundle
) this ResourceBundleSynchronizer
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[] |
locales |
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 |
---|
ResourceBundleSynchronizer()
The constructor.
|
Modifier and Type | Method and Description |
---|---|
String[] |
getLocales()
This method gets the locales of the bundles that should be
synchronized . |
protected File |
getTargetFile(NlsBundleDescriptor bundle,
String locale) |
private Properties |
loadOrCreatePropertiesFile(PrintWriter out,
File file,
boolean update) |
static void |
main(String[] arguments)
This is the main method used to run this class as application.
|
void |
setLocales(String[] locales)
This method sets the
locales . |
protected void |
synchronize(NlsBundleDescriptor bundle,
String locale,
File targetFile,
String date)
Like
AbstractResourceBundleCli.synchronize(NlsBundleDescriptor) but for a single Locale . |
private void |
synchronizeProperties(NlsBundleDescriptor bundle,
String locale,
Properties existingBundle,
StringBuffer buffer) |
private void |
writeProperties(String date,
File file,
boolean update,
StringBuffer buffer) |
getBundleClasses, getBundleHelper, getDatePattern, getEncoding, getLocales, getNewline, getPath, getReflectionUtil, getResourceBundleLocator, getTargetFileMkdirs, runDefaultMode, 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
@CliOption(name="--locale", aliases="-l", operand="LOCALE", required=true, 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
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 File getTargetFile(NlsBundleDescriptor bundle, String locale)
getTargetFile
in class AbstractResourceBundleCli
protected void synchronize(NlsBundleDescriptor bundle, String locale, 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.locale
- 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 Properties loadOrCreatePropertiesFile(PrintWriter out, File file, boolean update) throws FileNotFoundException, UnsupportedEncodingException
private void synchronizeProperties(NlsBundleDescriptor bundle, String locale, Properties existingBundle, StringBuffer buffer)
private void writeProperties(String date, File file, boolean update, StringBuffer buffer) throws FileNotFoundException, UnsupportedEncodingException, IOException
public static void main(String[] arguments)
arguments
- are the command-line arguments.Copyright © 2001–2016 mmm-Team. All rights reserved.