Search in sources :

Example 1 with ConfigDescriptionI18nUtil

use of org.eclipse.smarthome.config.core.i18n.ConfigDescriptionI18nUtil in project smarthome by eclipse.

the class AbstractResourceBundleProvider method getLocalizedConfigurationDescription.

protected List<ConfigDescriptionParameter> getLocalizedConfigurationDescription(TranslationProvider i18nProvider, List<ConfigDescriptionParameter> config, Bundle bundle, String uid, String prefix, Locale locale) {
    List<ConfigDescriptionParameter> configDescriptions = new ArrayList<ConfigDescriptionParameter>();
    if (config != null) {
        ConfigDescriptionI18nUtil util = new ConfigDescriptionI18nUtil(i18nProvider);
        for (ConfigDescriptionParameter parameter : config) {
            String parameterName = parameter.getName();
            URI uri = null;
            try {
                uri = new URI(prefix + ":" + uid + ".name");
            } catch (URISyntaxException e) {
                logger.error("Constructed invalid uri '{}:{}.name'", prefix, uid, e);
            }
            String llabel = parameter.getLabel();
            if (llabel != null) {
                llabel = util.getParameterLabel(bundle, uri, parameterName, llabel, locale);
            }
            String ldescription = parameter.getDescription();
            if (ldescription != null) {
                ldescription = util.getParameterDescription(bundle, uri, parameterName, ldescription, locale);
            }
            String lpattern = parameter.getPattern();
            if (lpattern != null) {
                lpattern = util.getParameterPattern(bundle, uri, parameterName, lpattern, locale);
            }
            List<ParameterOption> loptions = parameter.getOptions();
            if (loptions != null && !loptions.isEmpty()) {
                for (ParameterOption option : loptions) {
                    String label = util.getParameterOptionLabel(bundle, uri, parameterName, option.getValue(), option.getLabel(), locale);
                    option = new ParameterOption(option.getValue(), label);
                }
            }
            String lunitLabel = parameter.getUnitLabel();
            if (lunitLabel != null) {
                lunitLabel = util.getParameterUnitLabel(bundle, uri, parameterName, parameter.getUnit(), lunitLabel, locale);
            }
            configDescriptions.add(ConfigDescriptionParameterBuilder.create(parameterName, parameter.getType()).withMinimum(parameter.getMinimum()).withMaximum(parameter.getMaximum()).withStepSize(parameter.getStepSize()).withPattern(lpattern).withRequired(parameter.isRequired()).withMultiple(parameter.isMultiple()).withReadOnly(parameter.isReadOnly()).withContext(parameter.getContext()).withDefault(parameter.getDefault()).withLabel(llabel).withDescription(ldescription).withFilterCriteria(parameter.getFilterCriteria()).withGroupName(parameter.getGroupName()).withAdvanced(parameter.isAdvanced()).withOptions(loptions).withLimitToOptions(parameter.getLimitToOptions()).withMultipleLimit(parameter.getMultipleLimit()).withUnit(parameter.getUnit()).withUnitLabel(lunitLabel).build());
        }
    }
    return configDescriptions;
}
Also used : ParameterOption(org.eclipse.smarthome.config.core.ParameterOption) ArrayList(java.util.ArrayList) ConfigDescriptionI18nUtil(org.eclipse.smarthome.config.core.i18n.ConfigDescriptionI18nUtil) ConfigDescriptionParameter(org.eclipse.smarthome.config.core.ConfigDescriptionParameter) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI)

Aggregations

URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 ConfigDescriptionParameter (org.eclipse.smarthome.config.core.ConfigDescriptionParameter)1 ParameterOption (org.eclipse.smarthome.config.core.ParameterOption)1 ConfigDescriptionI18nUtil (org.eclipse.smarthome.config.core.i18n.ConfigDescriptionI18nUtil)1