use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.
the class ConfigI18nLocalizationService method getLocalizedOptions.
/**
* Localize parameter options.
*
* @param originalOptions the parameter options that should be localized
* @param bundle the bundle the i18n resources are located
* @param configDescriptionURI the config description URI
* @param parameterName the name of the parameter
* @param locale the locale it should be localized to
* @return a list with parameter option. If an option could not be localized (e.g. no translation is found), the
* non-localized one is added to the list.
*/
public List<ParameterOption> getLocalizedOptions(final List<ParameterOption> originalOptions, final Bundle bundle, final URI configDescriptionURI, final String parameterName, @Nullable final Locale locale) {
if (originalOptions == null || originalOptions.isEmpty()) {
return originalOptions;
}
final List<ParameterOption> localizedOptions = new ArrayList<>();
for (final ParameterOption option : originalOptions) {
final String localizedLabel = this.configDescriptionParamI18nUtil.getParameterOptionLabel(bundle, configDescriptionURI, parameterName, /* key */
option.getValue(), /* fallback */
option.getLabel(), locale);
final ParameterOption localizedOption = new ParameterOption(option.getValue(), localizedLabel);
localizedOptions.add(localizedOption);
}
return localizedOptions;
}
use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.
the class I18nConfigOptionsProvider method processParamType.
private Collection<ParameterOption> processParamType(String param, Locale locale, Locale translation) {
switch(param) {
case "language":
return getAvailable(locale, l -> new ParameterOption(l.getLanguage(), l.getDisplayLanguage(translation)));
case "region":
return getAvailable(locale, l -> new ParameterOption(l.getCountry(), l.getDisplayCountry(translation)));
case "variant":
return getAvailable(locale, l -> new ParameterOption(l.getVariant(), l.getDisplayVariant(translation)));
case "timezone":
Comparator<TimeZone> byOffset = (t1, t2) -> {
return t1.getRawOffset() - t2.getRawOffset();
};
Comparator<TimeZone> byID = (t1, t2) -> {
return t1.getID().compareTo(t2.getID());
};
return ZoneId.getAvailableZoneIds().stream().map(TimeZone::getTimeZone).sorted(byOffset.thenComparing(byID)).map(tz -> {
return new ParameterOption(tz.getID(), getTimeZoneRepresentation(tz));
}).collect(Collectors.toList());
default:
return null;
}
}
use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.
the class VoiceManagerTest method getParameterOptionsForTheDefaultVoice.
@Test
public void getParameterOptionsForTheDefaultVoice() throws URISyntaxException {
BundleContext context = bundleContext;
ttsService = new TTSServiceStub(context);
registerService(ttsService);
boolean isVoiceStubInTheOptions = false;
Collection<ParameterOption> options = voiceManager.getParameterOptions(new URI("system:voice"), "defaultVoice", null);
assertNotNull(options);
for (ParameterOption option : options) {
String optionValue = option.getValue();
String optionLabel = option.getLabel();
String voiceStubId = voice.getUID();
String voiceLabel = voice.getLabel();
if (optionValue.equals(voiceStubId) && optionLabel.equals(voiceLabel + " - " + voice.getLocale().getDisplayName())) {
isVoiceStubInTheOptions = true;
}
}
assertTrue(isVoiceStubInTheOptions);
}
use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.
the class VoiceManagerTest method getParameterOptionsForTheDefaultHli.
@Test
public void getParameterOptionsForTheDefaultHli() throws URISyntaxException {
hliStub = new HumanLanguageInterpreterStub();
registerService(hliStub);
boolean isHliStubInTheOptions = false;
Collection<ParameterOption> options = voiceManager.getParameterOptions(new URI("system:voice"), "defaultHLI", null);
assertNotNull(options);
for (ParameterOption option : options) {
String optionValue = option.getValue();
String optionLabel = option.getLabel();
String hliStubId = hliStub.getId();
String hliLabel = hliStub.getLabel(null);
if (optionValue.equals(hliStubId) && optionLabel.equals(hliLabel)) {
isHliStubInTheOptions = true;
}
}
assertTrue(isHliStubInTheOptions);
}
use of org.eclipse.smarthome.config.core.ParameterOption in project smarthome by eclipse.
the class ConfigI18nLocalizationService method getLocalizedConfigDescriptionParameter.
/**
* Localize a config description parameter.
*
* @param bundle the bundle the i18n resources are located
* @param configDescription the config description the parameter is part of
* @param parameter the parameter that should be localized
* @param locale the locale it should be localized to
* @return a localized parameter on success, a non-localized one on error (e.g. no translation is found).
*/
public ConfigDescriptionParameter getLocalizedConfigDescriptionParameter(final Bundle bundle, final ConfigDescription configDescription, final ConfigDescriptionParameter parameter, @Nullable final Locale locale) {
final URI configDescriptionURI = configDescription.getUID();
final String parameterName = parameter.getName();
final String label = this.configDescriptionParamI18nUtil.getParameterLabel(bundle, configDescriptionURI, parameterName, parameter.getLabel(), locale);
final String description = this.configDescriptionParamI18nUtil.getParameterDescription(bundle, configDescriptionURI, parameterName, parameter.getDescription(), locale);
final String pattern = this.configDescriptionParamI18nUtil.getParameterPattern(bundle, configDescriptionURI, parameterName, parameter.getPattern(), locale);
final String unitLabel = this.configDescriptionParamI18nUtil.getParameterUnitLabel(bundle, configDescriptionURI, parameterName, parameter.getUnit(), parameter.getUnitLabel(), locale);
final List<ParameterOption> options = getLocalizedOptions(parameter.getOptions(), bundle, configDescriptionURI, parameterName, locale);
final ConfigDescriptionParameter localizedParameter = ConfigDescriptionParameterBuilder.create(parameterName, parameter.getType()).withMinimum(parameter.getMinimum()).withMaximum(parameter.getMaximum()).withStepSize(parameter.getStepSize()).withPattern(pattern).withRequired(parameter.isRequired()).withReadOnly(parameter.isReadOnly()).withMultiple(parameter.isMultiple()).withContext(parameter.getContext()).withDefault(parameter.getDefault()).withLabel(label).withDescription(description).withOptions(options).withFilterCriteria(parameter.getFilterCriteria()).withGroupName(parameter.getGroupName()).withAdvanced(parameter.isAdvanced()).withVerify(parameter.isVerifyable()).withLimitToOptions(parameter.getLimitToOptions()).withMultipleLimit(parameter.getMultipleLimit()).withUnit(parameter.getUnit()).withUnitLabel(unitLabel).build();
return localizedParameter;
}
Aggregations