org.apache.wicket.Localizer Java Examples

The following examples show how to use org.apache.wicket.Localizer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
public static String getString(String key, final Locale loc, String... _params) {
	if (!exists()) {
		ThreadContext.setApplication(org.apache.wicket.Application.get(appName));
	}
	String[] params = _params;
	if ((params == null || params.length == 0) && STRINGS_WITH_APP.contains(key)) {
		params = new String[]{getApplicationName()};
	}
	Localizer l = get().getResourceSettings().getLocalizer();
	String value = l.getStringIgnoreSettings(key, null, null, loc, null, "[Missing]");
	if (params != null && params.length > 0) {
		final MessageFormat format = new MessageFormat(value, loc);
		value = format.format(params);
	}
	if (RuntimeConfigurationType.DEVELOPMENT == get().getConfigurationType()) {
		value += String.format(" [%s]", key);
	}
	return value;
}
 
Example #2
Source File: FormComponent.java    From onedev with MIT License 5 votes vote down vote up
/**
 * 
 * @param localizer
 * @param key
 * @param component
 * @return string
 */
private String getString(Localizer localizer, String key, Component component)
{
	triedKeys.add(key);

	// Note: It is important that the default value of "" is
	// provided to getString() not to throw a MissingResourceException or to
	// return a default string like "[Warning: String ..."
	return localizer.getString(key, component, "");
}
 
Example #3
Source File: FormComponent.java    From onedev with MIT License 4 votes vote down vote up
/**
 * @see org.apache.wicket.validation.IErrorMessageSource#getMessage(String, java.util.Map)
 */
@Override
public String getMessage(String key, Map<String, Object> vars)
{
	final FormComponent<T> formComponent = FormComponent.this;

	// Use the following log4j config for detailed logging on the property resolution
	// process
	// log4j.logger.org.apache.wicket.resource.loader=DEBUG
	// log4j.logger.org.apache.wicket.Localizer=DEBUG

	final Localizer localizer = formComponent.getLocalizer();

	// retrieve prefix that will be used to construct message keys
	String prefix = formComponent.getValidatorKeyPrefix();
	String message;

	// first try the full form of key [form-component-id].[prefix].[key]
	String resource = getId() + "." + prefix(prefix, key);
	message = getString(localizer, resource, formComponent);

	// if not found, try a more general form (without prefix)
	// [form-component-id].[key]
	if (Strings.isEmpty(message) && Strings.isEmpty(prefix))
	{
		resource = getId() + "." + key;
		message = getString(localizer, resource, formComponent);
	}

	// If not found try a more general form [prefix].[key]
	if (Strings.isEmpty(message))
	{
		resource = prefix(prefix, key);
		message = getString(localizer, resource, formComponent);
	}

	// If not found try the most general form [key]
	if (Strings.isEmpty(message))
	{
		// Try a variation of the resource key
		message = getString(localizer, key, formComponent);
	}

	// convert empty string to null in case our default value of "" was
	// returned from localizer
	if (Strings.isEmpty(message))
	{
		message = null;
	}
	else
	{
		message = substitute(message, addDefaultVars(vars));
	}
	return message;
}
 
Example #4
Source File: OrienteerModule.java    From Orienteer with Apache License 2.0 4 votes vote down vote up
@Provides
public Localizer getLocalizer(WebApplication application)
{
	return application.getResourceSettings().getLocalizer();
}