blob: 18d8d66bdb6c4af406593d4824f52d292da44662 [file] [log] [blame]
/**
*
* Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany)
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation
*/
package org.eclipse.osbp.preferences.ui.page;
import java.util.HashSet;
import java.util.Locale;
import org.eclipse.osbp.preferences.LocaleUtils;
import org.eclipse.osbp.preferences.Preference;
import org.eclipse.osbp.preferences.ProductConfiguration;
import org.eclipse.osbp.preferences.ui.component.APreferencePage;
import org.eclipse.osbp.preferences.ui.component.AddRemoveListFieldEditor;
import org.eclipse.osbp.preferences.ui.component.Item;
import org.eclipse.osbp.preferences.ui.component.Type;
import org.eclipse.osbp.preferences.ui.data.ProductConfigurationStore;
public class PreferencePageLocalization extends APreferencePage {
public PreferencePageLocalization() {
super(
"localization",
"localization"
);
}
protected String[][] getAvailableLanguages() {
Locale[] locales;
if (store.isWorkspaceSelected()) {
locales = Locale.getAvailableLocales();
}
else {
HashSet<Locale> helper = new HashSet<>();
for (Locale locale : ProductConfiguration.getLanguages().values()) {
if (locale != null) {
helper.add(locale);
}
}
locales = helper.toArray(new Locale[0]);
}
String[][] retcode = new String[locales.length][2];
LocaleUtils.sortLocalesOnDisplayName(locales);
int idx = 0;
for (Locale locale : locales) {
String loc = locale.toString();
if (!loc.isEmpty()) {
retcode[idx][0] = loc;
retcode[idx][1] = store.getLanguageDisplayName(locale);
}
idx++;
}
return retcode;
}
@Override
public void initialize() {
super.initialize();
AddRemoveListFieldEditor languages = (AddRemoveListFieldEditor)getEditor(Preference.LOCALIZATION_SUPPORTED_LANGUAGES);
if (languages != null) {
languages.setAvailableNamesAndValues(getAvailableLanguages());
}
}
@Override
protected Item[] initializeItems() {
return new Item[] {
new Item(Type.TEXT, Preference.SHOW_PRODUCT_CONFIGURATION, "Product Configuration", false),
new Item(""),
new Item(Type.BOOLEAN, Preference.LOCALIZATION_AUTOCREATE, "Extract I18N Properties"),
new Item(Type.BOOLEAN, Preference.LOCALIZATION_SHOW_SELECT_IN_RESPECTIVE_LOCALE, "Display locale selection in respective locale"),
new Item(""),
new Item(Type.LIST_ADD_REMOVE, Preference.LOCALIZATION_SUPPORTED_LANGUAGES, "Supported Languages", getAvailableLanguages(), ProductConfigurationStore.CONFIGURATION_ITEM_SEPARATOR)
};
}
}