/** * Gets the localized message indexed by the provided enumeration key. This * method is a wrapper to the conveyor's method of the same name. * @param <E> Enumeration type that represents the conveyor messages. * @param key Key set in the provided enumeration type. * @return A string containing a localized message indexed by the provided * enumeration key. */ public <E extends Enum<?>> String getMessage(E key) { return conveyor.getMessage(key); }
/** * Sets the current locale. This method actually resets the language * conveyor in order to use the new locale. It's quite simple. * @param locale The new locale for localized messages through the language * conveyor. */ public void setLocale(Locale locale) { conveyor = new MessageConveyor(locale); }
public String getMessage(MessageParameterObj mpo) throws MessageConveyorException { if (mpo == null) { throw new IllegalArgumentException( "MessageParameterObj argumument cannot be null"); } return getMessage(mpo.getKey(), mpo.getArgs()); } }
/** * Log a localized message at the DEBUG level. * * @param key * the key used for localization * @param args * optional arguments */ public void debug(Enum<?> key, Object... args) { if (!logger.isDebugEnabled()) { return; } String translatedMsg = imc.getMessage(key, args); MessageParameterObj mpo = new MessageParameterObj(key, args); if (instanceofLAL) { ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.DEBUG_INT, translatedMsg, args, null); } else { logger.debug(LOCALIZED, translatedMsg, mpo); } }
public String extractCharset(java.util.Locale juLocale) { LocaleData localeData = extractLocaleData(); if (localeData == null) { return ""; } String defaultCharset = localeData.defaultCharset(); Locale la = findLocaleAnnotation(juLocale, localeData); String localeCharset = null; if (la != null) { localeCharset = la.charset(); } if (!isEmptyString(localeCharset)) { return localeCharset; } return defaultCharset; }
public String getBaseName() { BaseName rbnAnnotation = enumClass.getAnnotation(BaseName.class); if (rbnAnnotation == null) { return null; } return rbnAnnotation.value(); }
public String[] extractLocaleNames() { Locale[] localeDataArray = extractLocales(); if (localeDataArray == null) { return null; } String[] names = new String[localeDataArray.length]; for (int i = 0; i < localeDataArray.length; i++) { names[i] = localeDataArray[i].value(); } return names; }
public Locale[] extractLocales() { LocaleData localeData = extractLocaleData(); if (localeData == null) { return null; } return localeData.value(); }
static Locale findLocaleAnnotation(java.util.Locale juLocale, LocaleData localeData) { Locale[] localeAnnotationArray = localeData.value(); if (localeAnnotationArray == null) { return null; } for (Locale la : localeAnnotationArray) { if (la.value().equals(juLocale.toString())) { return la; } } return null; }
/** * @return Message conveyor for English messages. */ @Produces @SuppressWarnings(CompilerWarnings.STATIC_METHOD) public IMessageConveyor messages() { return new MessageConveyor(Locale.ENGLISH); }
/** * Log a localized message at the TRACE level. * * @param key * the key used for localization * @param args * optional arguments */ public void trace(Enum<?> key, Object... args) { if (!logger.isTraceEnabled()) { return; } String translatedMsg = imc.getMessage(key, args); MessageParameterObj mpo = new MessageParameterObj(key, args); if (instanceofLAL) { ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.TRACE_INT, translatedMsg, args, null); } else { logger.trace(LOCALIZED, translatedMsg, mpo); } }
/** * Gets the localized message indexed by the provided enumeration key, * applying an array of objects as parameters. This method is a wrapper to * the conveyor's method of the same name. * @param <E> Enumeration type that represents the conveyor messages. * @param key Key set in the provided enumeration type. * @param parameters Array of objects to be used as parameters. * @return A string containing a localized message indexed by the provided * enumeration key and applied the array of objects as parameters. */ public <E extends Enum<?>> String getMessage(E key, Object... parameters) { return conveyor.getMessage(key, parameters); }
public String getBaseName() { BaseName baseNameAnnotation = typeElementForEnum.getAnnotation(BaseName.class); return baseNameAnnotation.value(); } }
/** * Private constructor. The fallback language is set to English for all * messages in arara. */ private LanguageController() { conveyor = new MessageConveyor(new Locale("en")); }
/** * Log a localized message at the INFO level. * * @param key * the key used for localization * @param args * optional arguments */ public void info(Enum<?> key, Object... args) { if (!logger.isInfoEnabled()) { return; } String translatedMsg = imc.getMessage(key, args); MessageParameterObj mpo = new MessageParameterObj(key, args); if (instanceofLAL) { ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.INFO_INT, translatedMsg, args, null); } else { logger.info(LOCALIZED, translatedMsg, mpo); } }
/** * Returns the localized error message corresponding to the given message code. * * @param <E> * Enum for the message code * @param messageCode * Error code to localize from Enum * @param args * Arguments for parametric replacement * @return Localized error message */ public <E extends Enum<?>> String getMessage(E messageCode, Object... args) { String message = mc.getMessage(messageCode, args); return message; }
/** * Instantiates a new localizer helper passing a locale. * * @param locale * the locale */ public LocalizerHelper(Locale locale) { mc = new MessageConveyor(locale); locLoggerFactory = new LocLoggerFactory(mc); }
/** * Log a localized message at the WARN level. * * @param key * the key used for localization * @param args * optional arguments */ public void warn(Enum<?> key, Object... args) { if (!logger.isWarnEnabled()) { return; } String translatedMsg = imc.getMessage(key, args); MessageParameterObj mpo = new MessageParameterObj(key, args); if (instanceofLAL) { ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.WARN_INT, translatedMsg, args, null); } else { logger.warn(LOCALIZED, translatedMsg, mpo); } }
@Override protected void configure() { bind(IMessageConveyor.class).toInstance(new MessageConveyor(Locale.ENGLISH)); }
/** * Log a localized message at the ERROR level. * * @param key * the key used for localization * @param args * optional arguments */ public void error(Enum<?> key, Object... args) { if (!logger.isErrorEnabled()) { return; } String translatedMsg = imc.getMessage(key, args); MessageParameterObj mpo = new MessageParameterObj(key, args); if (instanceofLAL) { ((LocationAwareLogger) logger).log(LOCALIZED, FQCN, LocationAwareLogger.ERROR_INT, translatedMsg, args, null); } else { logger.error(LOCALIZED, translatedMsg, mpo); } }