| /** |
| * |
| * 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 v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * 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.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]; |
| // --- sort by display name used in the respective locale, if it is configured --- |
| store.sortLocalesOnDisplayNameOnPages(locales); |
| int idx = 0; |
| for (Locale locale : locales) { |
| // String loc = locale.getLanguage(); |
| // if (locale.getCountry().length() > 0) { |
| // loc += "_" + locale.getCountry(); |
| // } else if (locale.getVariant().length() > 0) { |
| // loc += "_" + locale.getVariant(); |
| // } |
| String loc = locale.toString(); |
| if (!loc.isEmpty()) { |
| retcode[idx][0] = loc; |
| retcode[idx][1] = store.getLanguageDisplayName(locale, false); |
| } |
| 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_AUTOTRANSLATE, "Use Google Translator"), |
| new Item(Type.BOOLEAN, Preference.LOCALIZATION_SHOW_SELECT_IN_RESPECTIVE_LOCALE, "Display locale selection in respective locale"), |
| // new Item(Type.TEXT, Preference.LOCALIZATION_GOOGLE_API_KEY, "Google API Key"), |
| // new Item(Type.TEXT, Preference.LOCALIZATION_GOOGLE_HTTP_REFERRER, "Google HTTP Referrer"), |
| new Item(""), |
| new Item(Type.LIST_ADD_REMOVE, Preference.LOCALIZATION_SUPPORTED_LANGUAGES, "Supported Languages", getAvailableLanguages(), ProductConfigurationStore.CONFIGURATION_ITEM_SEPARATOR), |
| }; |
| } |
| } |